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

This is an example of how to use the TV Service's Channel lock and unlock queries.

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 <vconf.h>
#include <glib/gprintf.h>
#include "tv_service_logger.h"
#define CHANNEL_LOCK_PASSWORD_VALUE "0000"
static GMainLoop *loop = NULL;
static TvServiceLive live_handle = NULL;
gint service_id = 0;
static gboolean channel_unlock();
static gboolean channel_lock();
gboolean
exit_loop(gpointer user_data)
{
g_main_loop_quit(loop);
return FALSE;
}
void
app_callback(TvServiceLiveEvent event, gpointer user_data, const gpointer data)
{
switch(event) {
gboolean *lock_status = (gboolean*) data;
g_printf ("tv_service_callback: get tuner locked callback:%d\n", *lock_status);
}
break;
g_printf("tv_service_callback: set resolution width:%d,height:%d", res_data->width,res_data->height);
}
break;
g_printf ("tv_service_callback: get channel locked callback\n");
}
break;
g_printf ("tv_service_callback: get channel unlocked callback\n");
}
break;
default:
g_printf ("get callback_type: %d\n", event);
}
return;
}
void
signal_handle(int signum)
{
g_printf ("In signal handle!\n");
if(live_handle) {
}
g_main_loop_quit(loop);
exit(0);
return;
}
gboolean
live_channel_unlock(gpointer user_data)
{
channel_unlock();
return FALSE;
}
gboolean
live_channel_lock(gpointer user_data)
{
channel_lock();
return FALSE;
}
static
gboolean channel_unlock()
{
gint res = 0;
res = tv_service_unlock_channel(service_id, CHANNEL_LOCK_PASSWORD_VALUE);
if (res == TVS_ERROR_OK) {
printf("unlock channel Success \n");
gboolean locked;
if (TVS_ERROR_OK == tv_service_get_channel_locked(service_id, &locked)) {
g_printf("tv_service_get_channel_locked: locked[%d]\n", locked);
} else {
g_printf("tv_service_get_channel_locked fail !!!\n");
return FALSE;
}
} else {
g_printf("unlock channel Fail !!!");
return FALSE;
}
return TRUE;
}
static
gboolean channel_lock()
{
gint res;
res = tv_service_lock_channel(service_id, CHANNEL_LOCK_PASSWORD_VALUE);
if (res == TVS_ERROR_OK) {
g_printf("lock channel Success \n");
gboolean locked;
if (TVS_ERROR_OK == tv_service_get_channel_locked(service_id, &locked)) {
g_printf("tv_service_get_channel_locked, locked[%d]\n", locked);
} else {
g_printf("tv_service_get_channel_locked fail !!!\n");
return FALSE;
}
} else {
g_printf("lock channel Fail !!!\n");
return FALSE;
}
return TRUE;
}
gint
static live_tune()
{
gint res;
if(TVS_ERROR_OK != tv_service_live_create(&live_handle)) {
g_printf ("In main tv_service_live_create failed!\n");
return -1;
}
g_printf ("After tv_service_live_create\n");
tv_service_live_register_callback(live_handle, app_callback, NULL);
g_printf ("After tv_service_live_register_callback\n");
if(TVS_ERROR_OK != tv_service_live_tune(live_handle, service_id)) {
g_printf("tv_service_live_tune failed\n");
return -1;
}
res = tv_service_live_set_volume(live_handle, 5.0);
if (res != TVS_ERROR_OK) {
g_printf ("ERROR !!! tv_service_live_set_volume fail!\n");
return -1;
}
return 0;
}
int
main(int argc, char ** argv)
{
gint res = 0;
gboolean result;
gboolean locked;
service_id = 1;
loop = g_main_loop_new (NULL, FALSE);
signal(SIGINT,signal_handle);
res = vconf_set_str("db/menu/system/change_pin", CHANNEL_LOCK_PASSWORD_VALUE);
if (res) {
g_printf("get password error, res[%d] \n", res);
return -1;
}
if (TVS_ERROR_OK != tv_service_get_channel_locked(service_id, &locked)) {
g_printf("tv_service_get_channel_locked fail !!! \n");
return -1;
}
g_printf("get channel lock status:[%d]\n", locked);
if (locked) {
if (TRUE == channel_unlock()) {
result = channel_lock();
} else {
return -1;
}
} else {
result = channel_lock();
}
if (result == FALSE) {
g_printf("channel lock fail\n");
return -1;
}
live_tune();
g_timeout_add_seconds (10, live_channel_unlock, NULL);
g_timeout_add_seconds (20, live_channel_lock, NULL);
g_timeout_add_seconds (30, live_channel_unlock, NULL);
g_timeout_add_seconds (40, exit_loop, NULL);
g_main_loop_run (loop);
g_printf ("exit loop ###################################\n");
if(live_handle) {
}
return 0;
}