gmyth/src/gmyth_remote_util.c
author melunko
Wed Aug 22 14:55:41 2007 +0100 (2007-08-22)
branchtrunk
changeset 820 a223e9d89b01
parent 750 312d6bc514f3
permissions -rw-r--r--
[svn r826] gmyth-ls and gmyth_query now considers db_port. Thanks to Bastien Nocera for his patch.
     1 /**
     2  * GMyth Library
     3  *
     4  * @file gmyth/gmyth_remote_util.c
     5  * 
     6  * @brief <p> This component provides utility functions for accessing remote data.
     7  *
     8  * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     9  * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
    10  * @author Rosfran Borges <rosfran.borges@indt.org.br>
    11  *
    12  * 
    13  * This program is free software; you can redistribute it and/or modify
    14  * it under the terms of the GNU Lesser General Public License as published by
    15  * the Free Software Foundation; either version 2 of the License, or
    16  * (at your option) any later version.
    17  *
    18  * This program is distributed in the hope that it will be useful,
    19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  * GNU General Public License for more details.
    22  *
    23  * You should have received a copy of the GNU Lesser General Public License
    24  * along with this program; if not, write to the Free Software
    25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    26  */
    27 
    28 #ifdef HAVE_CONFIG_H
    29 #include "config.h"
    30 #endif
    31 
    32 #include "gmyth_remote_util.h"
    33 
    34 #include "gmyth_recorder.h"
    35 #include "gmyth_stringlist.h"
    36 #include "gmyth_debug.h"
    37 
    38 /** 
    39  * Requests the Mythtv backend for a free remote recorder.
    40  * 
    41  * @param socket The socket instance where to send the command.
    42  * @param curr The recorder index, or -1 to consider the first one.
    43  * 
    44  * @return the remote encoder instance available, or NULL if any error happens.
    45  */
    46 GMythRecorder  *
    47 remote_request_next_free_recorder(GMythSocket * socket, gint curr)
    48 {
    49     GMythRecorder  *recorder = NULL;
    50     GString        *hostname;
    51     gint            num,
    52                     port;
    53 
    54     GMythStringList *strlist = gmyth_string_list_new();
    55 
    56     gmyth_debug("[%s] Request next free recorder in the backend",
    57                 __FUNCTION__);
    58 
    59     gmyth_string_list_append_char_array(strlist, "GET_NEXT_FREE_RECORDER");
    60     gmyth_string_list_append_int(strlist, curr);
    61 
    62     if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) {
    63         g_warning("GET_NEXT_FREE_RECORDER request error!\n");
    64         return NULL;
    65     }
    66 
    67     num = gmyth_string_list_get_int(strlist, 0);
    68     hostname = gmyth_string_list_get_string(strlist, 1);
    69     port = gmyth_string_list_get_int(strlist, 2);
    70 
    71     if (num < 0 || port < 0)
    72         goto clean_up;
    73 
    74     gmyth_debug
    75         ("[%s] Free recorder info received: num: %d, hostname: %s, port: %d",
    76          __FUNCTION__, num, hostname->str, port);
    77 
    78     recorder = gmyth_recorder_new(num, hostname, port);
    79 
    80   clean_up:
    81 
    82     g_string_free(hostname, TRUE);
    83     g_object_unref(strlist);
    84 
    85     return recorder;
    86 }
    87 
    88 /** 
    89  * Requests the Mythtv backend for the number of free remote recorders.
    90  * 
    91  * @param socket The socket instance where to send the command.
    92  * 
    93  * @return the number of remote encoders instance available, or 0 if no one is actually free..
    94  */
    95 gint
    96 gmyth_remote_util_get_free_recorder_count(GMythSocket * socket)
    97 {
    98     gint            num_recs = 0;
    99 
   100     GMythStringList *strlist = gmyth_string_list_new();
   101 
   102     gmyth_debug("[%s] Request next free recorder in the backend",
   103                 __FUNCTION__);
   104 
   105     gmyth_string_list_append_char_array(strlist,
   106                                         "GET_FREE_RECORDER_COUNT");
   107 
   108     if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) {
   109         gmyth_debug("GET_FREE_RECORDER_COUNT request error!");
   110         return 0;
   111     }
   112 
   113     num_recs = gmyth_string_list_get_int(strlist, 0);
   114 
   115     if (num_recs < 0)
   116         goto clean_up;
   117 
   118     gmyth_debug("[%s] Free recorder info received: num recorders: %d",
   119                 __FUNCTION__, num_recs);
   120 
   121   clean_up:
   122 
   123     g_object_unref(strlist);
   124 
   125     return num_recs;
   126 }