Advertisement
kernel_memory_dump

serviceList

Apr 28th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.27 KB | None | 0 0
  1. /*
  2.  * cmd_servicelist-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.  
  11. #include <cli_print.h>
  12. #include <commands.h>
  13. #include <mal_service_zapper.h>
  14. #include <mal_basic_types.h>
  15.  
  16.  
  17. //everything you need about routes
  18. extern int curLiveRouteIdx;
  19.  
  20. extern MAL_RouteID* liveRoutes;
  21.  
  22.  
  23. static const char *optString = "l:s:c:a:d:f:r:weiznph?";
  24.  
  25. static const struct option longOpts[] = {
  26.     { "list", required_argument, NULL, 'l' },
  27.     { "print", no_argument, NULL, 'p' },
  28.     { "sort", required_argument, NULL, 's' },
  29.     { "create", required_argument, NULL, 'c' },
  30.     { "add2fav", required_argument, NULL, 'a' },
  31.     { "deleteservice", required_argument, NULL, 'd' },
  32.     { "eraselist", no_argument, NULL, 'e' },
  33.     { "filter", required_argument, NULL, 'f' },
  34.     { "activeservice", no_argument, NULL, 'w' },
  35.     { "getlast", no_argument, NULL, 'i' },
  36.     { "previous", no_argument, NULL, 'z' },
  37.     { "getlistname", no_argument, NULL, 'n' },
  38.     { "renamelist", required_argument, NULL, 'r' },
  39.  
  40.     { "help", no_argument, NULL, 'h' },
  41.     { NULL, no_argument, NULL, 0 }
  42. };
  43.  
  44. static void display_usage()
  45. {
  46.     CLI_PRINT(" ");
  47.     CLI_PRINT("%-20s - %s \n", "servicelist", "service list management");
  48.     CLI_PRINT("%-20s %s  %s  %s", "option", "has_arg", "shortcut", "description");
  49.     CLI_PRINT("----------------------------------------------------------------------------\n");
  50.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[0].name, longOpts[0].has_arg, (char)longOpts[0].val, "sets the desired list with list index (up to 2 lists can be specified)");
  51.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[1].name, longOpts[1].has_arg, (char)longOpts[1].val, "prints the services of the selected list");
  52.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[2].name, longOpts[2].has_arg, (char)longOpts[2].val, "sorts the services within the selected list");
  53.     CLI_PRINT("0 - ZAPPING_ORDER, 1 - STATUS, 2 - SERVICENAME, 3 - FREQ, 4 - SATELLITENAME ...");
  54.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[3].name, longOpts[3].has_arg, (char)longOpts[3].val, "creates a new favourite list with provided name");
  55.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[4].name, longOpts[4].has_arg, (char)longOpts[4].val, "adds service with specified master list index to the specified list");
  56.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[5].name, longOpts[5].has_arg, (char)longOpts[5].val, "delete service from specified (NON-MASTER) service list");
  57.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[6].name, longOpts[6].has_arg, (char)longOpts[6].val, "completely erase specified (NON-MASTER) service list");
  58.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[7].name, longOpts[7].has_arg, (char)longOpts[7].val, "filter source list with specified criteria and put results in destination list (please specify two lists with two -l arguments)");
  59.     CLI_PRINT("0 - TV, 1 - RADIO, 2 - DATA, 3 - SCRAMBLED, 4 - FREE_TO_AIR, 5 - DVB_S, 6 - DVB_T, 7 - DVB_C, 8 - IP");
  60.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[8].name, longOpts[8].has_arg, (char)longOpts[8].val, "get index of the service that is currently being watched");
  61.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[9].name, longOpts[9].has_arg, (char)longOpts[9].val, "get index of the last watched service and list (initially set after power on)");
  62.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[10].name, longOpts[10].has_arg, (char)longOpts[10].val, "get index of the previously watched service");
  63.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[11].name, longOpts[11].has_arg, (char)longOpts[11].val, "get name of the specified service list");
  64.     CLI_PRINT("--%-20s %-9d -%-4c  %s", longOpts[12].name, longOpts[12].has_arg, (char)longOpts[12].val, "renames the specified service list");
  65. }
  66.  
  67. static int print_services(unsigned int listIndex)
  68. {
  69.     /* TO_DO */
  70.     /* Retrieve number of services in the specified service list */
  71.  
  72.     int serviceCount;
  73.     MAL_SZ_GetServiceListCount(listIndex, (mal_uint32*)&serviceCount);
  74.    
  75.     CLI_PRINT(" ");
  76.     CLI_PRINT("Number Of Services: %d", serviceCount);
  77.     /* TO_DO */
  78.     /* List services from the specified service list */
  79.  
  80.     int i;
  81.     for (i = 0; i < serviceCount; i++)
  82.     {
  83.         MAL_SZ_ServiceDesc descriptor;
  84.  
  85.         MAL_SZ_GetServiceDesc(listIndex, i, &descriptor);
  86.  
  87.        
  88.         CLI_PRINT("Service Name: %s", descriptor.serviceName);
  89.     }
  90.    
  91.     return 0;
  92. }
  93.  
  94. int cmd_servicelist_execute(size_t argc, char** argv)
  95. {
  96.     int opt = 0;
  97.     char list = 0;
  98.     int listIndex = -1;
  99.     int secListIndex = -1;
  100.     bool res = false;
  101.     int print = 0;
  102.     int sortType = -1;
  103.     char* favListName = NULL;
  104.     int addIndex = -1;
  105.     int delIndex = -1;
  106.     int erase = 0;
  107.     int filterType = -1;
  108.     int getActive = 0;
  109.     int getLast = 0;
  110.     int getLastList = -1;
  111.     int getPrevious = 0;
  112.     int getPreviousList = 0;
  113.     int getListName = 0;
  114.     char listName[64];
  115.     char* newListName = NULL;
  116.    
  117.     MAL_SZ_ErrorCode malError;
  118.  
  119.     int longIndex;  /* nedded for long option without a short arg */
  120.     int listCount;
  121.  
  122.     /* init the getopt */
  123.     optind=1;
  124.  
  125.     /* parsing arguments */
  126.     while (opt != -1)
  127.     {
  128.  
  129.         opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
  130.  
  131.         switch (opt)
  132.         {
  133.             case 'l':
  134.                 if(listIndex<0)
  135.                 {
  136.                     listIndex = atoi(optarg);
  137.                 }
  138.                 else
  139.                 {
  140.                     secListIndex = atoi(optarg);
  141.                 }
  142.                 break;
  143.  
  144.             case 'p':
  145.                 print = 1;
  146.                 break;
  147.  
  148.             case 's':
  149.                 sortType = atoi(optarg);
  150.                 break;
  151.  
  152.             case 'c':
  153.                 favListName = optarg;
  154.                 break;
  155.  
  156.             case 'a':
  157.                 addIndex = atoi(optarg);
  158.                 break;
  159.                
  160.             case 'd':
  161.                 delIndex = atoi(optarg);
  162.                 break;
  163.                
  164.             case 'e':
  165.                 erase = 1;
  166.                 break;
  167.                
  168.             case 'f':
  169.                 filterType = 0x1 << atoi(optarg);
  170.                 break;
  171.                
  172.             case 'w':
  173.                 getActive = 1;
  174.                 break;
  175.                
  176.             case 'i':
  177.                 getLast = 1;
  178.                 break;
  179.                
  180.             case 'z':
  181.                 getPrevious = 1;
  182.                 break;
  183.                
  184.             case 'n':
  185.                 getListName = 1;
  186.                 break;
  187.                
  188.             case 'r':
  189.                 newListName = optarg;
  190.                 break;
  191.  
  192.             case 'h': /* fall-through is intentional */
  193.             case '?':
  194.                 display_usage();
  195.                 break;
  196.  
  197.             case 0: /* long option without a short arg */
  198.                 break;
  199.  
  200.             default:
  201.                 /* We should not get here. */
  202.                 break;
  203.             }
  204.     }
  205.    
  206.     /* TO_DO */
  207.     /* Check if list index is valid */
  208.    
  209.     if(favListName!=NULL)
  210.     {
  211.          /* TO_DO */
  212.          /* Create favourite list */
  213.  
  214.         malError = MAL_SZ_CreateFavList(favListName, (mal_uint32*)&listIndex);
  215.         if(malError!=MAL_SZ_NO_ERROR)
  216.         {
  217.             CLI_ERROR("CLI_SERVICELIST: Error creating list");
  218.             return -1;
  219.         }
  220.     }
  221.    
  222.     malError = MAL_SZ_GetNumberOfServiceLists((mal_uint32*)&listCount);
  223.     if(malError!=MAL_SZ_NO_ERROR)
  224.     {
  225.         CLI_ERROR("CLI_SERVICELIST: Error getting number of service lists");
  226.         return -1;
  227.     }
  228.    
  229.     if(listIndex < 0 || listIndex > listCount)
  230.     {
  231.         CLI_ERROR("CLI_SERVICELIST: Error - invalid list index");
  232.         return -1;
  233.     }
  234.  
  235.     if(sortType>=0 && sortType <=20)
  236.     {
  237.         /* TODO: Ugly hack with sortCriteria ;) */
  238.         malError = MAL_SZ_SortServiceList(listIndex, (MAL_SZ_SortCriteria)sortType);
  239.         if(malError!=MAL_SZ_NO_ERROR)
  240.         {
  241.             CLI_ERROR("CLI_SERVICELIST: Error sorting list");
  242.             return -1;
  243.         }
  244.     }
  245.    
  246.     if(addIndex>0)
  247.     {
  248.         /* TO_DO */
  249.         /* Add service in service list */
  250.         malError = MAL_SZ_AddServiceInServiceList((mal_uint32)listIndex, (mal_uint32)addIndex);
  251.         if(malError!=MAL_SZ_NO_ERROR)
  252.         {
  253.             CLI_ERROR("CLI_SERVICELIST: Error adding service");
  254.             return -1;
  255.         }
  256.     }
  257.    
  258.     if(delIndex>0)
  259.     {
  260.         /* TO_DO */
  261.         /* Delete service from servicelist */
  262.         malError = MAL_SZ_DeleteServiceFromServiceList((mal_uint32)listIndex, (mal_uint32)delIndex);
  263.         if(malError!=MAL_SZ_NO_ERROR)
  264.         {
  265.             CLI_ERROR("CLI_SERVICELIST: error deleting service");
  266.             return -1;
  267.         }
  268.     }
  269.    
  270.     if(erase)
  271.     {
  272.         /* TO_DO */
  273.         /* Delete service list */
  274.         malError = MAL_SZ_DeleteServiceList((mal_uint32)listIndex);
  275.         if(malError!=MAL_SZ_NO_ERROR)
  276.         {
  277.             CLI_ERROR("CLI_SERVICELIST: Error gdeleting service list");
  278.             return -1;
  279.         }
  280.     }
  281.    
  282.     if(filterType>0)
  283.     {
  284.         if(secListIndex!=0)
  285.         {
  286.             malError = MAL_SZ_FilterServiceList(listIndex,secListIndex,filterType);
  287.             if(malError!=MAL_SZ_NO_ERROR)
  288.             {
  289.                 CLI_ERROR("CLI_SERVICELIST: Error filtering service list %d to service list %d with filter(adapted) %d",listIndex,secListIndex,filterType);
  290.                 return -1;
  291.             }
  292.         }
  293.         else
  294.         {
  295.             CLI_ERROR("CLI_SERVICELIST: Error - secondary list index not specified or set to zero (master list), please specifiy a valid list index");
  296.             return -1;
  297.         }
  298.     }
  299.    
  300.     if(getActive)
  301.     {
  302.         /* TO_DO */
  303.         /* Get active service */
  304.         malError = MAL_SZ_GetActiveService(liveRoutes[curLiveRouteIdx], (mal_uint32*)&getActive);
  305.         if(malError!=MAL_SZ_NO_ERROR)
  306.         {
  307.             CLI_ERROR("CLI_SERVICELIST: Error getting active service");
  308.             return -1;
  309.         }
  310.  
  311.         CLI_PRINT("CLI_SERVICELIST: Active service: %d", getActive);
  312.     }
  313.    
  314.     if(getLast)
  315.     {
  316.         malError = MAL_SZ_GetLastPlayedListAndService((mal_uint32*)&getLastList,(mal_uint32*)&getLast);
  317.         if(malError!=MAL_SZ_NO_ERROR)
  318.         {
  319.             CLI_ERROR("CLI_SERVICELIST: Error getting last service and list index");
  320.             return -1;
  321.         }
  322.        
  323.         CLI_PRINT("CLI_SERVICELIST: Last watched service: %d",getLast);
  324.         CLI_PRINT("CLI_SERVICELIST: Last watched list: %d",getLastList);
  325.     }
  326.    
  327.     if(getPrevious)
  328.     {
  329.         malError = MAL_SZ_GetPreviousPlayedService((mal_uint32*)&getPrevious);
  330.         if(malError!=MAL_SZ_NO_ERROR)
  331.         {
  332.             CLI_ERROR("CLI_SERVICELIST: Error getting previous service index");
  333.             return -1;
  334.         }
  335.        
  336.         CLI_PRINT("CLI_SERVICELIST: Previously watched service: %d",getPrevious);
  337.     }
  338.    
  339.     if(getListName)
  340.     {
  341.         /* TO_DO */
  342.         /* Get list name */
  343.  
  344.         malError = MAL_SZ_GetServiceListName((mal_uint32)listIndex, (mal_char*)listName);
  345.         if(malError!=MAL_SZ_NO_ERROR)
  346.         {
  347.             CLI_ERROR("CLI_SERVICELIST: Error getting list name");
  348.             return -1;
  349.         }
  350.         CLI_PRINT("CLI_SERVICELIST: List name: %s", listName);
  351.     }
  352.    
  353.     if(newListName!=NULL)
  354.     {
  355.         if(listIndex!=0)
  356.         {
  357.             malError = MAL_SZ_RenameList(listIndex,newListName);
  358.             if(malError!=MAL_SZ_NO_ERROR)
  359.             {
  360.                 CLI_ERROR("CLI_SERVICELIST: Error renaming service list %d",listIndex);
  361.                 return -1;
  362.             }
  363.         }
  364.         else
  365.         {
  366.             CLI_ERROR("CLI_SERVICELIST: Error - list index not specified or set to zero (master list), please specifiy a valid list index");
  367.             return -1;
  368.         }
  369.     }
  370.    
  371.  
  372.     if(print)
  373.     {
  374.         CLI_PRINT("CLI_SERVICELIST: listCount: %u",listCount);
  375.         if(print_services(listIndex)<0)
  376.         {
  377.             return -1;
  378.         }
  379.     }
  380.    
  381.     if(opt!='h' && opt!='?')
  382.     {
  383.         CLI_PRINT("CLI_SERVICELIST: SUCCESS!");
  384.     }
  385.  
  386.     return 0;
  387. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement