[svn r213] Include GObject signal connects/emmits to GMythMonitorHandler.
1.1 --- a/gmyth/src/Makefile.am Wed Dec 06 21:50:34 2006 +0000
1.2 +++ b/gmyth/src/Makefile.am Thu Dec 07 18:39:41 2006 +0000
1.3 @@ -2,7 +2,11 @@
1.4
1.5 lib_LTLIBRARIES = libgmyth.la
1.6
1.7 -libgmyth_la_SOURCES = \
1.8 +BUILT_SOURCES = \
1.9 + gmyth_marshal.c \
1.10 + gmyth_marshal.h
1.11 +
1.12 +libgmyth_la_SOURCES = \
1.13 gmyth_common.c \
1.14 gmyth_debug.c \
1.15 gmyth_epg.c \
1.16 @@ -14,34 +18,47 @@
1.17 gmyth_query.c \
1.18 gmyth_socket.c \
1.19 gmyth_stringlist.c \
1.20 - gmyth_monitor_handler.c \
1.21 - gmyth_file_transfer.c \
1.22 + gmyth_monitor_handler.c \
1.23 + gmyth_file_transfer.c \
1.24 gmyth_livetv.c \
1.25 gmyth_backendinfo.c \
1.26 gmyth_programinfo.c \
1.27 - gmyth_uri.c
1.28 + gmyth_uri.c \
1.29 + $(BUILT_SOURCES)
1.30
1.31 -libgmyth_la_CFLAGS = \
1.32 - -DDATADIR=\"$(pkgdatadir)\" \
1.33 +EXTRA_libgmyth_la_SOURCES = gmyth_marshal.list
1.34 +
1.35 +gmyth_marshal.h: gmyth_marshal.list
1.36 + glib-genmarshal --header --prefix=gmyth_marshal gmyth_marshal.list > gmyth_marshal.h.tmp
1.37 + mv gmyth_marshal.h.tmp gmyth_marshal.h
1.38 +
1.39 +gmyth_marshal.c: gmyth_marshal.list gmyth_marshal.h
1.40 + echo "#include \"glib-object.h\"" > gmyth_marshal.c.tmp
1.41 + echo "#include \"gmyth_marshal.h\"" >> gmyth_marshal.c.tmp
1.42 + glib-genmarshal --body --prefix=gmyth_marshal $(srcdir)/gmyth_marshal.list >> gmyth_marshal.c.tmp
1.43 + mv gmyth_marshal.c.tmp gmyth_marshal.c
1.44 +
1.45 +libgmyth_la_CFLAGS = \
1.46 + -DDATADIR=\"$(pkgdatadir)\" \
1.47 $(GLIB_CFLAGS) \
1.48 $(GOBJECT_CFLAGS) \
1.49 $(GST_CFLAGS) \
1.50 $(GSTBASE_CFLAGS) \
1.51 - $(GSTPLUGINSBASE_CFLAGS) \
1.52 + $(GSTPLUGINSBASE_CFLAGS) \
1.53 $(MYSQL_CFLAGS)
1.54
1.55 -libgmyth_la_LDFLAGS = \
1.56 +libgmyth_la_LDFLAGS = \
1.57 -export-dynamic \
1.58 $(MYSQL_LIBS) \
1.59 $(GST_LIBS) \
1.60 $(GSTBASE_LIBS) \
1.61 $(GSTPLUGINS_LIBS)
1.62
1.63 -libgmyth_includedir = \
1.64 +libgmyth_includedir = \
1.65 $(pkgincludedir)
1.66
1.67 -libgmyth_include_HEADERS = \
1.68 - gmyth.h \
1.69 +libgmyth_include_HEADERS = \
1.70 + gmyth.h \
1.71 gmyth_common.h \
1.72 gmyth_debug.h \
1.73 gmyth_epg.h \
1.74 @@ -53,12 +70,11 @@
1.75 gmyth_socket.h \
1.76 gmyth_remote_util.h \
1.77 gmyth_stringlist.h \
1.78 - gmyth_monitor_handler.h \
1.79 - gmyth_file_transfer.h \
1.80 + gmyth_monitor_handler.h \
1.81 + gmyth_file_transfer.h \
1.82 gmyth_livetv.h \
1.83 gmyth_backendinfo.h \
1.84 gmyth_programinfo.h \
1.85 gmyth_uri.h
1.86
1.87 CLEANFILES = $(BUILT_SOURCES)
1.88 -
2.1 --- a/gmyth/src/gmyth_livetv.c Wed Dec 06 21:50:34 2006 +0000
2.2 +++ b/gmyth/src/gmyth_livetv.c Thu Dec 07 18:39:41 2006 +0000
2.3 @@ -111,6 +111,13 @@
2.4 return livetv;
2.5 }
2.6
2.7 +static void
2.8 +gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code,
2.9 + gchar* message )
2.10 +{
2.11 + gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d )\n", message, msg_code );
2.12 +}
2.13 +
2.14 gboolean
2.15 gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
2.16 {
2.17 @@ -143,6 +150,9 @@
2.18 if (res)
2.19 {
2.20 gmyth_debug("MythTV Monitor event socket connected and listening!");
2.21 + g_signal_connect (G_OBJECT (livetv->monitor), "backend-events-handler",
2.22 + (GCallback)gmyth_livetv_monitor_signal_handler,
2.23 + NULL);
2.24 }
2.25 else
2.26 {
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/gmyth/src/gmyth_marshal.list Thu Dec 07 18:39:41 2006 +0000
3.3 @@ -0,0 +1,1 @@
3.4 +VOID:INT,STRING
4.1 --- a/gmyth/src/gmyth_monitor_handler.c Wed Dec 06 21:50:34 2006 +0000
4.2 +++ b/gmyth/src/gmyth_monitor_handler.c Thu Dec 07 18:39:41 2006 +0000
4.3 @@ -32,6 +32,10 @@
4.4 * - port number *
4.5 */
4.6
4.7 +#ifdef HAVE_CONFIG_H
4.8 +#include "config.h"
4.9 +#endif
4.10 +
4.11 #include "gmyth_uri.h"
4.12 #include "gmyth_livetv.h"
4.13 #include "gmyth_util.h"
4.14 @@ -39,6 +43,7 @@
4.15 #include "gmyth_stringlist.h"
4.16 #include "gmyth_monitor_handler.h"
4.17 #include "gmyth_debug.h"
4.18 +#include "gmyth_marshal.h"
4.19
4.20 #include <unistd.h>
4.21 #include <glib.h>
4.22 @@ -74,11 +79,10 @@
4.23
4.24 GThreadPool *monitor_th = NULL;
4.25
4.26 -enum myth_sock_types {
4.27 - GMYTH_PLAYBACK_TYPE = 0,
4.28 - GMYTH_MONITOR_TYPE,
4.29 - GMYTH_FILETRANSFER_TYPE,
4.30 - GMYTH_RINGBUFFER_TYPE
4.31 +enum gmyth_monitor_handler_msg_types {
4.32 + GMYTH_BACKEND_NO_MESSAGE = 0,
4.33 + GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
4.34 + GMYTH_BACKEND_STOP_LIVETV
4.35 };
4.36
4.37 //static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
4.38 @@ -86,7 +90,8 @@
4.39 // gpointer data );
4.40 //static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret );
4.41
4.42 -static void gmyth_monitor_handler_listener ( GMythSocket *gmyth_socket, gboolean* ret );
4.43 +static void gmyth_monitor_handler_listener (GMythMonitorHandler *monitor,
4.44 + gpointer user_data);
4.45
4.46 static GMutex* mutex = NULL;
4.47
4.48 @@ -117,16 +122,17 @@
4.49 gobject_class->finalize = gmyth_monitor_handler_finalize;
4.50
4.51 gmonitor_class->backend_events_handler_signal_id =
4.52 - g_signal_newv ("backend-events-handler",
4.53 - G_TYPE_FROM_CLASS (gmonitor_class),
4.54 - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
4.55 - NULL /* class closure */,
4.56 - NULL /* accumulator */,
4.57 - NULL /* accu_data */,
4.58 - g_cclosure_marshal_VOID__VOID,
4.59 - G_TYPE_NONE /* return_type */,
4.60 - 0 /* n_params */,
4.61 - NULL /* param_types */);
4.62 + g_signal_new ("backend-events-handler",
4.63 + G_TYPE_FROM_CLASS (gmonitor_class),
4.64 + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
4.65 + 0,
4.66 + NULL,
4.67 + NULL,
4.68 + gmyth_marshal_VOID__INT_STRING,
4.69 + G_TYPE_NONE,
4.70 + 2,
4.71 + G_TYPE_INT,
4.72 + G_TYPE_STRING);
4.73
4.74 }
4.75
4.76 @@ -242,16 +248,66 @@
4.77
4.78 }
4.79
4.80 +static gint
4.81 +gmyth_monitor_handler_is_backend_message( GMythMonitorHandler *monitor,
4.82 + GMythStringList* strlist, gchar **back_msg_action )
4.83 +{
4.84 + gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
4.85 + GString *back_msg = NULL;
4.86 +
4.87 + back_msg = gmyth_string_list_get_string( strlist, 0 );
4.88 + if ( back_msg != NULL && back_msg->str != NULL &&
4.89 + strstr( back_msg->str, "BACKEND" ) != NULL )
4.90 + {
4.91 + if ( monitor->backend_msgs != NULL )
4.92 + {
4.93 + *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );
4.94 +
4.95 + if ( back_msg_action != NULL )
4.96 + {
4.97 +
4.98 + if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
4.99 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
4.100 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
4.101 + {
4.102 + msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
4.103 + }
4.104 +
4.105 + //g_hash_table_insert ( monitor->backend_msgs,
4.106 + // &(monitor->actual_index), *back_msg_action );
4.107 +
4.108 + } // if
4.109 +
4.110 + } // if
4.111 + }
4.112 +
4.113 + if ( back_msg != NULL )
4.114 + {
4.115 + g_string_free( back_msg, TRUE );
4.116 + back_msg = NULL;
4.117 + }
4.118 +
4.119 + return msg_type;
4.120 +
4.121 +}
4.122 +
4.123 +/*
4.124 +static void
4.125 +gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gpointer message )
4.126 +{
4.127 + //assert( message!= NULL );
4.128 + gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d )\n", (gchar*)message, msg_code );
4.129 +}
4.130 +*/
4.131 +
4.132 static void
4.133 gmyth_monitor_handler_print( GString *str, gpointer ptr )
4.134 {
4.135 - gmyth_debug( "Backend message event: %s.\n", str->str );
4.136 + gmyth_debug( "Backend message event: %s --- ", str->str );
4.137 }
4.138
4.139 static void
4.140 -//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
4.141 -//myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret )
4.142 -gmyth_monitor_handler_listener ( GMythSocket *gmyth_socket, gboolean* ret )
4.143 +gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
4.144 {
4.145
4.146 GIOStatus io_status;
4.147 @@ -260,14 +316,14 @@
4.148 //gchar *trash = NULL;
4.149 //GByteArray *byte_array = NULL;
4.150 guint recv = 0;
4.151 - ret = g_new0( gboolean, 1 );
4.152 + gboolean *ret = g_new0( gboolean, 1 );
4.153 *ret = TRUE;
4.154 //gboolean ret = TRUE;
4.155 gsize len = 0;
4.156
4.157 static guint count = 0;
4.158
4.159 - GIOChannel *io_channel = gmyth_socket->sd_io_ch;
4.160 + GIOChannel *io_channel = monitor->event_sock->sd_io_ch;
4.161 //GIOCondition condition = g_io_channel_get_buffer_condition( io_channel );
4.162
4.163 GMythStringList *strlist = NULL;
4.164 @@ -287,7 +343,6 @@
4.165
4.166 gmyth_debug ("%d - Listening on Monitor socket...!\n", count);
4.167
4.168 - guint buffer_size = GMYTHTV_BUFFER_SIZE;
4.169 do
4.170 {
4.171
4.172 @@ -295,7 +350,7 @@
4.173
4.174 strlist = gmyth_string_list_new();
4.175
4.176 - len = gmyth_socket_read_stringlist( gmyth_socket, strlist );
4.177 + len = gmyth_socket_read_stringlist( monitor->event_sock, strlist );
4.178
4.179 if ( strlist != NULL && gmyth_string_list_length( strlist ) > 0 )
4.180 {
4.181 @@ -310,6 +365,18 @@
4.182 /* debug purpose: prints out all the string list elements */
4.183 g_list_foreach( strlist->glist, (GFunc)gmyth_monitor_handler_print, NULL );
4.184
4.185 + gchar *back_msg_action = g_new0( gchar, 1 );
4.186 + gint msg_type = gmyth_monitor_handler_is_backend_message( monitor, strlist,
4.187 + &back_msg_action );
4.188 +
4.189 + g_signal_emit ( monitor,
4.190 + GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id,
4.191 + 0, /* details */
4.192 + msg_type, back_msg_action );
4.193 +
4.194 + if (back_msg_action!= NULL)
4.195 + g_free( back_msg_action );
4.196 +
4.197 }
4.198
4.199 if (strlist!=NULL)
4.200 @@ -319,9 +386,7 @@
4.201
4.202 } while ( ( io_cond & G_IO_IN ) != 0 );
4.203
4.204 - gmyth_debug ("\n\n\n[%s]\tMONITOR EVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv,
4.205 - strlist != NULL && strlist->glist != NULL ?
4.206 - gmyth_string_list_get_char_array( strlist, 0 ) : "[no event data]" );
4.207 + gmyth_debug ("[%s]\tMONITOR EVENT: Read %d bytes\n", __FUNCTION__, recv );
4.208
4.209 g_usleep( 300 );
4.210
4.211 @@ -334,11 +399,6 @@
4.212 goto clean_up;
4.213 }
4.214
4.215 - //g_hash_table_insert( monitor->backend_msgs, (gpointer)monitor->actual_index,
4.216 - // byte_array->data );
4.217 -
4.218 - //monitor->actual_index += recv;
4.219 -
4.220 clean_up:
4.221
4.222 if (strlist!=NULL)
4.223 @@ -371,6 +431,7 @@
4.224 return ret;
4.225 }
4.226
4.227 +/*
4.228 static gboolean*
4.229 gmyth_monitor_handler_setup( GIOChannel *channel )
4.230 {
4.231 @@ -418,6 +479,7 @@
4.232 return ret;
4.233
4.234 }
4.235 +*/
4.236
4.237 gboolean
4.238 gmyth_monitor_handler_start (GMythMonitorHandler *monitor)
4.239 @@ -428,9 +490,9 @@
4.240 if (!g_thread_supported () ) g_thread_init (NULL);
4.241
4.242 monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener,
4.243 - monitor->event_sock, 3, TRUE, NULL );
4.244 + monitor, 3, TRUE, NULL );
4.245
4.246 - g_thread_pool_push( monitor_th, monitor->event_sock, NULL );
4.247 + g_thread_pool_push( monitor_th, monitor, NULL );
4.248
4.249 //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
4.250 if ( monitor_th != NULL )
5.1 --- a/gmyth/src/gmyth_monitor_handler.h Wed Dec 06 21:50:34 2006 +0000
5.2 +++ b/gmyth/src/gmyth_monitor_handler.h Thu Dec 07 18:39:41 2006 +0000
5.3 @@ -66,7 +66,7 @@
5.4 guint backend_events_handler_signal_id;
5.5
5.6 /* signal default handlers */
5.7 - void (*backend_events_handler) (GMythMonitorHandler *self);
5.8 + void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message );
5.9 };
5.10
5.11 struct _GMythMonitorHandler