This is an example of how to use the TV Service's interface to get program information.
#include <glib-object.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gprintf.h>
static GMainLoop *mainloop = NULL;
static gint g_service_count = 0;
static void
test_print_help (char * argv)
{
g_printf ("| TV Service EPG Scenario Test \n");
g_printf ("| Test exits after getting epg info or using 'Ctrl+C' key\n\n");
g_printf ("| get all programs by service_id: \n");
g_printf ("| %s -a {service_id list}\n", argv);
g_printf ("| ie) %s -a 1 \n", argv);
g_printf ("| ie) %s -a 2 3 4 5\n\n", argv);
g_printf ("| get program of current date time by service_id: \n");
g_printf ("| %s -c {service_id list}\n", argv);
g_printf ("| ie) %s -c 1 \n", argv);
g_printf ("| ie) %s -c 2 3 4 5\n\n", argv);
g_printf ("| get programs by service_id and date time: \n");
g_printf ("| %s -s {service_id} {date} {time} {duration}\n", argv);
g_printf ("| ie) %s -s 1 20130815 120000 3600\n", argv);
g_printf ("| 20130815 means 2013-08-15, 120000 means 12:00:00, 3600 means 1 hour\n\n");
g_printf ("| get programs of one whole day for all services: \n");
g_printf ("| %s -d {date}\n", argv);
g_printf ("| ie) %s -d 20130815\n", argv);
g_printf ("| 20130815 means 2013-08-15\n\n");
g_printf ("| get current program from database directly: \n");
g_printf ("| %s -o {service_id list}\n", argv);
g_printf ("| ie) %s -o 1 \n", argv);
g_printf ("| ie) %s -o 2 3 4 5\n", argv);
}
static void
{
gint hour = 0;
gint min = 0;
gint sec = 0;
if (!p_epg_data)
return;
g_printf (
"service_id = [%d]\n", p_epg_data->
service_id);
g_printf (
"event_id = [%d]\n", p_epg_data->
event_id);
g_printf (
"title = [%s]\n", p_epg_data->
title_text);
GDateTime *g_time = g_date_time_new_from_unix_utc (p_epg_data->
start_time);
g_printf ("start_time = [%d.%d.%d-%d:%d:%d] UTC[%u]\n",
g_date_time_get_year (g_time),
g_date_time_get_month (g_time),
g_date_time_get_day_of_month (g_time),
g_date_time_get_hour (g_time),
g_date_time_get_minute (g_time),
g_date_time_get_second (g_time),
g_printf ("duration = [%d:%d:%d]\n", hour, min, sec);
}
static gint64
get_start_time_sec (gint date_day, gint date_hour)
{
gint year = date_day / 10000;
gint month = (date_day - year * 10000) / 100;
gint day = date_day - year * 10000 - month * 100;
gint hour = date_hour / 10000;
gint min = (date_hour - hour * 10000) / 100;
gint sec = date_hour - hour * 10000 - min * 100;
gint64 ret_time = 0;
GDateTime *g_time_t1 = g_date_time_new_utc (year, month, day, hour, min, sec);
ret_time = g_date_time_to_unix(g_time_t1);
return ret_time;
}
static gboolean
create_handle ()
{
if (!g_epg_handle) {
g_printf ("tv_service_epg_create failed, error code: [%d]\n", error);
return FALSE;
}
}
return TRUE;
}
static void
destroy_handle ()
{
if (g_epg_handle) {
g_epg_handle = NULL;
}
return;
}
void
exit_handler(int signum)
{
destroy_handle ();
g_main_loop_quit(mainloop);
return;
}
gboolean
timeout_handler (gpointer user_data)
{
destroy_handle ();
g_main_loop_quit (mainloop);
return TRUE;
}
static void
epg_callback (
tvs_epg_event_e type, gpointer user_data,
const gpointer data)
{
switch (type) {
g_printf ("epg auto destroy\n");
g_epg_handle = NULL;
g_main_loop_quit (mainloop);
break;
g_printf ("epg data update, service_id[%u]\n", *((guint *)user_data));
break;
default:
g_printf ("epg event type[%d]\n", type);
break;
}
return;
}
static void
epg_event_callback (
tvs_epg_event_e type, gpointer epg_data, gpointer user_data)
{
guint index = 0;
int length = 0;
static gint service_count = 0;
GList *epg_list = (GList *)epg_data;
service_count++;
length = g_list_length(epg_list);
for(index = 0; index < length; index++) {
if(NULL == p_tvs_data) {
g_printf ("error, TvServiceEpgEventData is NULL \n");
break;
}
g_printf ("######epg data info index[%d]#####\n",index);
print_epg_data(p_tvs_data);
if (index == (length - 1))
g_printf ("\n\n");
}
if (service_count >= g_service_count) {
g_timeout_add_seconds (1, timeout_handler, NULL);
}
}
int
main(int argc, char * argv[])
{
gint service_id;
gint start_time_day;
gint start_time_hour;
gint64 start_time;
int duration;
int index;
if (create_handle () != TRUE)
return 0;
mainloop = g_main_loop_new (NULL, FALSE);
if (argc >= 3 && g_strcmp0 (argv[1], "-a") == 0) {
for (index = 2; index < argc; index++) {
service_id = atoi (argv[index]);
if (service_id > 0) {
service_id,
0,
epg_event_callback,
NULL);
g_printf ("tv_service_epg_get_program_list failed, error code: [%d]\n", error);
goto err;
}
g_service_count ++;
}
}
} else if (argc >= 3 && g_strcmp0 (argv[1], "-c") == 0) {
for (index = 2; index < argc; index++) {
service_id = atoi (argv[index]);
if (service_id > 0) {
service_id,
epg_event_callback,
NULL);
g_printf ("tv_service_epg_get_current_program failed, error code: [%d]\n", error);
goto err;
}
g_service_count ++;
}
}
} else if (argc == 6 && g_strcmp0 (argv[1], "-s") == 0) {
service_id = atoi (argv[2]);
start_time_day = atoi (argv[3]);
start_time_hour = atoi (argv[4]);
duration = atoi (argv[5]);
if (service_id == 0 || start_time_day == 0 || start_time_hour == 0 || duration == 0) {
g_printf ("invalid parameter input!!!\n");
goto err;
}
start_time = get_start_time_sec (start_time_day, start_time_hour);
service_id,
start_time,
duration,
epg_event_callback,
NULL);
g_printf ("tv_service_epg_get_program_list failed, error code: [%d]\n", error);
goto err;
}
g_service_count ++;
} else if (argc == 3 && g_strcmp0(argv[1], "-d") == 0) {
start_time_day = atoi(argv[2]);
start_time_hour = 0;
duration = 3600 * 24;
if (start_time_day == 0) {
g_printf ("invalid input date!!!\n");
goto err;
}
start_time = get_start_time_sec (start_time_day, start_time_hour);
GList *channel_list = NULL;
&channel_list);
printf("tv_service_get_channel_list failed, error code: [%d]\n", error);
goto err;
}
for(index = 0; index < g_list_length (channel_list); index++) {
if(channel_data == NULL)
continue;
start_time,
duration,
epg_event_callback,
NULL);
g_printf ("tv_service_epg_get_program_list failed, service id: [%d], error code: [%d]\n",
else
g_service_count ++;
}
} else if (argc >= 3 && g_strcmp0 (argv[1], "-o") == 0) {
for (index = 2; index < argc; index++) {
memset (&tvs_data, 0, sizeof (tvs_data));
service_id = atoi (argv[index]);
g_printf ("get cached current program failure\n");
} else {
print_epg_data (&tvs_data);
}
}
goto err;
}
else {
test_print_help (argv[0]);
goto err;
}
signal (SIGINT, exit_handler);
g_main_loop_run (mainloop);
err:
destroy_handle ();
g_printf ("quit\n");
return 0;
}