Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * cmd_service-4.1.c
- *
- * Created on: Jan 21, 2013
- * Author: njovanovic
- */
- #include <getopt.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <cli_print.h>
- #include <commands.h>
- #include <mal_init.h>
- #include <mal_service_zapper.h>
- #include <mal_stream_component.h>
- #include <mal_epg.h>
- #define ZAPP_NUM 1000
- #define STARTING_INDEX 0
- extern int curLiveRouteIdx;
- extern MAL_RouteID* liveRoutes;
- extern MAL_EPG_ClientHandle* malHandles;
- extern int* clientBusy;
- int doAdditionalRequests = 0;
- static const char *optString = "u:p:l:z:t:sh?";
- static const struct option longOpts[] = {
- { "list", required_argument, NULL, 'l' },
- { "zapp", required_argument, NULL, 'z' },
- { "stop", no_argument, NULL, 's' },
- { "stresstest", required_argument, NULL, 't' },
- { "stresspause", required_argument, NULL, 'p' },
- { "urlzapp", required_argument, NULL, 'u' },
- { "help", no_argument, NULL, 'h' },
- { NULL, no_argument, NULL, 0 }
- };
- static void display_usage()
- {
- char stressString[256];
- sprintf(stressString,"zapps %d times to master list services starting with index %d with the pause specified in ms",ZAPP_NUM,STARTING_INDEX);
- CLI_PRINT(" ");
- CLI_PRINT("%-20s - %s \n", "service", "service zapping");
- CLI_PRINT("%-20s %s %s %s", "option", "has_arg", "shortcut", "description");
- CLI_PRINT("----------------------------------------------------------------------------\n");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[0].name, longOpts[0].has_arg, (char)longOpts[0].val, "sets the list of interest with list index");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[1].name, longOpts[1].has_arg, (char)longOpts[1].val, "zapp to service");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[2].name, longOpts[2].has_arg, (char)longOpts[2].val, "stop currently active service");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[3].name, longOpts[3].has_arg, (char)longOpts[3].val, stressString);
- CLI_PRINT("0 - simple zapping, 1 - zapping with information reqests between zapps");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[4].name, longOpts[4].has_arg, (char)longOpts[4].val, "specify the pause duration in ms (miliseconds) between every zapp during stress tests (default is 500)");
- #ifdef USE_MEDIUM_IP
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[5].name, longOpts[5].has_arg, (char)longOpts[5].val, "zapp to specified URL");
- #endif
- }
- int print_service_components(MAL_SC_CompType type, mal_uint16 count,char* compTypeStr)
- {
- int i;
- MAL_SC_ErrorCode malErrorSC;
- MAL_SC_CompDesc compDesc;
- if(count)
- {
- CLI_PRINT("\n| %-10s | %-6s | %-15s | %-5s | %-10s | %-10s | %-10s | %-10s | %-10s | %-10s | %-17s | %-15s |\n", "type", "PID", "componentTag", "index", "language", "videoType", "audioType", "ttxType", "pageNumber", "subType", "compositionPageID", "ancillaryPageID");
- for(i=0;i<count;i++)
- {
- malErrorSC = MAL_SC_GetCompDesc(liveRoutes[curLiveRouteIdx],type,i,&compDesc);
- if(malErrorSC != MAL_SC_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE: Error getting descriptor for component %d",i);
- return -1;
- }
- CLI_PRINT("| %-10s | %-6d | %-15d | %-5d | %-10s | %-10d | %-10d | %-10d | %-10d | %-10d | %-17d | %-15d |",
- compTypeStr,
- compDesc.PID,
- compDesc.componentTag,
- compDesc.index,
- compDesc.language,
- compDesc.videoType,
- compDesc.audioType,
- compDesc.ttxType,
- compDesc.pageNumber,
- compDesc.subType,
- compDesc.compositionPageID,
- compDesc.ancillaryPageID
- );
- }
- }
- return 0;
- }
- int print_service_event(MAL_EPG_Event* event)
- {
- mal_time* time;
- CLI_PRINT("Name: %s",event->name);
- CLI_PRINT("Description: %s",event->description);
- CLI_PRINT("Extended description: %s",event->extendedDescription);
- CLI_PRINT("Genre: %s",event->genre);
- time = &event->startTime;
- CLI_PRINT("Start time (mal_time) - year: %d, month:%d, day:%d, hour:%d, min:%d, sec:%d",time->year,time->month,time->day,time->hour,time->min,time->sec);
- time = &event->endTime;
- CLI_PRINT("End time (mal_time) - year: %d, month:%d, day:%d, hour:%d, min:%d, sec:%d",time->year,time->month,time->day,time->hour,time->min,time->sec);
- CLI_PRINT("Start time (string): %s",event->startTimeString);
- CLI_PRINT("End time (string): %s",event->endTimeString);
- CLI_PRINT("Duration: %s",event->durationString);
- CLI_PRINT("Parental rate: %d",event->parentalRate);
- CLI_PRINT("Language: %s",event->language);
- CLI_PRINT("Event ID: %u",event->eventId);
- return 0;
- }
- int doRequests()
- {
- MAL_SZ_ErrorCode malErrorSZ;
- MAL_SC_ErrorCode malErrorSC;
- MAL_EPG_ErrorCode malErrorEPG;
- mal_uint32 serviceIndex;
- MAL_SZ_ServiceDesc serviceDesc;
- mal_uint16 compCnt;
- MAL_EPG_Event epgEvent;
- mal_uint32 eventCnt;
- int i;
- //requesting active service
- malErrorSZ = MAL_SZ_GetActiveService(liveRoutes[curLiveRouteIdx],&serviceIndex);
- if(malErrorSZ != MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting active service");
- }
- else
- {
- CLI_PRINT("Active service index is: %u",(unsigned)serviceIndex);
- }
- //requesting active service info
- malErrorSZ = MAL_SZ_GetServiceDesc(0,serviceIndex,&serviceDesc);
- if(malErrorSZ != MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting active service info");
- }
- else
- {
- CLI_PRINT("Active service info:");
- CLI_PRINT("| %-10d | %-40s | %-10d | %-10d | %-10d | %-5d | %-10s |\n",
- (int)serviceIndex,
- serviceDesc.serviceName,
- (int)serviceDesc.ONID,
- (int)serviceDesc.TSID,
- (int)serviceDesc.serviceIdentifier,
- serviceDesc.serviceType,
- serviceDesc.scrambled ? "YES" : "NO"
- );
- }
- //requesting components
- malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_AUDIO,&compCnt);
- if(malErrorSC != MAL_SC_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting component count for audio");
- }
- else
- {
- CLI_PRINT("There are %hu AUDIO streams on this service",(short unsigned)compCnt);
- print_service_components(MAL_SC_COMP_TYPE_AUDIO,compCnt,"AUDIO");
- }
- malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_VIDEO,&compCnt);
- if(malErrorSC != MAL_SC_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting component count for video");
- }
- else
- {
- CLI_PRINT("There are %hu VIDEO streams on this service",(short unsigned)compCnt);
- print_service_components(MAL_SC_COMP_TYPE_VIDEO,compCnt,"VIDEO");
- }
- malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_SUB,&compCnt);
- if(malErrorSC != MAL_SC_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting component count for subtitle");
- }
- else
- {
- CLI_PRINT("There are %hu SUBTITLE streams on this service",(short unsigned)compCnt);
- print_service_components(MAL_SC_COMP_TYPE_SUB,compCnt,"SUBTITLE");
- }
- malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_TTX,&compCnt);
- if(malErrorSC != MAL_SC_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting component count for teletext");
- }
- else
- {
- CLI_PRINT("There are %hu TELETEXT streams on this service",(short unsigned)compCnt);
- print_service_components(MAL_SC_COMP_TYPE_TTX,compCnt,"TELETEXT");
- }
- #ifdef PRODUCT_USE_EIT
- //requesting present/following events
- if(clientBusy[0])
- {
- malErrorEPG = MAL_EPG_GetPresentFollowing(malHandles[0],MAL_EPG_PRESENT_EVENT,&epgEvent);
- if(malErrorEPG != MAL_EPG_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting present event");
- }
- else
- {
- CLI_PRINT("\nPresent event:");
- CLI_PRINT("-----------------------------------------------------------------");
- print_service_event(&epgEvent);
- CLI_PRINT("-----------------------------------------------------------------\n");
- }
- malErrorEPG = MAL_EPG_GetPresentFollowing(malHandles[0],MAL_EPG_FOLLOWING_EVENT,&epgEvent);
- if(malErrorEPG != MAL_EPG_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICE_stress: Error getting present event");
- }
- else
- {
- CLI_PRINT("\nFollowing event:");
- CLI_PRINT("-----------------------------------------------------------------");
- print_service_event(&epgEvent);
- CLI_PRINT("-----------------------------------------------------------------\n");
- }
- }
- else
- {
- CLI_PRINT("CLI_SERVICE_stress: Please register epg client with index 0 to get present/following events");
- }
- #endif
- return 0;
- }
- int cmd_service_execute(size_t argc, char** argv)
- {
- int opt = 0;
- int i;
- char list = 0;
- int serviceIndex = 0;
- int listIndex = 0;
- bool res = false;
- int listCount;
- MAL_SZ_ErrorCode malError;
- MAL_SZ_ServiceDesc serviceDesc;
- int stressTest = -1;
- int stressPause = -1;
- char* zappURL = NULL;
- int serviceCount;
- int stop = 0;
- int longIndex; /* nedded for long option without a short arg */
- /* init the getopt */
- optind=1;
- /* parsing arguments */
- while (opt != -1)
- {
- opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
- switch (opt)
- {
- case 'l':
- listIndex = atoi(optarg);
- break;
- case 'z':
- serviceIndex = atoi(optarg);
- break;
- case 't':
- if(atoi(optarg)<0)
- {
- CLI_PRINT("CLI_SERVICE: Invalid stress test specified, please specify a non-negative test index");
- return -1;
- }
- stressTest = atoi(optarg);
- break;
- case 'p':
- if(atoi(optarg)<0)
- {
- CLI_PRINT("CLI_SERVICE: Invalid pause specified, please specify a non-negative pause");
- return -1;
- }
- stressPause = atoi(optarg)*1000;
- break;
- case 's':
- stop = 1;
- break;
- case 'u':
- zappURL = optarg;
- break;
- case 'h': /* fall-through is intentional */
- case '?':
- display_usage();
- break;
- case 0: /* long option without a short arg */
- break;
- default:
- /* We should not get here. */
- break;
- }
- }
- /* TO_DO */
- /* Check if list and service are valid */
- malError = MAL_SZ_GetNumberOfServiceLists((mal_uint32*)&listCount);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error getting number of service lists");
- return -1;
- }
- if(listIndex < 0 || listIndex > listCount)
- {
- CLI_ERROR("CLI_SERVICELIST: Error - invalid list index");
- return -1;
- }
- MAL_SZ_GetServiceListCount(listIndex, (mal_uint32*)&serviceCount);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error getting number of services in list");
- return -1;
- }
- if(serviceIndex < 0 || serviceIndex > serviceCount)
- {
- CLI_ERROR("CLI_SERVICELIST: Error - invalid service index");
- return -1;
- }
- if(serviceIndex>=0)
- {
- /* TO_DO */
- /* Zapp to serviceIndex */
- malError = MAL_SZ_StartService(liveRoutes[curLiveRouteIdx], (mal_uint32)serviceIndex);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error starting service");
- return -1;
- }
- }
- if(stop)
- {
- /* TO_DO */
- /* stop service */
- malError = MAL_SZ_StopService(liveRoutes[curLiveRouteIdx]);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error stoping service");
- return -1;
- }
- }
- if(opt!='h' && opt!='?')
- {
- CLI_PRINT("CLI_SERVICE: SUCCESS!");
- }
- return 0;
- }
- void ServiceStatusCallback(void* userData, MAL_SZ_EventType event)
- {
- switch(event)
- {
- case MAL_SZ_EVENT_CHANNEL_CHANGE_SUCCESS:
- CLI_PRINT("CLI_SERVICE: MAL_SZ callback received MAL_SZ_EVENT_CHANNEL_CHANGE_SUCCESS");
- if(doAdditionalRequests)
- {
- doRequests();
- }
- break;
- case MAL_SZ_EVENT_CHANNEL_CHANGE_FAIL:
- CLI_PRINT("CLI_SERVICE: MAL_SZ callback received MAL_SZ_EVENT_CHANNEL_CHANGE_FAIL");
- break;
- case MAL_SZ_EVENT_SERVICE_STOPPED:
- CLI_PRINT("CLI_SERVICE: MAL_SZ callback received MAL_SZ_EVENT_SERVICE_STOPPED");
- break;
- default:
- CLI_PRINT("CLI_SERVICE: MAL_SZ callback received an unknown event");
- return;
- }
- }
- void cmd_service_init()
- {
- /* TO_DO */
- /* Register ServiceStatusCallback */
- MAL_SZ_ErrorCode malError;
- malError = MAL_SZ_RegisterCallback(ServiceStatusCallback);
- if (malError != MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error registering service callback");
- }
- }
- void cmd_service_term()
- {
- /* TO_DO */
- /* Unregister callback */
- MAL_SZ_ErrorCode malError;
- malError = MAL_SZ_UnregisterCallback(ServiceStatusCallback);
- if (malError != MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error unregistering service callback");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement