branches/gmyth-0.1b/src/gmyth_remote_util.c
branchtrunk
changeset 345 8c26cc7dc51b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/src/gmyth_remote_util.c	Fri Feb 09 20:42:11 2007 +0000
     1.3 @@ -0,0 +1,79 @@
     1.4 +/**
     1.5 + * GMyth Library
     1.6 + *
     1.7 + * @file gmyth/gmyth_remote_util.c
     1.8 + * 
     1.9 + * @brief <p> This component provides utility functions for accessing remote data.
    1.10 + *
    1.11 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    1.12 + * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
    1.13 + *
    1.14 + *//*
    1.15 + * 
    1.16 + * This program is free software; you can redistribute it and/or modify
    1.17 + * it under the terms of the GNU Lesser General Public License as published by
    1.18 + * the Free Software Foundation; either version 2 of the License, or
    1.19 + * (at your option) any later version.
    1.20 + *
    1.21 + * This program is distributed in the hope that it will be useful,
    1.22 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.23 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.24 + * GNU General Public License for more details.
    1.25 + *
    1.26 + * You should have received a copy of the GNU Lesser General Public License
    1.27 + * along with this program; if not, write to the Free Software
    1.28 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.29 + */
    1.30 + 
    1.31 +#ifdef HAVE_CONFIG_H
    1.32 +#include "config.h"
    1.33 +#endif
    1.34 +
    1.35 +#include "gmyth_remote_util.h"
    1.36 + 
    1.37 +#include "gmyth_recorder.h"
    1.38 +#include "gmyth_stringlist.h"
    1.39 +#include "gmyth_debug.h"
    1.40 +
    1.41 +/** Requests the Mythtv backend for a free remote recorder.
    1.42 + * 
    1.43 + * @param curr The recorder index, or -1 to consider the first one.
    1.44 + * @return the remote encoder instance available, or NULL if any error happens.
    1.45 + */
    1.46 +GMythRecorder*
    1.47 +remote_request_next_free_recorder (GMythSocket *socket, int curr)
    1.48 +{
    1.49 +    GMythRecorder *recorder = NULL;
    1.50 +    GString *hostname;
    1.51 +    int num, port;
    1.52 +	
    1.53 +    GMythStringList *strlist = gmyth_string_list_new();
    1.54 +	
    1.55 +    gmyth_debug ("[%s] Request next free recorder in the backend", __FUNCTION__);
    1.56 +	
    1.57 +    gmyth_string_list_append_char_array (strlist, "GET_NEXT_FREE_RECORDER");
    1.58 +    gmyth_string_list_append_int (strlist, curr);
    1.59 +
    1.60 +    if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) {
    1.61 +    	g_warning ("GET_NEXT_FREE_RECORDER request error!\n");
    1.62 +        return NULL;
    1.63 +    }
    1.64 +
    1.65 +    num = gmyth_string_list_get_int (strlist, 0);
    1.66 +    hostname = gmyth_string_list_get_string (strlist, 1);
    1.67 +    port = gmyth_string_list_get_int (strlist, 2);
    1.68 +    
    1.69 +    if ( num < 0 || port < 0 )
    1.70 +    	goto clean_up;
    1.71 +
    1.72 +    gmyth_debug ("[%s] Free recorder info received: num: %d, hostname: %s, port: %d", 
    1.73 +				__FUNCTION__, num, hostname->str, port);
    1.74 +	
    1.75 +    recorder = gmyth_recorder_new (num, hostname, port);
    1.76 +
    1.77 +clean_up:
    1.78 +	
    1.79 +    g_object_unref (strlist);
    1.80 +	
    1.81 +    return recorder;
    1.82 +}