# HG changeset patch # User rosfran # Date 1170453840 0 # Node ID eb6b0b1409b5e691074446c072768bedda1f9306 # Parent 1c020e9ef06d2453670cd922f111a10e1c55d286 [svn r324] Added function to request how many recorders are available. diff -r 1c020e9ef06d -r eb6b0b1409b5 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Thu Feb 01 22:10:18 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Fri Feb 02 22:04:00 2007 +0000 @@ -303,8 +303,14 @@ res = FALSE; goto error; } + + if ( gmyth_remote_util_get_free_recorder_count (socket) <= 0 ) { + gmyth_debug ("No free remote encoder available."); + res = FALSE; + goto error; + } - // Gets the recorder num + /* Gets the recorder num */ livetv->recorder = remote_request_next_free_recorder (socket, -1); gmyth_socket_close_connection (socket); diff -r 1c020e9ef06d -r eb6b0b1409b5 gmyth/src/gmyth_remote_util.c --- a/gmyth/src/gmyth_remote_util.c Thu Feb 01 22:10:18 2007 +0000 +++ b/gmyth/src/gmyth_remote_util.c Fri Feb 02 22:04:00 2007 +0000 @@ -37,6 +37,7 @@ /** Requests the Mythtv backend for a free remote recorder. * + * @param socket The socket instance where to send the command. * @param curr The recorder index, or -1 to consider the first one. * @return the remote encoder instance available, or NULL if any error happens. */ @@ -45,7 +46,7 @@ { GMythRecorder *recorder = NULL; GString *hostname; - int num, port; + gint num, port; GMythStringList *strlist = gmyth_string_list_new(); @@ -77,3 +78,42 @@ return recorder; } + +/** + * Requests the Mythtv backend for the number of free remote recorders. + * + * @param socket The socket instance where to send the command. + * @return the number of remote encoders instance available, or 0 if no one is actually free.. + */ +gint +gmyth_remote_util_get_free_recorder_count (GMythSocket *socket) +{ + GMythRecorder *recorder = NULL; + gint num_recs = 0; + + GMythStringList *strlist = gmyth_string_list_new(); + + gmyth_debug ("[%s] Request next free recorder in the backend", __FUNCTION__); + + gmyth_string_list_append_char_array (strlist, "GET_FREE_RECORDER_COUNT"); + + if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) { + gmyth_debug ("GET_FREE_RECORDER_COUNT request error!"); + return 0; + } + + num_recs = gmyth_string_list_get_int (strlist, 0); + + if ( num_recs < 0 ) + goto clean_up; + + gmyth_debug ("[%s] Free recorder info received: num recorders: %d", + __FUNCTION__, num_recs); + +clean_up: + + g_object_unref (strlist); + + return num_recs; +} + diff -r 1c020e9ef06d -r eb6b0b1409b5 gmyth/src/gmyth_remote_util.h --- a/gmyth/src/gmyth_remote_util.h Thu Feb 01 22:10:18 2007 +0000 +++ b/gmyth/src/gmyth_remote_util.h Fri Feb 02 22:04:00 2007 +0000 @@ -35,6 +35,7 @@ G_BEGIN_DECLS GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, int curr); +gint gmyth_remote_util_get_free_recorder_count (GMythSocket *socket); G_END_DECLS