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