28 #include <sys/types.h>
58 #define MODE_XML_TO_BINARY "xtob"
59 #define MODE_BINARY_TO_XML "btox"
60 #define MODE_DUMP_TO_CONSOLE "dump"
80 printf(
"\nRDK SI CACHE CONVERTER \t- User's Manual\n");
81 printf(
"\nUSAGE: \n\n\t%s [-mode MODE] [-input INPUT_FILE] [-output OUTPUT_FILE] [-sioutput SIOUTPUT_FILE] [-snsoutput SNSOUTPUT_FILE] [-help] [-version]\n", app_name);
82 printf(
"\nDESCRIPTION:\n\n\tRDK SI Cache Converter is a tool to convert the the given SI Cache file from binary to XML format or vice versa based on the specified mode. This tool helps to enhance the existing channel map\n\tto support the development activities at locations where Comcast head-end connectivity is not available. This tool uses Libxml2 XML toolkit (http://xmlsoft.org/) for all XML related operations.\n\nOPTIONS:\n\n");
83 printf(
"\t-mode\t\t: Operation mode. It can be one of the following:\n");
84 printf(
"\t\t\t\txtob - Generate SI Cache binaries from the given XML file\n");
85 printf(
"\t\t\t\tbtox - Generate SI Cache XML file from the given binary file\n");
86 printf(
"\t\t\t\tdump - Dump channel map from the given binary file to console\n");
87 printf(
"\t-input \t: Input file. It can be an XML file or a binary SI Cache file depending on the operation mode\n");
88 printf(
"\t-output \t: Output file. It can be a binary SI Cache file or an XML file depending on the operation mode\n");
89 printf(
"\t-sioutput \t: Binary SI Cache file to be generated. To use this option, the mode should be set to 'xtob'\n");
90 printf(
"\t-snsoutput\t: Binary SNS Cache file to be generated. To use this option, the mode should be set to 'xtob'\n");
91 printf(
"\t-version\t: Prints the tool's version details\n");
92 printf(
"\t-help\t\t: Prints this user's manual\n");
93 printf(
"\nEXAMPLES:\n");
94 printf(
"\n(i) Command to generate binary SI cache from given XML file:\n");
95 printf(
"\t%s -mode xtob -input si.xml -output SICache\n", app_name);
96 printf(
"\n(ii) Command to generate both binary SI cache and binary SNS cache from given XML file:\n");
97 printf(
"\t%s -mode xtob -input si.xml -sioutput SICache -snsoutput SNSCache \n",app_name);
98 printf(
"\n(iii) Command to generate XML file from binary SI cache:\n");
99 printf(
"\t%s -mode btox -input SICache -output si.xml\n", app_name);
100 printf(
"\n(iv) Command to dump channel map from binary SI cache to console:\n");
101 printf(
"\t%s -mode dump -input SICache \n\n", app_name);
121 bool processCommandLine(
int argc,
char** argv,
string& mode,
string& input_file,
string& output_file,
string& output_file_sns)
131 for(
int i=1; i < argc; ++i)
133 if(std::string(argv[i]) ==
"-help")
138 else if(std::string(argv[i]) ==
"-version")
140 printf(
"RDK SI CACHE CONVERTER - %s\nCopyright 2016 RDK Management, Licensed under the Apache License,Version 2.0\n", PACKAGE_VERSION);
143 else if(std::string(argv[i]) ==
"-mode")
145 if(i < argc-1 && argv[i+1][0] !=
'-')
148 if((mode != MODE_XML_TO_BINARY) && (mode != MODE_BINARY_TO_XML) && (mode != MODE_DUMP_TO_CONSOLE))
150 printf(
"argv[0]: invalid mode option '%s'. Try '%s -help' for more info.\n", mode.c_str(),argv[0]);
156 else if(std::string(argv[i]) ==
"-input")
158 if(i < argc-1 && argv[i+1][0] !=
'-')
159 input_file = argv[++i];
161 else if((std::string(argv[i]) ==
"-output") && (mode != MODE_DUMP_TO_CONSOLE))
163 if(i < argc-1 && argv[i+1][0] !=
'-')
164 output_file = argv[++i];
166 else if((std::string(argv[i]) ==
"-sioutput") && (mode == MODE_XML_TO_BINARY))
168 if(i < argc-1 && argv[i+1][0] !=
'-')
169 output_file = argv[++i];
171 else if((std::string(argv[i]) ==
"-snsoutput") && (mode == MODE_XML_TO_BINARY))
173 if(i < argc-1 && argv[i+1][0] !=
'-')
174 output_file_sns = argv[++i];
178 printf(
"argv[0]: invalid option '%s'. Try '%s -help' for more info.\n", argv[i], argv[0]);
186 printf(
"Mode: unset \n");
190 if(input_file.empty())
192 printf(
"Input file: unset \n");
196 if(output_file.empty() && (mode != MODE_DUMP_TO_CONSOLE))
198 printf(
"Output file: unset \n");
205 int main(
int argc,
char ** argv)
210 string output_sns_file;
218 if(mode == MODE_XML_TO_BINARY)
222 if(pSiMgr->
Load(input_file, SI_FILETYPE_XML))
224 if(output_sns_file.empty())
230 else if(mode == MODE_BINARY_TO_XML)
234 if(pSiMgr->
Load(input_file, SI_FILETYPE_BINARY))
239 else if(mode == MODE_DUMP_TO_CONSOLE)
243 if(pSiMgr->
Load(input_file, SI_FILETYPE_BINARY))