rosfran@683
|
1 |
#include <glib-object.h>
|
rosfran@683
|
2 |
|
rosfran@683
|
3 |
#include "common.h"
|
rosfran@683
|
4 |
|
rosfran@683
|
5 |
#include <gmyth/gmyth_uri.h>
|
rosfran@683
|
6 |
#include <gmyth/gmyth_backendinfo.h>
|
rosfran@683
|
7 |
#include <gmyth/gmyth_livetv.h>
|
rosfran@683
|
8 |
#include <gmyth/gmyth_file.h>
|
rosfran@683
|
9 |
#include <gmyth/gmyth_file_transfer.h>
|
rosfran@683
|
10 |
#include <gmyth/gmyth_file_local.h>
|
rosfran@683
|
11 |
#include <gmyth/gmyth_common.h>
|
rosfran@683
|
12 |
|
rosfran@683
|
13 |
#define URI_DEFAULT "myth://192.168.3.165:6543/livetv?channel=9"
|
rosfran@683
|
14 |
|
rosfran@683
|
15 |
static gboolean
|
rosfran@683
|
16 |
test_tvchain_setup ( gchar *uri )
|
rosfran@683
|
17 |
{
|
rosfran@683
|
18 |
GMythTVChain *tvchain = NULL;
|
rosfran@683
|
19 |
gchar *channel = NULL;
|
rosfran@683
|
20 |
gboolean ret = TRUE;
|
rosfran@683
|
21 |
|
rosfran@683
|
22 |
if ( NULL == uri )
|
rosfran@683
|
23 |
uri = g_strdup( URI_DEFAULT );
|
rosfran@683
|
24 |
|
rosfran@683
|
25 |
GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
|
rosfran@683
|
26 |
|
rosfran@683
|
27 |
GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
|
rosfran@683
|
28 |
|
rosfran@683
|
29 |
channel = gmyth_uri_get_channel_name( gmyth_uri );
|
rosfran@683
|
30 |
|
rosfran@683
|
31 |
/* Creates livetv chain handler */
|
rosfran@683
|
32 |
tvchain = gmyth_tvchain_new ();
|
rosfran@683
|
33 |
gmyth_tvchain_initialize (tvchain, backend_info);
|
rosfran@683
|
34 |
|
rosfran@683
|
35 |
if (tvchain == NULL || tvchain->tvchain_id == NULL)
|
rosfran@683
|
36 |
{
|
rosfran@683
|
37 |
ret = FALSE;
|
rosfran@683
|
38 |
goto init_failed;
|
rosfran@683
|
39 |
}
|
rosfran@683
|
40 |
|
rosfran@683
|
41 |
ret = ( gmyth_tvchain_get_id (tvchain) != NULL );
|
rosfran@683
|
42 |
if (!ret)
|
rosfran@683
|
43 |
{
|
rosfran@683
|
44 |
g_debug ("[%s] TV Chain ID is NULL.\n", __FUNCTION__);
|
rosfran@683
|
45 |
goto init_failed;
|
rosfran@683
|
46 |
}
|
rosfran@683
|
47 |
|
rosfran@683
|
48 |
gmyth_backend_info_set_username (tvchain->backend_info,
|
rosfran@683
|
49 |
"mythtv");
|
rosfran@683
|
50 |
gmyth_backend_info_set_password (tvchain->backend_info,
|
rosfran@683
|
51 |
"mythtv");
|
rosfran@683
|
52 |
gmyth_backend_info_set_db_name (tvchain->backend_info,
|
rosfran@683
|
53 |
"mythconverg");
|
rosfran@683
|
54 |
GList *prog_list =
|
rosfran@683
|
55 |
gmyth_tvchain_get_program_info_from_channel (tvchain,
|
rosfran@683
|
56 |
channel);
|
rosfran@683
|
57 |
GMythProgramInfo *ch_prog = NULL;
|
rosfran@683
|
58 |
if (prog_list != NULL && g_list_length (prog_list) > 0)
|
rosfran@683
|
59 |
{
|
rosfran@683
|
60 |
ch_prog = (GMythProgramInfo *) g_list_nth_data (prog_list, 0);
|
rosfran@683
|
61 |
g_debug ("Channel program info (from a list with size = %d)!",
|
rosfran@683
|
62 |
g_list_length (prog_list));
|
rosfran@683
|
63 |
gmyth_program_info_print (ch_prog);
|
rosfran@683
|
64 |
}
|
rosfran@683
|
65 |
|
rosfran@683
|
66 |
g_debug ("Program Info: %s\n",
|
rosfran@683
|
67 |
gmyth_program_info_to_string (ch_prog));
|
rosfran@683
|
68 |
|
rosfran@683
|
69 |
/* Reload all TV chain from Mysql database. */
|
rosfran@683
|
70 |
gmyth_tvchain_reload_all (tvchain);
|
rosfran@683
|
71 |
|
rosfran@683
|
72 |
if (tvchain == NULL)
|
rosfran@683
|
73 |
{
|
rosfran@683
|
74 |
ret = FALSE;
|
rosfran@683
|
75 |
goto init_failed;
|
rosfran@683
|
76 |
}
|
rosfran@683
|
77 |
|
rosfran@683
|
78 |
/* Get program info from database using chanid and starttime */
|
rosfran@683
|
79 |
ch_prog = gmyth_tvchain_get_program_at (tvchain, 0);
|
rosfran@683
|
80 |
if (NULL == ch_prog)
|
rosfran@683
|
81 |
{
|
rosfran@683
|
82 |
g_debug ("TVChain not successfully started.\n");
|
rosfran@683
|
83 |
ret = FALSE;
|
rosfran@683
|
84 |
goto init_failed;
|
rosfran@683
|
85 |
}
|
rosfran@683
|
86 |
else
|
rosfran@683
|
87 |
{
|
rosfran@683
|
88 |
ret = TRUE;
|
rosfran@683
|
89 |
g_debug
|
rosfran@683
|
90 |
("GMythTVChain: All requests to backend to start TV were OK. [%s]\n",
|
rosfran@683
|
91 |
ch_prog->pathname->str);
|
rosfran@683
|
92 |
}
|
rosfran@683
|
93 |
|
rosfran@683
|
94 |
|
rosfran@683
|
95 |
init_failed:
|
rosfran@683
|
96 |
if ( tvchain != NULL )
|
rosfran@683
|
97 |
g_object_unref(tvchain);
|
rosfran@683
|
98 |
|
rosfran@683
|
99 |
if ( gmyth_uri != NULL )
|
rosfran@683
|
100 |
g_object_unref( gmyth_uri );
|
rosfran@683
|
101 |
|
rosfran@683
|
102 |
if ( ch_prog != NULL )
|
rosfran@683
|
103 |
g_object_unref( ch_prog );
|
rosfran@683
|
104 |
|
rosfran@683
|
105 |
if ( prog_list != NULL )
|
rosfran@683
|
106 |
g_list_free( prog_list );
|
rosfran@683
|
107 |
|
rosfran@683
|
108 |
if ( backend_info != NULL )
|
rosfran@683
|
109 |
g_object_unref( backend_info );
|
rosfran@683
|
110 |
|
rosfran@683
|
111 |
return ret;
|
rosfran@683
|
112 |
|
rosfran@683
|
113 |
}
|
rosfran@683
|
114 |
|
rosfran@683
|
115 |
gint
|
rosfran@683
|
116 |
main (gint args, const gchar **argv)
|
rosfran@683
|
117 |
{
|
rosfran@683
|
118 |
gboolean ret;
|
rosfran@683
|
119 |
|
rosfran@683
|
120 |
g_type_init ();
|
rosfran@683
|
121 |
g_thread_init (NULL);
|
rosfran@683
|
122 |
|
rosfran@683
|
123 |
fprintf(stdout, SYNC_STRING);
|
rosfran@683
|
124 |
fflush(NULL);
|
rosfran@683
|
125 |
getchar();
|
rosfran@683
|
126 |
|
rosfran@683
|
127 |
if ( args > 1 )
|
rosfran@683
|
128 |
ret = test_tvchain_setup ( argv[1] );
|
rosfran@683
|
129 |
else
|
rosfran@683
|
130 |
ret = test_tvchain_setup ( NULL );
|
rosfran@683
|
131 |
|
rosfran@683
|
132 |
if ( !ret )
|
rosfran@683
|
133 |
g_debug ("Error when running TV Chain setup test script!");
|
rosfran@683
|
134 |
else
|
rosfran@683
|
135 |
g_debug ("TV Chain setup test script finished with success.");
|
rosfran@683
|
136 |
|
rosfran@683
|
137 |
return(0);
|
rosfran@683
|
138 |
}
|
rosfran@683
|
139 |
|
rosfran@683
|
140 |
|
rosfran@683
|
141 |
|
rosfran@683
|
142 |
|