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

This is an example of how to use TV Service's interface to get information of channel list.

Author
Jiang Minmin min86.nosp@m..jia.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 <string.h>
#include <glib/gprintf.h>
#include "tv_service_logger.h"
GValue g_value_filter[10];
void print_usage(char *argv)
{
g_printf ("%s -s {service_id}\n",argv);
g_printf ("{i.e}%s -s 1 \n",argv);
g_printf ("%s -l {channel_mode} {antenna_type} -f {filter1} {filter2} ...\n",argv);
g_printf ("channel_mode:{0:all},{1:digital},{2:analog},{3:digital & analog},{4:favorite},{5:all digital & analog}\n");
g_printf ("antenna_type:{0:air},{1:cable},{2:all}\n");
g_printf ("filter: {atrribute_type} {value} {match_type} \n");
g_printf ("{i.e}%s -l 0 2 \n",argv);
g_printf ("{i.e}%s -l 0 2 -f 6 1 1 (list added channels)\n",argv);
g_printf ("{i.e}%s -l 0 2 -f 6 1 1 5 SBC 1 (channel name equal \'SBC\' and added)\n",argv);
g_printf ("{i.e}%s -l 0 2 -f 3 50 1 4 2 1 (major number equal 50 and minor number equal 2)\n",argv);
g_printf ("{i.e}%s -l 0 2 -f 5 KB 5 (channel name begin with \'KB\')\n",argv);
g_printf ("{i.e}%s -l 0 2 -f 3 1 5 (major number begin with \'1\')\n",argv);
}
void print_service(TvServiceChannel *tvs_data)
{
g_printf ("%3d"" | ", tvs_data->service_id);
g_printf ("%10d""| ", tvs_data->frequency);
g_printf ("%d"" | ", tvs_data->service_type);
g_printf ("%d"" | ", tvs_data->channel_type);
g_printf ("%3ld"" | ", tvs_data->source_id);
g_printf ("%3ld"" | ", tvs_data->program_number);
g_printf ("%5ld"" | ", tvs_data->stream_id);
g_printf ("%5ld"" | ", tvs_data->major);
g_printf ("%5ld"" | ", tvs_data->minor);
g_printf ("%5ld"" | ", tvs_data->vpid);
g_printf ("%5ld"" | ", tvs_data->apid);
g_printf ("%d"" | ", tvs_data->locked);
g_printf ("%d"" | ", tvs_data->remembered);
g_printf ("%d"" | ", tvs_data->favorite);
g_printf ("%20s"" | ", tvs_data->program_name);
g_printf ("%2d"" | ", tvs_data->modulation_type);
g_printf ("%d"" | ", tvs_data->antenna_type);
g_printf ("%d"" | ", tvs_data->video_type);
g_printf ("%d", tvs_data->audio_type);
g_printf ("\n");
}
gint tv_serivce_get_service(gint service_id)
{
TvServiceChannel tvs_data;
gint rc = 0;
g_printf("service id is %d\n",service_id);
rc = tv_service_get_channel(service_id,&tvs_data);
if(rc != TVS_ERROR_OK){
g_printf("tv_service_get_channel error %d\n",rc);
return rc;
}
else{
g_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");
print_service(&tvs_data);
}
g_printf("#tv_service_get_service test end#\n");
return rc;
}
gint tv_serivce_get_service_list(gint channel_mode, gint antenna_type, GList* filter)
{
gint rc = 0;
GList *tvs_list = NULL;
gint index = 0;
TvServiceChannel *p_tvs_data = NULL;
if (filter) {
g_printf("get filter, call tv_service_get_channel_list_ex \n");
rc = tv_service_get_channel_list_ex(channel_mode, antenna_type, &tvs_list, filter, CHANNEL_SORT_TYPE_MAJOR_MINOR_NUMBER);
} else {
rc = tv_service_get_channel_list(channel_mode,antenna_type, &tvs_list);
}
if(rc != TVS_ERROR_OK){
g_printf("tv_service_get_channel_list is error %d\n",rc);
return rc;
} else{
if (g_list_length(tvs_list) == 0) {
g_printf("can not get right data \n");
} else {
g_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 -1;
} else{
print_service(p_tvs_data);
}
}
}
}
g_list_free(tvs_list);
tvs_list = NULL;
g_printf("#tv_service_get_service_list test end#\n");
return rc;
}
GList* get_channel_filter(int argc, char **argv)
{
GList *filter = NULL;
TvServiceFilterNode* filter_node = NULL;
int arg_num = 5;
int g_value_index = 0;
int attr = 0;
int match_type = 0;
g_printf("argc = %d \n", argc);
while ((arg_num + 2) < argc) {
GValue *g_value = &g_value_filter[g_value_index];
filter_node = g_malloc0(sizeof(TvServiceFilterNode));
attr = atoi(argv[arg_num]);
match_type = atoi(argv[arg_num+2]);
g_printf("read filter, arg_num[%d]\n", arg_num);
g_printf("filter attribute wrong [%d] \n", attr);
return NULL;
}
if (match_type >= CHANNEL_FILTER_MATCH_MAX || match_type <= CHANNEL_FILTER_MATCH_NONE) {
g_printf("filter match type wrong [%d] \n", match_type);
return NULL;
}
filter_node->attribute = attr;
filter_node->match_type = match_type;
g_printf("get filter, attribute[%d], match_type[%d]\n", filter_node->attribute, filter_node->match_type);
g_value_init (g_value, G_TYPE_STRING);
g_value_set_string(g_value, argv[arg_num+1]);
g_printf ("get filter string[%s]\n", g_value_get_string (g_value));
} else {
g_value_init (g_value, G_TYPE_INT);
g_value_set_int(g_value, atoi(argv[arg_num+1]));
g_printf ("get filter int[%d]\n", g_value_get_int (g_value));
}
filter_node->value = g_value;
filter = g_list_append (filter,(gpointer)filter_node);
arg_num = arg_num + 3;
g_value_index ++;
}
return filter;
}
int main(int argc, char **argv)
{
gint rc = 0;
gint service_id = -1;
gint channel_mode = -2;
gint antenna_type = -2;
if(rc != TVS_ERROR_OK)
{
g_printf("tv_service_channel_info_create error %d\n",rc);
return rc;
}
if (argc == 3 && !g_strcmp0(argv[1], "-s")) {
service_id = atoi(argv[2]);
g_printf("service_id is %d\n",service_id);
rc = tv_serivce_get_service(service_id);
if(rc != TVS_ERROR_OK) {
g_printf("tv_serivce_get_service is error %d\n",rc);
return rc;
} else {
g_printf("tv_serivce_get_service is ok\n");
}
} else if(argc > 3 && !g_strcmp0(argv[1], "-l")){
GList *filter = NULL;
channel_mode = atoi(argv[2]);
antenna_type = atoi(argv[3]);
g_printf("get channel_mode:%d,antenna_type:%d\n",channel_mode,antenna_type);
if (argc > 4) {
if (!g_strcmp0(argv[4], "-f")) {
filter = get_channel_filter(argc, argv);
if (!filter) {
g_printf("fail to get filter \n");
return -1;
}
} else {
print_usage(argv[0]);
return 0;
}
}
rc = tv_serivce_get_service_list(channel_mode, antenna_type, filter);
if(rc != TVS_ERROR_OK) {
g_printf("tv_serivce_get_service_list is error %d\n",rc);
return rc;
} else {
g_printf("tv_serivce_get_service_list is ok\n");
}
g_list_free_full (filter, g_free);
} else {
print_usage(argv[0]);
return 0;
}
return 0;
}