61 _createdInputStrm( false ),
76 StandAloneApp::showVersion()
78 cout <<
appName() <<
": version 2.0" << endl ;
82 StandAloneApp::showUsage( )
85 cout <<
appName() <<
": the following flags are available:" << endl ;
86 cout <<
" -c <configFile> - specifies a BES configuration file to use" << endl ;
87 cout <<
" -x <command> - specifies a command for the server to execute" << endl ;
88 cout <<
" -i <inputFile> - specifies a file name for a sequence of input commands" << endl ;
89 cout <<
" -f <outputFile> - specifies a file name to output the results of the input" << endl ;
90 cout <<
" -d - sets the optional debug flag for the client session" << endl ;
91 cout <<
" -r <num> - repeat the command(s) num times" << endl ;
92 cout <<
" -? - display this list of flags" << endl ;
102 string outputStr =
"" ;
103 string inputStr =
"" ;
104 string repeatStr =
"" ;
106 bool badUsage = false ;
110 while( ( c = getopt( argc, argv,
"?vc:d:x:f:i:r:" ) ) != EOF )
147 if( outputStr !=
"" )
149 if( _cmd ==
"" && inputStr ==
"" )
151 cerr <<
"When specifying an output file you must either "
152 <<
"specify a command or an input file"
156 else if( _cmd !=
"" && inputStr !=
"" )
158 cerr <<
"You must specify either a command or an input file on "
159 <<
"the command line, not both"
165 if( badUsage ==
true )
171 if( outputStr !=
"" )
173 _outputStrm =
new ofstream( outputStr.c_str() ) ;
174 if( !(*_outputStrm) )
176 cerr <<
"could not open the output file " << outputStr << endl ;
183 _inputStrm =
new ifstream( inputStr.c_str() ) ;
186 cerr <<
"could not open the input file " << inputStr << endl ;
189 _createdInputStrm = true ;
192 if( !repeatStr.empty() )
194 _repeat = atoi( repeatStr.c_str() ) ;
195 if( !_repeat && repeatStr !=
"0" )
197 cerr <<
"repeat number invalid: " << repeatStr << endl ;
206 if( badUsage ==
true )
214 BESDEBUG(
"standalone",
"ServerApp: initializing default module ... "
217 BESDEBUG(
"standalone",
"ServerApp: done initializing default module"
220 BESDEBUG(
"standalone",
"ServerApp: initializing default commands ... "
223 BESDEBUG(
"standalone",
"ServerApp: done initializing default commands"
226 BESDEBUG(
"standalone",
"ServerApp: initializing loaded modules ... "
229 BESDEBUG(
"standalone",
"ServerApp: done initializing loaded modules"
236 cerr <<
"Failed to initialize stand alone app" << endl ;
241 BESDEBUG(
"standalone",
"StandAloneApp: initialized settings:"
255 _client->
setOutput( _outputStrm,
true ) ;
261 BESDEBUG(
"standalone",
"OK" << endl ) ;
270 BESDEBUG(
"standalone",
"FAILED" << endl ) ;
271 cerr <<
"error starting the client" << endl ;
282 else if( _inputStrm )
293 cerr <<
"error processing commands" << endl ;
299 BESDEBUG(
"standalone",
"StandAloneApp: shutting down client ... "
306 BESDEBUG(
"standalone",
"OK" << endl ) ;
308 BESDEBUG(
"standalone",
"StandAloneApp: closing input stream ... "
310 if( _createdInputStrm )
312 _inputStrm->close() ;
316 BESDEBUG(
"standalone",
"OK" << endl ) ;
320 BESDEBUG(
"standalone",
"FAILED" << endl ) ;
321 cerr <<
"error closing the client" << endl ;
337 BESDEBUG(
"standalone",
"ServerApp: terminating loaded modules ... "
340 BESDEBUG(
"standalone",
"ServerApp: done terminating loaded modules"
343 BESDEBUG(
"standalone",
"ServerApp: terminating default commands ... "
346 BESDEBUG(
"standalone",
"ServerApp: done terminating default commands"
349 BESDEBUG(
"standalone",
"ServerApp: terminating default module ... "
352 BESDEBUG(
"standalone",
"ServerApp: done terminating default module"
370 << (
void *)
this <<
")" << endl ;
375 BESIndent::Indent() ;
376 _client->
dump( strm ) ;
384 strm <<
BESIndent::LMarg <<
"output stream: " << (
void *)_outputStrm << endl ;
385 strm <<
BESIndent::LMarg <<
"input stream: " << (
void *)_inputStrm << endl ;
386 strm <<
BESIndent::LMarg <<
"created input stream? " << _createdInputStrm << endl ;
395 return app.
main( argc, argv ) ;