gmyth/tests/gmyth_test_recorder.c
author renatofilho
Thu Jun 14 18:19:52 2007 +0100 (2007-06-14)
branchtrunk
changeset 750 312d6bc514f3
parent 618 88001a25ab5a
child 754 cb885ee44618
permissions -rw-r--r--
[svn r756] fixed indent using GNU Style
     1 #include <glib-object.h>
     2 
     3 #include <gmyth/gmyth_backendinfo.h>
     4 #include <gmyth/gmyth_remote_util.h>
     5 #include <gmyth/gmyth_query.h>
     6 #include <gmyth/gmyth_epg.h>
     7 #include <gmyth/gmyth_common.h>
     8 
     9 #include "common.h"
    10 
    11 static gboolean
    12 test_recorder_availability(GMythBackendInfo * backend_info)
    13 {
    14   GMythRecorder *recorder;
    15   GMythSocket *socket = gmyth_socket_new();
    16 
    17   if (gmyth_socket_connect_to_backend(socket,
    18 									  gmyth_backend_info_get_hostname
    19 									  (backend_info),
    20 									  gmyth_backend_info_get_port
    21 									  (backend_info), TRUE) == FALSE)
    22 	{
    23 	  g_debug("Test recorder failed: Connection failed");
    24 	  return FALSE;
    25 	}
    26 
    27   recorder = remote_request_next_free_recorder(socket, -1);
    28   gmyth_socket_close_connection(socket);
    29 
    30   if (socket != NULL)
    31 	g_object_unref(socket);
    32 
    33   if (recorder == NULL)
    34 	{
    35 	  g_debug("Recorder not available\n");
    36 	  return FALSE;
    37 	}
    38 
    39   g_debug("Recorder found (num): %d", recorder->recorder_num);
    40 
    41   if (recorder != NULL)
    42 	g_object_unref(recorder);
    43 
    44   return TRUE;
    45 }
    46 
    47 static gboolean
    48 test_recorder_setup(GMythBackendInfo * backend_info)
    49 {
    50   GMythQuery *query = gmyth_query_new();
    51 
    52   if (gmyth_query_connect_with_timeout(query, backend_info, 3) == TRUE)
    53 	{
    54 	  g_debug("Mysql connection success");
    55 	  return TRUE;
    56 	}
    57   else
    58 	{
    59 	  g_debug("Mysql connection failed");
    60 	  return FALSE;
    61 	}
    62 
    63   if (query != NULL)
    64 	g_object_unref(query);
    65 
    66 }
    67 
    68 static gboolean
    69 test_recorder_check_channels(GMythBackendInfo * backend_info)
    70 {
    71   GMythRecorder *recorder;
    72   GMythSocket *socket = gmyth_socket_new();
    73   GMythEPG *epg = gmyth_epg_new();
    74   GList *clist;
    75   gint i, length;
    76 
    77   // Gets the free recorder
    78   if (gmyth_socket_connect_to_backend(socket,
    79 									  gmyth_backend_info_get_hostname
    80 									  (backend_info),
    81 									  gmyth_backend_info_get_port
    82 									  (backend_info), TRUE) == FALSE)
    83 	{
    84 	  g_debug("Test recorder failed: Connection failed");
    85 	  return FALSE;
    86 	}
    87 
    88   recorder = remote_request_next_free_recorder(socket, -1);
    89   gmyth_socket_close_connection(socket);
    90   g_object_unref(socket);
    91 
    92   if (recorder == NULL)
    93 	{
    94 	  g_debug("[%s] Recorder not available", __FUNCTION__);
    95 	  return FALSE;
    96 	}
    97 
    98   // Connects the recorder socket
    99   gmyth_recorder_setup(recorder);
   100 
   101   // Gets the list of channels
   102   if (!gmyth_epg_connect(epg, backend_info))
   103 	{
   104 	  g_debug("%s: Not connected\n", __FUNCTION__);
   105 	  return FALSE;
   106 	}
   107 
   108   length = gmyth_epg_get_channel_list(epg, &clist);
   109   gmyth_epg_disconnect(epg);
   110   g_object_unref(epg);
   111 
   112   g_print("==== Verifying the %d channels found in the EPG ====\n", length);
   113   for (i = 0; i < length; i++)
   114 	{
   115 	  GMythChannelInfo *channel_info =
   116 		(GMythChannelInfo *) g_list_nth_data(clist, i);
   117 	  gboolean res;
   118 
   119 	  // Checks the channels
   120 	  res = gmyth_recorder_check_channel(recorder, channel_info->channel_ID);
   121 	  g_debug("Channel %d %s", channel_info->channel_ID,
   122 			  res ? "Found" : "Not found");
   123 	}
   124 
   125   g_list_free(clist);
   126 
   127   if (recorder != NULL)
   128 	g_object_unref(recorder);
   129 
   130 }
   131 
   132 int
   133 main(int args, const char **argv)
   134 {
   135 
   136   GMythBackendInfo *backend_info;
   137   g_type_init();
   138   g_thread_init(NULL);
   139 
   140   backend_info = gmyth_backend_info_new_with_uri(argv[1]);
   141 
   142   printf("******** Testing recorder availability ***********\n");
   143   test_recorder_availability(backend_info);
   144 
   145   printf("******** Testing recorder check channels function ***********\n");
   146   test_recorder_check_channels(backend_info);
   147 
   148   fprintf(stdout, SYNC_STRING);
   149   fflush(NULL);
   150   getchar();
   151 
   152   if (backend_info != NULL)
   153 	g_object_unref(backend_info);
   154 
   155   return (0);
   156 
   157 }