Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * cmd_servicelist-4.1.c
- *
- * Created on: Jan 21, 2013
- * Author: njovanovic
- */
- #include <getopt.h>
- #include <string.h>
- #include <stdlib.h>
- #include <cli_print.h>
- #include <commands.h>
- #include <mal_service_zapper.h>
- #include <mal_basic_types.h>
- //everything you need about routes
- extern int curLiveRouteIdx;
- extern MAL_RouteID* liveRoutes;
- static const char *optString = "l:s:c:a:d:f:r:weiznph?";
- static const struct option longOpts[] = {
- { "list", required_argument, NULL, 'l' },
- { "print", no_argument, NULL, 'p' },
- { "sort", required_argument, NULL, 's' },
- { "create", required_argument, NULL, 'c' },
- { "add2fav", required_argument, NULL, 'a' },
- { "deleteservice", required_argument, NULL, 'd' },
- { "eraselist", no_argument, NULL, 'e' },
- { "filter", required_argument, NULL, 'f' },
- { "activeservice", no_argument, NULL, 'w' },
- { "getlast", no_argument, NULL, 'i' },
- { "previous", no_argument, NULL, 'z' },
- { "getlistname", no_argument, NULL, 'n' },
- { "renamelist", required_argument, NULL, 'r' },
- { "help", no_argument, NULL, 'h' },
- { NULL, no_argument, NULL, 0 }
- };
- static void display_usage()
- {
- CLI_PRINT(" ");
- CLI_PRINT("%-20s - %s \n", "servicelist", "service list management");
- 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 desired list with list index (up to 2 lists can be specified)");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[1].name, longOpts[1].has_arg, (char)longOpts[1].val, "prints the services of the selected list");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[2].name, longOpts[2].has_arg, (char)longOpts[2].val, "sorts the services within the selected list");
- CLI_PRINT("0 - ZAPPING_ORDER, 1 - STATUS, 2 - SERVICENAME, 3 - FREQ, 4 - SATELLITENAME ...");
- 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");
- 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");
- 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");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[6].name, longOpts[6].has_arg, (char)longOpts[6].val, "completely erase specified (NON-MASTER) service list");
- 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)");
- 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");
- 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");
- 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)");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[10].name, longOpts[10].has_arg, (char)longOpts[10].val, "get index of the previously watched service");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[11].name, longOpts[11].has_arg, (char)longOpts[11].val, "get name of the specified service list");
- CLI_PRINT("--%-20s %-9d -%-4c %s", longOpts[12].name, longOpts[12].has_arg, (char)longOpts[12].val, "renames the specified service list");
- }
- static int print_services(unsigned int listIndex)
- {
- /* TO_DO */
- /* Retrieve number of services in the specified service list */
- int serviceCount;
- MAL_SZ_GetServiceListCount(listIndex, (mal_uint32*)&serviceCount);
- CLI_PRINT(" ");
- CLI_PRINT("Number Of Services: %d", serviceCount);
- /* TO_DO */
- /* List services from the specified service list */
- int i;
- for (i = 0; i < serviceCount; i++)
- {
- MAL_SZ_ServiceDesc descriptor;
- MAL_SZ_GetServiceDesc(listIndex, i, &descriptor);
- CLI_PRINT("Service Name: %s", descriptor.serviceName);
- }
- return 0;
- }
- int cmd_servicelist_execute(size_t argc, char** argv)
- {
- int opt = 0;
- char list = 0;
- int listIndex = -1;
- int secListIndex = -1;
- bool res = false;
- int print = 0;
- int sortType = -1;
- char* favListName = NULL;
- int addIndex = -1;
- int delIndex = -1;
- int erase = 0;
- int filterType = -1;
- int getActive = 0;
- int getLast = 0;
- int getLastList = -1;
- int getPrevious = 0;
- int getPreviousList = 0;
- int getListName = 0;
- char listName[64];
- char* newListName = NULL;
- MAL_SZ_ErrorCode malError;
- int longIndex; /* nedded for long option without a short arg */
- int listCount;
- /* init the getopt */
- optind=1;
- /* parsing arguments */
- while (opt != -1)
- {
- opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
- switch (opt)
- {
- case 'l':
- if(listIndex<0)
- {
- listIndex = atoi(optarg);
- }
- else
- {
- secListIndex = atoi(optarg);
- }
- break;
- case 'p':
- print = 1;
- break;
- case 's':
- sortType = atoi(optarg);
- break;
- case 'c':
- favListName = optarg;
- break;
- case 'a':
- addIndex = atoi(optarg);
- break;
- case 'd':
- delIndex = atoi(optarg);
- break;
- case 'e':
- erase = 1;
- break;
- case 'f':
- filterType = 0x1 << atoi(optarg);
- break;
- case 'w':
- getActive = 1;
- break;
- case 'i':
- getLast = 1;
- break;
- case 'z':
- getPrevious = 1;
- break;
- case 'n':
- getListName = 1;
- break;
- case 'r':
- newListName = 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 index is valid */
- if(favListName!=NULL)
- {
- /* TO_DO */
- /* Create favourite list */
- malError = MAL_SZ_CreateFavList(favListName, (mal_uint32*)&listIndex);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error creating list");
- return -1;
- }
- }
- 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;
- }
- if(sortType>=0 && sortType <=20)
- {
- /* TODO: Ugly hack with sortCriteria ;) */
- malError = MAL_SZ_SortServiceList(listIndex, (MAL_SZ_SortCriteria)sortType);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error sorting list");
- return -1;
- }
- }
- if(addIndex>0)
- {
- /* TO_DO */
- /* Add service in service list */
- malError = MAL_SZ_AddServiceInServiceList((mal_uint32)listIndex, (mal_uint32)addIndex);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error adding service");
- return -1;
- }
- }
- if(delIndex>0)
- {
- /* TO_DO */
- /* Delete service from servicelist */
- malError = MAL_SZ_DeleteServiceFromServiceList((mal_uint32)listIndex, (mal_uint32)delIndex);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: error deleting service");
- return -1;
- }
- }
- if(erase)
- {
- /* TO_DO */
- /* Delete service list */
- malError = MAL_SZ_DeleteServiceList((mal_uint32)listIndex);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error gdeleting service list");
- return -1;
- }
- }
- if(filterType>0)
- {
- if(secListIndex!=0)
- {
- malError = MAL_SZ_FilterServiceList(listIndex,secListIndex,filterType);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error filtering service list %d to service list %d with filter(adapted) %d",listIndex,secListIndex,filterType);
- return -1;
- }
- }
- else
- {
- CLI_ERROR("CLI_SERVICELIST: Error - secondary list index not specified or set to zero (master list), please specifiy a valid list index");
- return -1;
- }
- }
- if(getActive)
- {
- /* TO_DO */
- /* Get active service */
- malError = MAL_SZ_GetActiveService(liveRoutes[curLiveRouteIdx], (mal_uint32*)&getActive);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error getting active service");
- return -1;
- }
- CLI_PRINT("CLI_SERVICELIST: Active service: %d", getActive);
- }
- if(getLast)
- {
- malError = MAL_SZ_GetLastPlayedListAndService((mal_uint32*)&getLastList,(mal_uint32*)&getLast);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error getting last service and list index");
- return -1;
- }
- CLI_PRINT("CLI_SERVICELIST: Last watched service: %d",getLast);
- CLI_PRINT("CLI_SERVICELIST: Last watched list: %d",getLastList);
- }
- if(getPrevious)
- {
- malError = MAL_SZ_GetPreviousPlayedService((mal_uint32*)&getPrevious);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error getting previous service index");
- return -1;
- }
- CLI_PRINT("CLI_SERVICELIST: Previously watched service: %d",getPrevious);
- }
- if(getListName)
- {
- /* TO_DO */
- /* Get list name */
- malError = MAL_SZ_GetServiceListName((mal_uint32)listIndex, (mal_char*)listName);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error getting list name");
- return -1;
- }
- CLI_PRINT("CLI_SERVICELIST: List name: %s", listName);
- }
- if(newListName!=NULL)
- {
- if(listIndex!=0)
- {
- malError = MAL_SZ_RenameList(listIndex,newListName);
- if(malError!=MAL_SZ_NO_ERROR)
- {
- CLI_ERROR("CLI_SERVICELIST: Error renaming service list %d",listIndex);
- return -1;
- }
- }
- else
- {
- CLI_ERROR("CLI_SERVICELIST: Error - list index not specified or set to zero (master list), please specifiy a valid list index");
- return -1;
- }
- }
- if(print)
- {
- CLI_PRINT("CLI_SERVICELIST: listCount: %u",listCount);
- if(print_services(listIndex)<0)
- {
- return -1;
- }
- }
- if(opt!='h' && opt!='?')
- {
- CLI_PRINT("CLI_SERVICELIST: SUCCESS!");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement