Advertisement
kernel_memory_dump

cmdService

Apr 28th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.56 KB | None | 0 0
  1. /*
  2.  * cmd_service-4.1.c
  3.  *
  4.  *  Created on: Jan 21, 2013
  5.  *      Author: njovanovic
  6.  */
  7. #include <getopt.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11.  
  12. #include <cli_print.h>
  13. #include <commands.h>
  14. #include <mal_init.h>
  15. #include <mal_service_zapper.h>
  16. #include <mal_stream_component.h>
  17. #include <mal_epg.h>
  18.  
  19. #define ZAPP_NUM 1000
  20. #define STARTING_INDEX 0
  21.  
  22.  
  23. extern int curLiveRouteIdx;
  24.  
  25. extern MAL_RouteID* liveRoutes;
  26.  
  27. extern MAL_EPG_ClientHandle* malHandles;
  28.  
  29. extern int* clientBusy;
  30.  
  31. int doAdditionalRequests = 0;
  32.  
  33. static const char *optString = "u:p:l:z:t:sh?";
  34.  
  35. static const struct option longOpts[] = {
  36.     { "list", required_argument, NULL, 'l' },
  37.    
  38.     { "zapp", required_argument, NULL, 'z' },
  39.     { "stop", no_argument, NULL, 's' },
  40.     { "stresstest", required_argument, NULL, 't' },
  41.     { "stresspause", required_argument, NULL, 'p' },
  42.     { "urlzapp", required_argument, NULL, 'u' },
  43.  
  44.     { "help", no_argument, NULL, 'h' },
  45.     { NULL, no_argument, NULL, 0 }
  46. };
  47.  
  48. static void display_usage()
  49. {
  50.     char stressString[256];
  51.     sprintf(stressString,"zapps %d times to master list services starting with index %d with the pause specified in ms",ZAPP_NUM,STARTING_INDEX);
  52.     CLI_PRINT(" ");
  53.     CLI_PRINT("%-20s - %s \n", "service", "service zapping");
  54.     CLI_PRINT("%-20s %s  %s  %s", "option", "has_arg", "shortcut", "description");
  55.     CLI_PRINT("----------------------------------------------------------------------------\n");
  56.     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");
  57.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[1].name, longOpts[1].has_arg, (char)longOpts[1].val, "zapp to service");
  58.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[2].name, longOpts[2].has_arg, (char)longOpts[2].val, "stop currently active service");
  59.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[3].name, longOpts[3].has_arg, (char)longOpts[3].val, stressString);
  60.     CLI_PRINT("0 - simple zapping, 1 - zapping with information reqests between zapps");
  61.     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)");
  62. #ifdef USE_MEDIUM_IP
  63.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[5].name, longOpts[5].has_arg, (char)longOpts[5].val, "zapp to specified URL");
  64. #endif
  65. }
  66.  
  67. int print_service_components(MAL_SC_CompType type, mal_uint16 count,char* compTypeStr)
  68. {
  69.     int i;
  70.     MAL_SC_ErrorCode malErrorSC;
  71.     MAL_SC_CompDesc compDesc;
  72.    
  73.     if(count)
  74.     {
  75.         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");
  76.         for(i=0;i<count;i++)
  77.         {
  78.             malErrorSC = MAL_SC_GetCompDesc(liveRoutes[curLiveRouteIdx],type,i,&compDesc);
  79.             if(malErrorSC != MAL_SC_NO_ERROR)
  80.             {
  81.                 CLI_ERROR("CLI_SERVICE: Error getting descriptor for component %d",i);
  82.                 return -1;
  83.             }
  84.             CLI_PRINT("| %-10s | %-6d | %-15d | %-5d | %-10s | %-10d | %-10d | %-10d | %-10d | %-10d | %-17d | %-15d |",
  85.                 compTypeStr,
  86.                 compDesc.PID,
  87.                 compDesc.componentTag,
  88.                 compDesc.index,
  89.                 compDesc.language,
  90.                 compDesc.videoType,
  91.                 compDesc.audioType,
  92.                 compDesc.ttxType,
  93.                 compDesc.pageNumber,
  94.                 compDesc.subType,
  95.                 compDesc.compositionPageID,
  96.                 compDesc.ancillaryPageID
  97.             );
  98.         }
  99.     }
  100.    
  101.     return 0;
  102. }
  103.  
  104. int print_service_event(MAL_EPG_Event* event)
  105. {
  106.     mal_time* time;
  107.     CLI_PRINT("Name: %s",event->name);
  108.     CLI_PRINT("Description: %s",event->description);
  109.     CLI_PRINT("Extended description: %s",event->extendedDescription);
  110.     CLI_PRINT("Genre: %s",event->genre);
  111.     time = &event->startTime;
  112.     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);
  113.     time = &event->endTime;
  114.     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);
  115.     CLI_PRINT("Start time (string): %s",event->startTimeString);
  116.     CLI_PRINT("End time (string): %s",event->endTimeString);
  117.     CLI_PRINT("Duration: %s",event->durationString);
  118.     CLI_PRINT("Parental rate: %d",event->parentalRate);
  119.     CLI_PRINT("Language: %s",event->language);
  120.     CLI_PRINT("Event ID: %u",event->eventId);
  121.    
  122.     return 0;
  123. }
  124.  
  125. int doRequests()
  126. {
  127.     MAL_SZ_ErrorCode malErrorSZ;
  128.     MAL_SC_ErrorCode malErrorSC;
  129.     MAL_EPG_ErrorCode malErrorEPG;
  130.     mal_uint32 serviceIndex;
  131.     MAL_SZ_ServiceDesc serviceDesc;
  132.     mal_uint16 compCnt;
  133.     MAL_EPG_Event epgEvent;
  134.     mal_uint32 eventCnt;
  135.     int i;
  136.    
  137.     //requesting active service
  138.     malErrorSZ = MAL_SZ_GetActiveService(liveRoutes[curLiveRouteIdx],&serviceIndex);
  139.     if(malErrorSZ != MAL_SZ_NO_ERROR)
  140.     {
  141.         CLI_ERROR("CLI_SERVICE_stress: Error getting active service");
  142.     }
  143.     else
  144.     {
  145.         CLI_PRINT("Active service index is: %u",(unsigned)serviceIndex);
  146.     }
  147.    
  148.     //requesting active service info
  149.     malErrorSZ = MAL_SZ_GetServiceDesc(0,serviceIndex,&serviceDesc);
  150.     if(malErrorSZ != MAL_SZ_NO_ERROR)
  151.     {
  152.         CLI_ERROR("CLI_SERVICE_stress: Error getting active service info");
  153.     }
  154.     else
  155.     {
  156.         CLI_PRINT("Active service info:");
  157.         CLI_PRINT("| %-10d | %-40s | %-10d | %-10d | %-10d | %-5d | %-10s |\n",
  158.                                                           (int)serviceIndex,
  159.                                                           serviceDesc.serviceName,
  160.                                                           (int)serviceDesc.ONID,
  161.                                                           (int)serviceDesc.TSID,
  162.                                                           (int)serviceDesc.serviceIdentifier,
  163.                                                           serviceDesc.serviceType,
  164.                                                           serviceDesc.scrambled ? "YES" : "NO"
  165.                                                           );
  166.     }
  167.    
  168.     //requesting components
  169.     malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_AUDIO,&compCnt);
  170.     if(malErrorSC != MAL_SC_NO_ERROR)
  171.     {
  172.         CLI_ERROR("CLI_SERVICE_stress: Error getting component count for audio");
  173.     }
  174.     else
  175.     {
  176.         CLI_PRINT("There are %hu AUDIO streams on this service",(short unsigned)compCnt);
  177.         print_service_components(MAL_SC_COMP_TYPE_AUDIO,compCnt,"AUDIO");
  178.     }
  179.    
  180.     malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_VIDEO,&compCnt);
  181.     if(malErrorSC != MAL_SC_NO_ERROR)
  182.     {
  183.         CLI_ERROR("CLI_SERVICE_stress: Error getting component count for video");
  184.     }
  185.     else
  186.     {
  187.         CLI_PRINT("There are %hu VIDEO streams on this service",(short unsigned)compCnt);
  188.         print_service_components(MAL_SC_COMP_TYPE_VIDEO,compCnt,"VIDEO");
  189.     }
  190.    
  191.     malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_SUB,&compCnt);
  192.     if(malErrorSC != MAL_SC_NO_ERROR)
  193.     {
  194.         CLI_ERROR("CLI_SERVICE_stress: Error getting component count for subtitle");
  195.     }
  196.     else
  197.     {
  198.         CLI_PRINT("There are %hu SUBTITLE streams on this service",(short unsigned)compCnt);
  199.         print_service_components(MAL_SC_COMP_TYPE_SUB,compCnt,"SUBTITLE");
  200.     }
  201.    
  202.     malErrorSC = MAL_SC_GetCompCount(liveRoutes[curLiveRouteIdx],MAL_SC_COMP_TYPE_TTX,&compCnt);
  203.     if(malErrorSC != MAL_SC_NO_ERROR)
  204.     {
  205.         CLI_ERROR("CLI_SERVICE_stress: Error getting component count for teletext");
  206.     }
  207.     else
  208.     {
  209.         CLI_PRINT("There are %hu TELETEXT streams on this service",(short unsigned)compCnt);
  210.         print_service_components(MAL_SC_COMP_TYPE_TTX,compCnt,"TELETEXT");
  211.     }
  212.  
  213. #ifdef PRODUCT_USE_EIT
  214.     //requesting present/following events
  215.     if(clientBusy[0])
  216.     {
  217.         malErrorEPG = MAL_EPG_GetPresentFollowing(malHandles[0],MAL_EPG_PRESENT_EVENT,&epgEvent);
  218.         if(malErrorEPG != MAL_EPG_NO_ERROR)
  219.         {
  220.             CLI_ERROR("CLI_SERVICE_stress: Error getting present event");
  221.         }
  222.         else
  223.         {
  224.             CLI_PRINT("\nPresent event:");
  225.             CLI_PRINT("-----------------------------------------------------------------");
  226.             print_service_event(&epgEvent);
  227.             CLI_PRINT("-----------------------------------------------------------------\n");
  228.         }
  229.        
  230.         malErrorEPG = MAL_EPG_GetPresentFollowing(malHandles[0],MAL_EPG_FOLLOWING_EVENT,&epgEvent);
  231.         if(malErrorEPG != MAL_EPG_NO_ERROR)
  232.         {
  233.             CLI_ERROR("CLI_SERVICE_stress: Error getting present event");
  234.         }
  235.         else
  236.         {
  237.             CLI_PRINT("\nFollowing event:");
  238.             CLI_PRINT("-----------------------------------------------------------------");
  239.             print_service_event(&epgEvent);
  240.             CLI_PRINT("-----------------------------------------------------------------\n");
  241.         }
  242.     }
  243.     else
  244.     {
  245.         CLI_PRINT("CLI_SERVICE_stress: Please register epg client with index 0 to get present/following events");
  246.     }
  247. #endif
  248.    
  249.     return 0;
  250. }
  251.  
  252. int cmd_service_execute(size_t argc, char** argv)
  253. {
  254.     int opt = 0;
  255.     int i;
  256.     char list = 0;
  257.     int serviceIndex = 0;
  258.     int listIndex = 0;
  259.     bool res = false;
  260.     int listCount;
  261.     MAL_SZ_ErrorCode malError;
  262.     MAL_SZ_ServiceDesc serviceDesc;
  263.     int stressTest = -1;
  264.     int stressPause = -1;
  265.     char* zappURL = NULL;
  266.     int serviceCount;
  267.     int stop = 0;
  268.  
  269.  
  270.  
  271.     int longIndex;  /* nedded for long option without a short arg */
  272.  
  273.     /* init the getopt */
  274.     optind=1;
  275.  
  276.     /* parsing arguments */
  277.     while (opt != -1)
  278.     {
  279.  
  280.         opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
  281.  
  282.         switch (opt)
  283.         {
  284.             case 'l':
  285.                 listIndex = atoi(optarg);
  286.                 break;
  287.  
  288.             case 'z':
  289.                 serviceIndex = atoi(optarg);
  290.                 break;
  291.                
  292.             case 't':
  293.                 if(atoi(optarg)<0)
  294.                 {
  295.                     CLI_PRINT("CLI_SERVICE: Invalid stress test specified, please specify a non-negative test index");
  296.                     return -1;
  297.                 }
  298.                 stressTest = atoi(optarg);
  299.                 break;
  300.                
  301.             case 'p':
  302.                 if(atoi(optarg)<0)
  303.                 {
  304.                     CLI_PRINT("CLI_SERVICE: Invalid pause specified, please specify a non-negative pause");
  305.                     return -1;
  306.                 }
  307.                 stressPause = atoi(optarg)*1000;
  308.                 break;
  309.                
  310.             case 's':
  311.                 stop = 1;
  312.                 break;
  313.                
  314.             case 'u':
  315.                 zappURL = optarg;
  316.                 break;
  317.  
  318.             case 'h': /* fall-through is intentional */
  319.             case '?':
  320.                 display_usage();
  321.                 break;
  322.  
  323.             case 0: /* long option without a short arg */
  324.                 break;
  325.  
  326.             default:
  327.             /* We should not get here. */
  328.                 break;
  329.         }
  330.     }
  331.    
  332.     /* TO_DO */
  333.     /* Check if list and service are valid */
  334.  
  335.     malError = MAL_SZ_GetNumberOfServiceLists((mal_uint32*)&listCount);
  336.     if(malError!=MAL_SZ_NO_ERROR)
  337.     {
  338.         CLI_ERROR("CLI_SERVICELIST: Error getting number of service lists");
  339.         return -1;
  340.     }
  341.    
  342.     if(listIndex < 0 || listIndex > listCount)
  343.     {
  344.         CLI_ERROR("CLI_SERVICELIST: Error - invalid list index");
  345.         return -1;
  346.     }
  347.  
  348.     MAL_SZ_GetServiceListCount(listIndex, (mal_uint32*)&serviceCount);
  349.     if(malError!=MAL_SZ_NO_ERROR)
  350.     {
  351.         CLI_ERROR("CLI_SERVICELIST: Error getting number of services in list");
  352.         return -1;
  353.     }
  354.  
  355.     if(serviceIndex < 0 || serviceIndex > serviceCount)
  356.     {
  357.         CLI_ERROR("CLI_SERVICELIST: Error - invalid service index");
  358.         return -1;
  359.     }
  360.    
  361.     if(serviceIndex>=0)
  362.     {
  363.         /* TO_DO */
  364.         /* Zapp to serviceIndex */
  365.         malError = MAL_SZ_StartService(liveRoutes[curLiveRouteIdx], (mal_uint32)serviceIndex);
  366.         if(malError!=MAL_SZ_NO_ERROR)
  367.         {
  368.             CLI_ERROR("CLI_SERVICELIST: Error starting service");
  369.             return -1;
  370.         }
  371.     }
  372.    
  373.     if(stop)
  374.     {
  375.         /* TO_DO */
  376.         /* stop service */
  377.         malError = MAL_SZ_StopService(liveRoutes[curLiveRouteIdx]);
  378.         if(malError!=MAL_SZ_NO_ERROR)
  379.         {
  380.             CLI_ERROR("CLI_SERVICELIST: Error stoping service");
  381.             return -1;
  382.         }
  383.     }
  384.    
  385.     if(opt!='h' && opt!='?')
  386.     {
  387.         CLI_PRINT("CLI_SERVICE: SUCCESS!");
  388.     }
  389.  
  390.     return 0;
  391. }
  392.  
  393. void ServiceStatusCallback(void* userData, MAL_SZ_EventType event)
  394. {
  395.     switch(event)
  396.     {
  397.         case MAL_SZ_EVENT_CHANNEL_CHANGE_SUCCESS:
  398.             CLI_PRINT("CLI_SERVICE: MAL_SZ callback received MAL_SZ_EVENT_CHANNEL_CHANGE_SUCCESS");
  399.             if(doAdditionalRequests)
  400.             {
  401.                 doRequests();
  402.             }
  403.             break;
  404.         case MAL_SZ_EVENT_CHANNEL_CHANGE_FAIL:
  405.             CLI_PRINT("CLI_SERVICE: MAL_SZ callback received MAL_SZ_EVENT_CHANNEL_CHANGE_FAIL");
  406.             break;
  407.         case MAL_SZ_EVENT_SERVICE_STOPPED:
  408.             CLI_PRINT("CLI_SERVICE: MAL_SZ callback received MAL_SZ_EVENT_SERVICE_STOPPED");
  409.             break;
  410.         default:
  411.             CLI_PRINT("CLI_SERVICE: MAL_SZ callback received an unknown event");
  412.             return;
  413.     }
  414. }
  415.  
  416. void cmd_service_init()
  417. {
  418.     /* TO_DO */
  419.     /* Register ServiceStatusCallback */
  420.  
  421.     MAL_SZ_ErrorCode malError;
  422.  
  423.     malError = MAL_SZ_RegisterCallback(ServiceStatusCallback);
  424.     if (malError != MAL_SZ_NO_ERROR)
  425.     {
  426.         CLI_ERROR("CLI_SERVICELIST: Error registering service callback");
  427.     }
  428. }
  429.  
  430. void cmd_service_term()
  431. {
  432.     /* TO_DO */
  433.     /* Unregister callback */
  434.  
  435.     MAL_SZ_ErrorCode malError;
  436.  
  437.     malError = MAL_SZ_UnregisterCallback(ServiceStatusCallback);
  438.     if (malError != MAL_SZ_NO_ERROR)
  439.     {
  440.         CLI_ERROR("CLI_SERVICELIST: Error unregistering service callback");
  441.     }
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement