[svn r324] Added function to request how many recorders are available. trunk
authorrosfran
Fri Feb 02 22:04:00 2007 +0000 (2007-02-02)
branchtrunk
changeset 322eb6b0b1409b5
parent 321 1c020e9ef06d
child 323 6523ab923c00
[svn r324] Added function to request how many recorders are available.
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_remote_util.c
gmyth/src/gmyth_remote_util.h
     1.1 --- a/gmyth/src/gmyth_livetv.c	Thu Feb 01 22:10:18 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_livetv.c	Fri Feb 02 22:04:00 2007 +0000
     1.3 @@ -303,8 +303,14 @@
     1.4  		res = FALSE;
     1.5  		goto error;
     1.6  	}
     1.7 +	
     1.8 +	if ( gmyth_remote_util_get_free_recorder_count (socket) <= 0 ) {
     1.9 +		gmyth_debug ("No free remote encoder available.");
    1.10 +		res = FALSE;
    1.11 +		goto error;
    1.12 +	}
    1.13  
    1.14 -	// Gets the recorder num
    1.15 +	/* Gets the recorder num */
    1.16  	livetv->recorder = remote_request_next_free_recorder (socket, -1);
    1.17  	gmyth_socket_close_connection (socket);
    1.18  
     2.1 --- a/gmyth/src/gmyth_remote_util.c	Thu Feb 01 22:10:18 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_remote_util.c	Fri Feb 02 22:04:00 2007 +0000
     2.3 @@ -37,6 +37,7 @@
     2.4  
     2.5  /** Requests the Mythtv backend for a free remote recorder.
     2.6   * 
     2.7 + * @param socket The socket instance where to send the command.
     2.8   * @param curr The recorder index, or -1 to consider the first one.
     2.9   * @return the remote encoder instance available, or NULL if any error happens.
    2.10   */
    2.11 @@ -45,7 +46,7 @@
    2.12  {
    2.13      GMythRecorder *recorder = NULL;
    2.14      GString *hostname;
    2.15 -    int num, port;
    2.16 +    gint num, port;
    2.17  	
    2.18      GMythStringList *strlist = gmyth_string_list_new();
    2.19  	
    2.20 @@ -77,3 +78,42 @@
    2.21  	
    2.22      return recorder;
    2.23  }
    2.24 +
    2.25 +/** 
    2.26 + * Requests the Mythtv backend for the number of free remote recorders.
    2.27 + * 
    2.28 + * @param socket The socket instance where to send the command.
    2.29 + * @return the number of remote encoders instance available, or 0 if no one is actually free..
    2.30 + */
    2.31 +gint
    2.32 +gmyth_remote_util_get_free_recorder_count (GMythSocket *socket)
    2.33 +{
    2.34 +    GMythRecorder *recorder = NULL;
    2.35 +    gint num_recs = 0;
    2.36 +	
    2.37 +    GMythStringList *strlist = gmyth_string_list_new();
    2.38 +	
    2.39 +    gmyth_debug ("[%s] Request next free recorder in the backend", __FUNCTION__);
    2.40 +	
    2.41 +    gmyth_string_list_append_char_array (strlist, "GET_FREE_RECORDER_COUNT");
    2.42 +
    2.43 +    if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) {
    2.44 +    	gmyth_debug ("GET_FREE_RECORDER_COUNT request error!");
    2.45 +      return 0;
    2.46 +    }
    2.47 +    
    2.48 +    num_recs = gmyth_string_list_get_int (strlist, 0);
    2.49 +    
    2.50 +    if ( num_recs < 0 )
    2.51 +    	goto clean_up;
    2.52 +
    2.53 +    gmyth_debug ("[%s] Free recorder info received: num recorders: %d", 
    2.54 +				__FUNCTION__, num_recs);	
    2.55 +
    2.56 +clean_up:
    2.57 +	
    2.58 +    g_object_unref (strlist);
    2.59 +	
    2.60 +    return num_recs;
    2.61 +}
    2.62 +
     3.1 --- a/gmyth/src/gmyth_remote_util.h	Thu Feb 01 22:10:18 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_remote_util.h	Fri Feb 02 22:04:00 2007 +0000
     3.3 @@ -35,6 +35,7 @@
     3.4  G_BEGIN_DECLS
     3.5  
     3.6  GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, int curr);
     3.7 +gint					 gmyth_remote_util_get_free_recorder_count (GMythSocket *socket);
     3.8  
     3.9  G_END_DECLS
    3.10