branches/gmyth-0.1b/src/gmyth_remote_util.c
author rosfran
Thu Feb 08 20:57:31 2007 +0000 (2007-02-08)
branchtrunk
changeset 337 60bfeabc0af6
permissions -rw-r--r--
[svn r339] GObject's dispose methods organization, and reviewed clean-up actions.
renatofilho@320
     1
/**
renatofilho@320
     2
 * GMyth Library
renatofilho@320
     3
 *
renatofilho@320
     4
 * @file gmyth/gmyth_remote_util.c
renatofilho@320
     5
 * 
renatofilho@320
     6
 * @brief <p> This component provides utility functions for accessing remote data.
renatofilho@320
     7
 *
renatofilho@320
     8
 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
renatofilho@320
     9
 * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
renatofilho@320
    10
 *
renatofilho@320
    11
 *//*
renatofilho@320
    12
 * 
renatofilho@320
    13
 * This program is free software; you can redistribute it and/or modify
renatofilho@320
    14
 * it under the terms of the GNU Lesser General Public License as published by
renatofilho@320
    15
 * the Free Software Foundation; either version 2 of the License, or
renatofilho@320
    16
 * (at your option) any later version.
renatofilho@320
    17
 *
renatofilho@320
    18
 * This program is distributed in the hope that it will be useful,
renatofilho@320
    19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
renatofilho@320
    20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
renatofilho@320
    21
 * GNU General Public License for more details.
renatofilho@320
    22
 *
renatofilho@320
    23
 * You should have received a copy of the GNU Lesser General Public License
renatofilho@320
    24
 * along with this program; if not, write to the Free Software
renatofilho@320
    25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
renatofilho@320
    26
 */
renatofilho@320
    27
 
renatofilho@320
    28
#ifdef HAVE_CONFIG_H
renatofilho@320
    29
#include "config.h"
renatofilho@320
    30
#endif
renatofilho@320
    31
renatofilho@320
    32
#include "gmyth_remote_util.h"
renatofilho@320
    33
 
renatofilho@320
    34
#include "gmyth_recorder.h"
renatofilho@320
    35
#include "gmyth_stringlist.h"
renatofilho@320
    36
#include "gmyth_debug.h"
renatofilho@320
    37
renatofilho@320
    38
/** Requests the Mythtv backend for a free remote recorder.
renatofilho@320
    39
 * 
renatofilho@320
    40
 * @param curr The recorder index, or -1 to consider the first one.
renatofilho@320
    41
 * @return the remote encoder instance available, or NULL if any error happens.
renatofilho@320
    42
 */
renatofilho@320
    43
GMythRecorder*
renatofilho@320
    44
remote_request_next_free_recorder (GMythSocket *socket, int curr)
renatofilho@320
    45
{
renatofilho@320
    46
    GMythRecorder *recorder = NULL;
renatofilho@320
    47
    GString *hostname;
renatofilho@320
    48
    int num, port;
renatofilho@320
    49
	
renatofilho@320
    50
    GMythStringList *strlist = gmyth_string_list_new();
renatofilho@320
    51
	
renatofilho@320
    52
    gmyth_debug ("[%s] Request next free recorder in the backend", __FUNCTION__);
renatofilho@320
    53
	
renatofilho@320
    54
    gmyth_string_list_append_char_array (strlist, "GET_NEXT_FREE_RECORDER");
renatofilho@320
    55
    gmyth_string_list_append_int (strlist, curr);
renatofilho@320
    56
renatofilho@320
    57
    if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) {
renatofilho@320
    58
    	g_warning ("GET_NEXT_FREE_RECORDER request error!\n");
renatofilho@320
    59
        return NULL;
renatofilho@320
    60
    }
renatofilho@320
    61
renatofilho@320
    62
    num = gmyth_string_list_get_int (strlist, 0);
renatofilho@320
    63
    hostname = gmyth_string_list_get_string (strlist, 1);
renatofilho@320
    64
    port = gmyth_string_list_get_int (strlist, 2);
renatofilho@320
    65
    
renatofilho@320
    66
    if ( num < 0 || port < 0 )
renatofilho@320
    67
    	goto clean_up;
renatofilho@320
    68
renatofilho@320
    69
    gmyth_debug ("[%s] Free recorder info received: num: %d, hostname: %s, port: %d", 
renatofilho@320
    70
				__FUNCTION__, num, hostname->str, port);
renatofilho@320
    71
	
renatofilho@320
    72
    recorder = gmyth_recorder_new (num, hostname, port);
renatofilho@320
    73
renatofilho@320
    74
clean_up:
renatofilho@320
    75
	
renatofilho@320
    76
    g_object_unref (strlist);
renatofilho@320
    77
	
renatofilho@320
    78
    return recorder;
renatofilho@320
    79
}