# HG changeset patch
# User renatofilho
# Date 1187723063 -3600
# Node ID 888b9724f6011472f07385f102ae7db8df2a984c
# Parent c404781fda4e035ba7bbd17f9e847620cd4d38ae
[svn r823] fixed monitor_handler dispose
diff -r c404781fda4e -r 888b9724f601 gmyth/src/gmyth_backendinfo.c
--- a/gmyth/src/gmyth_backendinfo.c Tue Aug 21 17:14:42 2007 +0100
+++ b/gmyth/src/gmyth_backendinfo.c Tue Aug 21 20:04:23 2007 +0100
@@ -73,7 +73,9 @@
g_free(backend_info->username);
g_free(backend_info->password);
g_free(backend_info->db_name);
- g_object_unref (backend_info->sock);
+
+ if (backend_info->sock)
+ g_object_unref (backend_info->sock);
backend_info->hostname = NULL;
backend_info->username = NULL;
@@ -81,6 +83,7 @@
backend_info->db_name = NULL;
backend_info->port = -1;
backend_info->status_port = -1;
+ backend_info->sock = NULL;
G_OBJECT_CLASS(gmyth_backend_info_parent_class)->dispose(object);
}
diff -r c404781fda4e -r 888b9724f601 gmyth/src/gmyth_file_transfer.c
--- a/gmyth/src/gmyth_file_transfer.c Tue Aug 21 17:14:42 2007 +0100
+++ b/gmyth/src/gmyth_file_transfer.c Tue Aug 21 20:04:23 2007 +0100
@@ -142,8 +142,8 @@
g_signal_connect(G_OBJECT(transfer), "program-info-changed",
(GCallback) (GMYTH_FILE_TRANSFER_GET_CLASS
- (transfer)->
- program_info_changed_handler), NULL);
+ (transfer)->program_info_changed_handler),
+ NULL);
}
static void
diff -r c404781fda4e -r 888b9724f601 gmyth/src/gmyth_livetv.c
--- a/gmyth/src/gmyth_livetv.c Tue Aug 21 17:14:42 2007 +0100
+++ b/gmyth/src/gmyth_livetv.c Tue Aug 21 20:04:23 2007 +0100
@@ -109,12 +109,12 @@
livetv->monitor = NULL;
}
+
if (livetv->file != NULL) {
g_object_unref(livetv->file);
livetv->file = NULL;
}
-
if (livetv->recorder != NULL) {
// gmyth_recorder_close(livetv->recorder);
g_object_unref(livetv->recorder);
@@ -131,7 +131,6 @@
livetv->tvchain = NULL;
}
-
if (livetv->proginfo != NULL) {
g_object_unref(livetv->proginfo);
livetv->proginfo = NULL;
@@ -142,7 +141,6 @@
livetv->backend_info = NULL;
}
-
if (livetv->uri != NULL) {
g_object_unref(livetv->uri);
livetv->uri = NULL;
@@ -153,7 +151,6 @@
livetv->mutex = NULL;
}
-
if (livetv->local_hostname != NULL) {
g_string_free(livetv->local_hostname, TRUE);
livetv->local_hostname = NULL;
@@ -321,7 +318,6 @@
}
livetv->monitor = gmyth_monitor_handler_new();
-
res =
gmyth_monitor_handler_open(livetv->monitor,
livetv->backend_info->hostname,
@@ -403,9 +399,8 @@
g_return_val_if_fail(livetv != NULL, FALSE);
- if (NULL == livetv->socket) {
+ if (livetv->socket == NULL) {
livetv->socket = gmyth_socket_new();
-
/*
* FIME: Implement this at gmyth_socket
*/
diff -r c404781fda4e -r 888b9724f601 gmyth/src/gmyth_monitor_handler.c
--- a/gmyth/src/gmyth_monitor_handler.c Tue Aug 21 17:14:42 2007 +0100
+++ b/gmyth/src/gmyth_monitor_handler.c Tue Aug 21 20:04:23 2007 +0100
@@ -70,7 +70,9 @@
#define GMYTHTV_ENABLE_DEBUG 1
#endif
-gpointer gmyth_monitor_handler_listener(gpointer data);
+gboolean gmyth_monitor_handler_listener (GIOChannel *io_channel,
+ GIOCondition condition,
+ gpointer data);
static void gmyth_monitor_handler_default_listener(GMythMonitorHandler
* monitor,
@@ -92,51 +94,10 @@
void gmyth_monitor_handler_close(GMythMonitorHandler * monitor);
-G_DEFINE_TYPE(GMythMonitorHandler, gmyth_monitor_handler, G_TYPE_OBJECT)
- static void
+G_DEFINE_TYPE(GMythMonitorHandler, gmyth_monitor_handler, G_TYPE_OBJECT);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- gmyth_monitor_handler_class_init(GMythMonitorHandlerClass * klass)
+static void
+gmyth_monitor_handler_class_init(GMythMonitorHandlerClass * klass)
{
GObjectClass *gobject_class;
GMythMonitorHandlerClass *gmonitor_class;
@@ -169,23 +130,11 @@
monitor->hostname = NULL;
monitor->port = 0;
monitor->actual_index = 0;
-
monitor->allow_msgs_listener = FALSE;
-
- /*
- * monitor->backend_msgs = g_hash_table_new( g_int_hash, g_int_equal
- * );
- */
-
/*
* it is used for signalizing the event socket consumer thread
*/
monitor->mutex = g_mutex_new();
-
- monitor->th = NULL;
-
- monitor->gmyth_monitor_handler_listener =
- gmyth_monitor_handler_listener;
}
static void
@@ -197,14 +146,9 @@
monitor->allow_msgs_listener = FALSE;
- if (monitor->th != NULL) {
- gboolean *ret = (gboolean *) g_thread_join(monitor->th);
-
- if (*ret == FALSE)
- gmyth_debug("Error closing GThread listener socket!");
- else
- gmyth_debug("Closed GThread listener socket.");
- // g_object_unref( monitor->th );
+ if (monitor->io_source != 0) {
+ g_source_remove (monitor->io_source);
+ monitor->io_source = 0;
}
/*
@@ -226,6 +170,7 @@
monitor->hostname = NULL;
}
+
if (monitor->backend_msgs != NULL) {
g_hash_table_destroy(monitor->backend_msgs);
monitor->backend_msgs = NULL;
@@ -236,6 +181,7 @@
* io_watcher_cond = NULL; }
*/
+
G_OBJECT_CLASS(gmyth_monitor_handler_parent_class)->dispose(object);
}
@@ -353,30 +299,22 @@
gmyth_debug("Monitor event socket --- hostname: %s, port %d\n",
monitor->hostname, monitor->port);
- if (NULL != monitor->event_sock) {
+ if (monitor->event_sock != NULL) {
g_object_unref(monitor->event_sock);
monitor->event_sock = NULL;
}
/*
- * configure the event socket
+ * configure the event socket
*/
- if (NULL == monitor->event_sock) {
- if (!gmyth_connect_to_backend_monitor(monitor)) {
- gmyth_debug("Connection to backend failed (Event Socket)!");
- ret = FALSE;
- } else {
- gmyth_debug
- ("Remote monitor event socket had been succesfully created. (io_fd == %d)\n",
- g_io_channel_unix_get_fd(monitor->event_sock->sd_io_ch));
- }
+ if (!gmyth_connect_to_backend_monitor(monitor)) {
+ gmyth_debug("Connection to backend failed (Event Socket)!");
+ ret = FALSE;
} else {
- gmyth_debug
- ("ASSERT ERROR: Remote monitor event socket is not NULL at the setup...\n");
+ gmyth_debug ("Remote monitor event socket had been succesfully create");
}
return ret;
-
}
/**
@@ -493,122 +431,73 @@
* @return Pointer to a gboolean true
value, if the data was
* successfully read.
*/
-gpointer
-gmyth_monitor_handler_listener(gpointer data)
+gboolean
+gmyth_monitor_handler_listener (GIOChannel *io_channel,
+ GIOCondition io_cond,
+ gpointer data)
{
- GMythMonitorHandler *monitor = (GMythMonitorHandler *) data;
+ GMythMonitorHandler *monitor;
guint recv = 0;
- gboolean *ret = g_new0(gboolean, 1);
gsize len = 0;
- GIOChannel *io_channel = monitor->event_sock->sd_io_ch;
- GIOCondition io_cond =
- g_io_channel_get_buffer_condition(io_channel);
- static guint count = 0;
+ GMythStringList *strlist = NULL;
+ gint bytes_sent = 0;
- *ret = TRUE;
+ monitor = (GMythMonitorHandler *) data;
gmyth_debug("Entering MONITOR handler listener...");
myth_control_acquire_context(monitor, TRUE);
- if ((io_cond & G_IO_HUP) != 0) {
- *ret = FALSE;
+ if (((io_cond & G_IO_HUP) != 0) ||
+ ((io_cond & G_IO_ERR) != 0)) {
goto clean_up;
}
- GMythStringList *strlist = NULL;
- if (NULL == io_channel) {
- gmyth_debug("Monitor socket is NULL! (GIOChannel)");
- *ret = FALSE;
- goto clean_up;
+ gmyth_debug("%d - Listening on Monitor socket...!\n", count);
+ strlist = gmyth_string_list_new();
+
+ len = gmyth_socket_read_stringlist(monitor->event_sock, strlist);
+ if ((len > 0) && strlist != NULL && gmyth_string_list_length(strlist) > 0) {
+ gchar *back_msg_action;
+ gint msg_type;
+
+ bytes_sent = gmyth_string_list_get_int(strlist, 0);
+ // on backend error
+ gmyth_debug ("received data buffer from IO event channel... %d strings gone!\n", len);
+ recv += len;
+
+ /*
+ * debug purpose: prints out all the string list
+ * elements
+ */
+ g_list_foreach(strlist->glist,
+ (GFunc) gmyth_monitor_handler_print,
+ NULL);
+
+ back_msg_action = g_new0(gchar, 1);
+ msg_type = gmyth_monitor_handler_is_backend_message(monitor,
+ strlist,
+ &back_msg_action);
+
+ if (msg_type != GMYTH_BACKEND_NO_MESSAGE) {
+ g_signal_emit(monitor,
+ GMYTH_MONITOR_HANDLER_GET_CLASS(monitor)->backend_events_handler_signal_id,
+ 0, msg_type, back_msg_action);
+ }
+
+ if (back_msg_action != NULL)
+ g_free(back_msg_action);
+
+ g_object_unref(strlist);
}
- while (monitor->allow_msgs_listener) {
- ++count;
-
- gmyth_debug("%d - Listening on Monitor socket...!\n", count);
-
- do {
-
- gint bytes_sent = 0;
-
- strlist = gmyth_string_list_new();
-
- if (monitor->event_sock != NULL) {
-
- len =
- gmyth_socket_read_stringlist(monitor->event_sock,
- strlist);
-
- if ((len > 0) && strlist != NULL
- && gmyth_string_list_length(strlist) > 0) {
- bytes_sent = gmyth_string_list_get_int(strlist, 0); // -1
- //
- //
- // on
- // backend
- // error
-
- gmyth_debug
- ("[%s] MONITOR: received data buffer from IO event channel... %d strings gone!\n",
- __FUNCTION__, len);
-
- recv += len;
-
- /*
- * debug purpose: prints out all the string list
- * elements
- */
- g_list_foreach(strlist->glist,
- (GFunc) gmyth_monitor_handler_print,
- NULL);
-
- gchar *back_msg_action = g_new0(gchar, 1);
- gint msg_type =
- gmyth_monitor_handler_is_backend_message(monitor,
- strlist,
- &back_msg_action);
-
- if (monitor != NULL
- && msg_type != GMYTH_BACKEND_NO_MESSAGE)
- g_signal_emit(monitor, GMYTH_MONITOR_HANDLER_GET_CLASS(monitor)->backend_events_handler_signal_id, 0, /* details
- */
- msg_type, back_msg_action);
-
- if (back_msg_action != NULL)
- g_free(back_msg_action);
-
- }
-
- }
-
- if (strlist != NULL) {
- g_object_unref(strlist);
- strlist = NULL;
- }
-
- io_cond = g_io_channel_get_buffer_condition(io_channel);
-
- g_usleep(500);
-
- }
- while (recv <= 0 && ((io_cond & G_IO_HUP) == 0));
-
- gmyth_debug("\tMONITOR EVENT: Read %d bytes\n", recv);
-
- } /* main GThread while */
-
- clean_up:
+clean_up:
myth_control_release_context(monitor);
-
- g_thread_exit(ret);
-
- return (gpointer) ret;
-
+ return TRUE;
}
-/**
+/**
* Opens connection events' socket the the Monitor socket on
* MythTV backend server.
*
@@ -616,7 +505,7 @@
*
* @return true
, if the socket was successfully opened.
*/
-static gboolean
+static gboolean
gmyth_connect_to_backend_monitor(GMythMonitorHandler * monitor)
{
gboolean ret = TRUE;
@@ -625,7 +514,7 @@
/*
* Connects the socket, send Mythtv ANN Monitor and verify Mythtv
- * protocol version
+ * protocol version
*/
if (!gmyth_socket_connect_to_backend_events(monitor->event_sock,
monitor->hostname,
@@ -638,52 +527,38 @@
return ret;
}
-/**
+/**
* Opens connection the the Monitor socket on MythTV backend server,
* where all status messages are notified to the client.
- *
+ *
* @param monitor The GMythMonitorHandler instance.
* @param channel The GIOChannel instance to the Monitor socket.
- *
+ *
* @return Pointer to the boolean value, and it is true
only if the
- * GMythMonitorHandler could be configured.
+ * GMythMonitorHandler could be configured.
*/
-static gboolean
+static gboolean
gmyth_monitor_handler_setup(GMythMonitorHandler * monitor,
GIOChannel * channel)
{
- gboolean ret = TRUE;
+ gboolean ret = TRUE;
if (channel != NULL) {
monitor->allow_msgs_listener = TRUE;
-
- monitor->th =
- g_thread_create((GThreadFunc) gmyth_monitor_handler_listener,
- monitor, TRUE, NULL);
- gmyth_debug("MONITOR GThread created!");
+ monitor->io_source = g_io_add_watch (channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
+ gmyth_monitor_handler_listener,
+ monitor);
} else {
ret = FALSE;
- goto cleanup;
}
-
- if (NULL == monitor->th) {
- gmyth_debug
- ("[%s] Error adding GThread listener function to the IO control channel!\n",
- __FUNCTION__);
- ret = FALSE;
- goto cleanup;
- }
-
- cleanup:
-
return ret;
}
-/**
+/**
* Starts the MonitorHandler thread to the GIOWatcher.
- *
+ *
* @param monitor The GMythMonitorHandler instance.
- *
+ *
* @return true
, if the MonitorHandler was started.
*/
gboolean
diff -r c404781fda4e -r 888b9724f601 gmyth/src/gmyth_monitor_handler.h
--- a/gmyth/src/gmyth_monitor_handler.h Tue Aug 21 17:14:42 2007 +0100
+++ b/gmyth/src/gmyth_monitor_handler.h Tue Aug 21 20:04:23 2007 +0100
@@ -63,12 +63,12 @@
GObjectClass parent_class;
/*
- * callbacks
+ * callbacks
*/
guint backend_events_handler_signal_id;
/*
- * signal default handlers
+ * signal default handlers
*/
void (*backend_events_handler) (GMythMonitorHandler *
monitor, gint msg_code,
@@ -88,13 +88,7 @@
*/
GMythSocket *event_sock;
-
-
-
-
-
-
- gpointer(*gmyth_monitor_handler_listener) (gpointer data);
+ //gpointer(*gmyth_monitor_handler_listener) (gpointer data);
gchar *hostname;
gint port;
@@ -109,9 +103,7 @@
GHashTable *backend_msgs;
GMutex *mutex;
-
- GThread *th;
-
+ guint io_source;
};
GType gmyth_monitor_handler_get_type(void);
diff -r c404781fda4e -r 888b9724f601 gmyth/src/gmyth_socket.c
--- a/gmyth/src/gmyth_socket.c Tue Aug 21 17:14:42 2007 +0100
+++ b/gmyth/src/gmyth_socket.c Tue Aug 21 20:04:23 2007 +0100
@@ -1071,7 +1071,7 @@
GIOCondition io_cond;
/*
- * verify if the input (read) buffer is ready to receive data
+ * verify if the input (read) buffer is ready to receive data
*/
g_mutex_lock(gmyth_socket->mutex);
@@ -1085,10 +1085,10 @@
/*
* if ( NULL == gmyth_socket->sd_io_ch->read_buf || ( NULL ==
* gmyth_socket->sd_io_ch->read_buf->str ) ) gmyth_socket->sd_io_ch =
- * g_io_channel_unix_new( gmyth_socket->sd );
+ * g_io_channel_unix_new( gmyth_socket->sd );
*/
- if (gmyth_socket->sd_io_ch->is_readable /* && !( ( io_cond & G_IO_IN )
+ if (gmyth_socket->sd_io_ch->is_readable /* && !( ( io_cond & G_IO_IN )
* == 0 ) */ )
io_status =
g_io_channel_read_chars(gmyth_socket->sd_io_ch, buffer,