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

This is an example of how to use the TV Service's Channel & Program Scan queries.

Author
Tang Daoguang dguan.nosp@m.g.ta.nosp@m.ng@sa.nosp@m.msun.nosp@m.g.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 <glib/gprintf.h>
static TvServiceScan g_scan_handle = NULL;
static GMainLoop *mainloop = NULL;
static void
test_print_help (char * argv)
{
g_printf ("| test_type set digital and antenna type and scan \n");
g_printf ("| ie)%s -air/-cable/-all -dtv/-atv/-all \n", argv);
}
static void
scan_event_callback (TvServiceScanEvent type,
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_main_loop_quit (mainloop);
break;
}
return;
}
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 (mainloop);
exit (0);
}
gboolean
pause_scan(gpointer user_data)
{
TvServiceScan scan_handle = user_data;
gint res;
res = tv_service_scan_pause (scan_handle);
if (res != TVS_ERROR_OK) {
g_printf ("ERROR !! tv_service_scan_pause failed");
return FALSE;
}
g_printf ("Scan be stopped temporarily\n");
return FALSE;
}
gboolean
resume_scan(gpointer user_data)
{
TvServiceScan scan_handle = user_data;
gint res;
res = tv_service_scan_resume (scan_handle);
if (res != TVS_ERROR_OK) {
g_printf ("ERROR !! tv_service_scan_resume failed");
return FALSE;
}
g_printf ("Scan be started again\n");
return FALSE;
}
int
main (int argc, char * argv[])
{
mainloop = g_main_loop_new (NULL, FALSE);
if (argc == 3) {
if (!g_strcmp0 (argv[1], "-air")) {
if (!g_strcmp0 (argv[2], "-atv")) {
} else if (!g_strcmp0 (argv[2], "-dtv")) {
} else if (!g_strcmp0 (argv[2], "-all")) {
}
} else if (!g_strcmp0 (argv[1], "-cable")) {
if (!g_strcmp0 (argv[2], "-atv")) {
} else if (!g_strcmp0 (argv[2], "-dtv")) {
} else if (!g_strcmp0 (argv[2], "-all")) {
}
} else if (!g_strcmp0 (argv[1], "-all")) {
if (!g_strcmp0 (argv[2], "-atv")) {
} else if (!g_strcmp0 (argv[2], "-dtv")) {
} else if (!g_strcmp0 (argv[2], "-all")) {
}
}
}
if (type < TVS_SCAN_TYPE_MAX) {
error = tv_service_scan_create (&g_scan_handle, type);
} else {
g_printf ("Error input scan parameter!\n");
test_print_help (argv[0]);
return error;
}
if (error == TVS_ERROR_OK) {
error = tv_service_scan_register_callback (g_scan_handle,
scan_event_callback,
NULL);
error = tv_service_scan_start (g_scan_handle);
if (error != TVS_ERROR_OK) {
tv_service_scan_destroy (g_scan_handle);
return error;
}
} else {
g_printf ("tv_service create error !\n");
return error;
}
g_timeout_add_seconds (5, pause_scan, g_scan_handle);
g_timeout_add_seconds (10, resume_scan, g_scan_handle);
signal (SIGINT, signal_handle);
g_main_loop_run (mainloop);
return 0;
}