63 _createdInputStrm( false ),
81 StandAloneApp::showVersion()
83 cout <<
appName() <<
": version 2.0" << endl ;
87 StandAloneApp::showUsage( )
90 cout <<
appName() <<
": the following options are available:" << endl ;
91 cout <<
" -c <file>, --config=<file> - BES configuration file" << endl ;
92 cout <<
" -x <command>, --execute=<command> - command for the server to execute" << endl ;
93 cout <<
" -i <file>, --inputfile=<file> - file with a sequence of input commands" << endl ;
94 cout <<
" -f <file>, --outputfile=<file> - write output to this file" << endl ;
95 cout <<
" -d, --debug - turn on debugging for the client session" << endl ;
96 cout <<
" -r <num>, --repeat=<num> - repeat the command(s) <num> times" << endl ;
97 cout <<
" -v, --version - return version information" << endl;
98 cout <<
" -?, --help - display help information" << endl ;
108 string outputStr =
"" ;
109 string inputStr =
"" ;
110 string repeatStr =
"" ;
112 bool badUsage = false ;
116 static struct option longopts[] =
118 {
"config", 1, 0,
'c'},
119 {
"debug", 0, 0,
'd'},
120 {
"version", 0, 0,
'v'},
121 {
"execute", 1, 0,
'x'},
122 {
"outputfile", 1, 0,
'f'},
123 {
"inputfile", 1, 0,
'i'},
124 {
"repeat", 1, 0,
'r'},
128 int option_index = 0;
130 while( ( c = getopt_long( argc, argv,
"?vc:d:x:f:i:r:", longopts, &option_index) ) != EOF )
167 if( outputStr !=
"" )
169 if( _cmd ==
"" && inputStr ==
"" )
171 cerr <<
"When specifying an output file you must either "
172 <<
"specify a command or an input file"
176 else if( _cmd !=
"" && inputStr !=
"" )
178 cerr <<
"You must specify either a command or an input file on "
179 <<
"the command line, not both"
185 if( badUsage ==
true )
191 if( outputStr !=
"" )
193 _outputStrm =
new ofstream( outputStr.c_str() ) ;
194 if( !(*_outputStrm) )
196 cerr <<
"could not open the output file " << outputStr << endl ;
203 _inputStrm =
new ifstream( inputStr.c_str() ) ;
206 cerr <<
"could not open the input file " << inputStr << endl ;
209 _createdInputStrm = true ;
212 if( !repeatStr.empty() )
214 _repeat = atoi( repeatStr.c_str() ) ;
215 if( !_repeat && repeatStr !=
"0" )
217 cerr <<
"repeat number invalid: " << repeatStr << endl ;
226 if( badUsage ==
true )
234 BESDEBUG(
"standalone",
"ServerApp: initializing default module ... "
237 BESDEBUG(
"standalone",
"ServerApp: done initializing default module"
240 BESDEBUG(
"standalone",
"ServerApp: initializing default commands ... "
243 BESDEBUG(
"standalone",
"ServerApp: done initializing default commands"
246 BESDEBUG(
"standalone",
"ServerApp: initializing loaded modules ... "
249 BESDEBUG(
"standalone",
"ServerApp: done initializing loaded modules"
256 cerr <<
"Failed to initialize stand alone app" << endl ;
261 BESDEBUG(
"standalone",
"StandAloneApp: initialized settings:"
275 _client->
setOutput( _outputStrm,
true ) ;
281 BESDEBUG(
"standalone",
"OK" << endl ) ;
290 BESDEBUG(
"standalone",
"FAILED" << endl ) ;
291 cerr <<
"error starting the client" << endl ;
302 else if( _inputStrm )
313 cerr <<
"error processing commands" << endl ;
319 BESDEBUG(
"standalone",
"StandAloneApp: shutting down client ... "
326 BESDEBUG(
"standalone",
"OK" << endl ) ;
328 BESDEBUG(
"standalone",
"StandAloneApp: closing input stream ... "
330 if( _createdInputStrm )
332 _inputStrm->close() ;
336 BESDEBUG(
"standalone",
"OK" << endl ) ;
340 BESDEBUG(
"standalone",
"FAILED" << endl ) ;
341 cerr <<
"error closing the client" << endl ;
357 BESDEBUG(
"standalone",
"ServerApp: terminating loaded modules ... "
360 BESDEBUG(
"standalone",
"ServerApp: done terminating loaded modules"
363 BESDEBUG(
"standalone",
"ServerApp: terminating default commands ... "
366 BESDEBUG(
"standalone",
"ServerApp: done terminating default commands"
369 BESDEBUG(
"standalone",
"ServerApp: terminating default module ... "
372 BESDEBUG(
"standalone",
"ServerApp: done terminating default module"
390 << (
void *)
this <<
")" << endl ;
396 _client->
dump( strm ) ;
404 strm <<
BESIndent::LMarg <<
"output stream: " << (
void *)_outputStrm << endl ;
405 strm <<
BESIndent::LMarg <<
"input stream: " << (
void *)_inputStrm << endl ;
406 strm <<
BESIndent::LMarg <<
"created input stream? " << _createdInputStrm << endl ;
415 return app.
main( argc, argv ) ;
void executeCommands(const string &cmd_list, int repeat)
Send the command(s) specified to the BES server after wrapping in request document.
virtual int run()
the applications functionality is implemented in the run method
void setOutput(ostream *strm, bool created)
Set the output stream for responses from the BES server.
static void SetUp(const string &values)
Sets up debugging for the bes.
static int initialize(int argc, char **argv)
virtual void dump(ostream &strm) const
dumps information about this object
virtual int main(int argC, char **argV)
main method of the BES application
static int terminate(void)
virtual int terminate(int sig=0)
clean up after the application
StandAloneClient is an object that handles the connection to, sending requests to, and receiving response from a specified OpenDAP server running either on this machine or another machine.
static int terminate(void)
Removes the default set of BES XML commands from the list of possible commands.
string appName(void) const
Returns the name of the application.
virtual string get_message()
get the error message for this exception
virtual int initialize(int argC, char **argV)
Load and initialize any BES modules.
static int initialize(int argc, char **argv)
Loads the default set of BES XML commands.
Abstract exception class for the BES with basic string message.
void interact()
An interactive BES client that takes BES requests on the command line.
static void Help(ostream &strm)
Writes help information for so that developers know what can be set for debugging.
static int terminate(void)
static ostream & LMarg(ostream &strm)
virtual void dump(ostream &strm) const
dumps information about this object
Base application object for all BES applications.
virtual int initialize(int argC, char **argV)
Load and initialize any BES modules.
virtual int terminate(int sig=0)
clean up after the application
static int initialize(int argc, char **argv)
virtual void dump(ostream &strm) const
dumps information about this object
int main(int argc, char **argv)
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static void delete_all_catalogs()
static BESKeys * TheKeys()