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

This is an example of how to get notification when channel information change.

Author
Liu Kun k2.li.nosp@m.u@sa.nosp@m.msung.nosp@m..com
/* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <glib-object.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <glib/gprintf.h>
#include "tv_service_logger.h"
static GMainLoop *loop = NULL;
static TvServiceScan g_scan_handle = NULL;
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 (g_scan_handle) {
tv_service_scan_destroy(g_scan_handle);
g_scan_handle = NULL;
}
g_main_loop_quit(loop);
exit(0);
return;
}
static void
scan_event_callback (TvServiceScanEvent type, TvServiceScanEventData * data, gpointer user_data)
{
switch(type) {
g_printf ("scan event type: TVS_SCAN_EVENT_SEARCH_BEGIN\n");
g_printf ("total air number: [%ld]\n",data ->data.l[0]);
g_printf ("total cable number: [%ld]\n", data->data.l[1]);
break;
g_printf ("scan event type: TVS_SCAN_EVENT_SEARCH_CHANNEL\n");
g_printf ("channel number(PTC): [%ld]\n", data->data.l[0]);
g_printf ("frequency: [%ld]\n", data->data.l[1]);
break;
g_printf ("scan event type: TVS_SCAN_EVENT_CHANNEL_FOUND\n");
g_printf ("antenna type: [%d], digital type: [%d]\n", data->data.s[0], data->data.s[1]);
g_printf ("atv channels: [%d], dtv channels: [%d]\n", data->data.s[2], data->data.s[3]);
break;
g_printf ("scan event type: TVS_SCAN_EVENT_SEARCH_FINISH\n");
g_printf ("scan search finish type: [%ld]\n", data->data.l[0]);
tv_service_scan_destroy (g_scan_handle);
g_scan_handle = NULL;
break;
}
}
static gboolean
channel_scan(gpointer user_data)
{
g_printf ("tv_service_scan_create fail !\n");
g_main_loop_quit(loop);
return FALSE;
}
tv_service_scan_register_callback (g_scan_handle, scan_event_callback, NULL);
if (TVS_ERROR_OK != tv_service_scan_start (g_scan_handle)) {
g_printf ("tv_service_scan_start fail !\n");
g_main_loop_quit(loop);
return FALSE;
}
return FALSE;
}
void
print_service(TvServiceChannel * tvs_data)
{
printf ("%d""|", tvs_data->service_id);
printf ("%d""|", tvs_data->frequency);
printf ("%d""|", tvs_data->service_type);
printf ("%d""|", tvs_data->channel_type);
printf ("%ld""|", tvs_data->source_id);
printf ("%ld""|", tvs_data->program_number);
printf ("%ld""|", tvs_data->stream_id);
printf ("%ld""|", tvs_data->major);
printf ("%ld""|", tvs_data->minor);
printf ("%ld""|", tvs_data->vpid);
printf ("%ld""|", tvs_data->apid);
printf ("%d""|", tvs_data->locked);
printf ("%d""|", tvs_data->remembered);
printf ("%d""|", tvs_data->favorite);
printf ("%s""|", tvs_data->program_name);
printf ("%d""|", tvs_data->modulation_type);
printf ("%d""|", tvs_data->antenna_type);
printf ("%d""|", tvs_data->video_type);
printf ("%d""|", tvs_data->audio_type);
printf ("\n");
}
void
notify_callback(TvServiceChannelEvent event, gpointer data, gpointer user_data)
{
switch(event) {
{
GList *tvs_list = NULL;
gint index;
TvServiceChannel* p_tvs_data = NULL;
g_printf ("tv_service_callback: get channel callback, event:%d \n", event);
printf("tv_service_get_channel_list fail \n");
return;
} else {
printf("get channels, number[%d] \n", g_list_length(tvs_list));
printf("Serv ID|Fre|Ser Type|Cha Type|Sou ID|Pro Num|Str ID|Maj|Min|Vid Pid|Aud Pid|Loc|Rem|fav|Pro Name|Mod Type|Ant Mode|Vid Type|Aud Type\n");
for(index = 0; index < g_list_length(tvs_list); index++) {
p_tvs_data = (TvServiceChannel*)g_list_nth_data(tvs_list,index);
if(p_tvs_data == NULL) {
TVS_LOGE("p_tvs_data is NULL\n");
return;
} else {
print_service(p_tvs_data);
}
}
}
}
break;
default:
g_printf ("get unknown callback_type: %d \n", event);
}
return;
}
int
main(int argc, char ** argv)
{
loop = g_main_loop_new (NULL, FALSE);
signal(SIGINT,signal_handle);
NULL);
g_timeout_add_seconds (1, channel_scan, NULL);
g_timeout_add_seconds (60, exit_loop, NULL);
g_main_loop_run (loop);
g_printf ("exit loop ###################################\n");
return 0;
}