tv-service  0.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tv_service_utils_test.c

This is an example of how to use the TV Service's utils interface to get broadcast time.

Author
Liu Kun k2.li.nosp@m.u@sa.nosp@m.msung.nosp@m..com
#include <gio/gio.h>
#include <stdlib.h>
#include <signal.h>
#include <glib/gprintf.h>
#include <time.h>
#include "tv_service_logger.h"
static GMainLoop *loop = NULL;
static TvServiceLive live_handle = NULL;
guint system_time;
guint gps_utc_offset;
guint daylight_saving;
gint service_id = 0;
void
print_usage ()
{
g_printf ("test_type: -s set service id and set tune.\n");
g_printf ("i.e) tvs_utils_test -s {service id}\n");
return;
}
gboolean
exit_loop (gpointer user_data)
{
g_main_loop_quit (loop);
return FALSE;
}
void
signal_handle (int signum)
{
g_printf ("In signal handle!\n");
if (live_handle) {
tv_service_live_destroy (live_handle);
}
g_main_loop_quit (loop);
exit(0);
return;
}
static void
print_time (guint system_time)
{
GDateTime *g_time = g_date_time_new_from_unix_utc (system_time);
g_printf ("system_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), system_time);
}
gboolean
get_stt_time ()
{
g_printf ("In get_stt_time!\n");
if (TVS_ERROR_OK != tv_service_utils_get_time (service_id)) {
g_printf ("In get_time tv_service_utils_get_time failed!\n");
}
return TRUE;
}
gboolean
live_broadcast ()
{
if (TVS_ERROR_OK != tv_service_live_create (&live_handle)) {
g_printf ("In main tv_service_live_create failed!\n");
return FALSE;
}
if (TVS_ERROR_OK != tv_service_live_tune (live_handle, service_id)) {
g_printf ("tv_service_live_tune failed\n");
return FALSE;
}
return TRUE;
}
void
app_util_callback (TvServiceUtilsEvent event, gpointer data, gpointer user_data)
{
switch (event) {
{
GetTimeResult *gt_result = (GetTimeResult *)data;
g_printf ("app_util_callback: get time callback, result:%d \n", gt_result->result);
if (gt_result->result != UTILS_GET_TIME_SUCCESS) {
g_printf ("get time fail !!! \n");
} else {
g_printf ("get time success, system_time[%d], daylight_saving[%d]\n",
gt_result->system_time, gt_result->daylight_saving);
print_time (gt_result->system_time);
}
}
break;
default:
g_printf ("get callback_type: %d", event);
}
return;
}
int
main(int argc, char ** argv)
{
gint type = 0;
loop = g_main_loop_new (NULL, FALSE);
if (argc != 3 && argc != 4) {
print_usage ();
return -1;
}
if (!g_strcmp0 (argv[1], "-s")) {
service_id = atoi (argv[2]);
type = 1;
g_printf ("live_utils_test: Get tune info by Service ID and set tune!");
} else {
print_usage ();
return -1;
}
g_printf ("In main tv_service_utils_create failed!\n");
return -1;
}
tv_service_utils_register_callback (app_util_callback, NULL);
signal (SIGINT, signal_handle);
if (argc == 4 && !g_strcmp0 (argv[1], "-l")) {
live_broadcast ();
}
if (type == 1) {
get_stt_time ();
g_timeout_add_seconds (5, get_stt_time, NULL);
}
g_timeout_add_seconds (200, exit_loop, NULL);
g_main_loop_run (loop);
g_printf ("exit loop ###################################");
if (live_handle) {
tv_service_live_destroy (live_handle);
}
return 0;
}