59 #define BES_CMDLN_DEFAULT_TIMEOUT 5 69 _createdInputStrm( false ),
87 cout <<
appName() <<
": version 2.0" << endl ;
94 cout <<
appName() <<
": the following flags are available:" << endl ;
95 cout <<
" -h <host> - specifies a host for TCP/IP connection" << endl ;
96 cout <<
" -p <port> - specifies a port for TCP/IP connection" << endl ;
97 cout <<
" -u <unixSocket> - specifies a unix socket for connection. " << endl ;
98 cout <<
" -x <command> - specifies a command for the server to execute" << endl ;
99 cout <<
" -i <inputFile> - specifies a file name for a sequence of input commands" << endl ;
100 cout <<
" -f <outputFile> - specifies a file name to output the results of the input" << endl ;
101 cout <<
" -t <timeoutVal> - specifies an optional timeout value in seconds" << endl ;
102 cout <<
" -d - sets the optional debug flag for the client session" << endl ;
103 cout <<
" -r <num> - repeat the command(s) num times" << endl ;
104 cout <<
" -? - display this list of flags" << endl ;
121 <<
": No response, server may be down or " 122 <<
"busy with another incoming connection. exiting!\n" ;
135 <<
": Please type exit to terminate the session" << endl ;
140 <<
": Could not re-register signal\n" ;
150 <<
": Please type exit to terminate the session" << endl ;
155 <<
": Could not re-register signal\n" ;
165 <<
": got a broken pipe, server may be down or the port invalid." 167 <<
"Please check parameters and try again" << endl ;
185 CmdApp::registerSignals()
188 BESDEBUG(
"cmdln",
"CmdApp: Registering signal SIGCONT ... " << endl ) ;
191 BESDEBUG(
"cmdln",
"FAILED" << endl ) ;
192 cerr <<
appName() <<
"Failed to register signal SIGCONT" << endl ;
199 BESDEBUG(
"cmdln",
"CmdApp: Registering signal SIGINT ... " << endl ) ;
202 BESDEBUG(
"cmdln",
"FAILED" << endl ) ;
203 cerr <<
appName() <<
"Failed to register signal SIGINT" << endl ;
210 BESDEBUG(
"cmdln",
"CmdApp: Registering signal SIGTERM ... " << endl ) ;
213 BESDEBUG(
"cmdln",
"FAILED" << endl ) ;
214 cerr <<
appName() <<
"Failed to register signal SIGTERM" << endl ;
220 BESDEBUG(
"cmdln",
"CmdApp: Registering signal SIGPIPE ... " << endl ) ;
223 BESDEBUG(
"cmdln",
"FAILED" << endl ) ;
224 cerr <<
appName() <<
"Failed to register signal SIGPIPE" << endl ;
239 string portStr =
"" ;
240 string outputStr =
"" ;
241 string inputStr =
"" ;
242 string timeoutStr =
"" ;
243 string repeatStr =
"" ;
245 bool badUsage = false ;
249 while( ( c = getopt( argc, argv,
"?vd:h:p:t:u:x:f:i:r:" ) ) != EOF )
254 timeoutStr = optarg ;
294 if( _hostStr ==
"" && _unixStr ==
"" )
296 cerr <<
"host/port or unix socket must be specified" << endl ;
300 if( _hostStr !=
"" && _unixStr !=
"" )
302 cerr <<
"must specify either a host and port or a unix socket" << endl ;
306 if( portStr !=
"" && _unixStr !=
"" )
308 cerr <<
"must specify either a host and port or a unix socket" << endl ;
316 cout <<
"port must be specified when specifying a host" << endl ;
321 _portVal = atoi( portStr.c_str() ) ;
325 if( timeoutStr !=
"" )
327 _timeout = atoi( timeoutStr.c_str() ) ;
334 if( outputStr !=
"" )
336 if( _cmd ==
"" && inputStr ==
"" )
338 cerr <<
"When specifying an output file you must either " 339 <<
"specify a command or an input file" 343 else if( _cmd !=
"" && inputStr !=
"" )
345 cerr <<
"You must specify either a command or an input file on " 346 <<
"the command line, not both" 352 if( badUsage ==
true )
358 if( outputStr !=
"" )
360 _outputStrm =
new ofstream( outputStr.c_str() ) ;
361 if( !(*_outputStrm) )
363 cerr <<
"could not open the output file " << outputStr << endl ;
370 _inputStrm =
new ifstream( inputStr.c_str() ) ;
373 cerr <<
"could not open the input file " << inputStr << endl ;
376 _createdInputStrm = true ;
379 if( !repeatStr.empty() )
381 _repeat = atoi( repeatStr.c_str() ) ;
382 if( !_repeat && repeatStr !=
"0" )
384 cerr <<
"repeat number invalid: " << repeatStr << endl ;
393 if( badUsage ==
true )
401 BESDEBUG(
"cmdln",
"CmdApp: initialized settings:" << endl << *
this ) ;
414 BESDEBUG(
"cmdln",
"CmdApp: Connecting to host: " << _hostStr
415 <<
" at port: " << _portVal <<
" ... " << endl ) ;
416 _client->
startClient( _hostStr, _portVal, _timeout ) ;
420 BESDEBUG(
"cmdln",
"CmdApp: Connecting to unix socket: " 421 << _unixStr <<
" ... " << endl ) ;
427 _client->
setOutput( _outputStrm,
true ) ;
443 BESDEBUG(
"cmdln",
"FAILED" << endl ) ;
444 cerr <<
"error starting the client" << endl ;
449 bool do_exit = false ;
456 else if( _inputStrm )
467 cerr <<
"error processing commands" << endl ;
473 BESDEBUG(
"cmdln",
"CmdApp: shutting down client ... " << endl ) ;
484 BESDEBUG(
"cmdln",
"CmdApp: closing input stream ... " << endl ) ;
485 if( _createdInputStrm )
487 _inputStrm->close() ;
495 BESDEBUG(
"cmdln",
"FAILED" << endl ) ;
496 cerr <<
"error closing the client" << endl ;
514 << (
void *)
this <<
")" << endl ;
520 _client->
dump( strm ) ;
531 strm <<
BESIndent::LMarg <<
"output stream: " << (
void *)_outputStrm << endl ;
532 strm <<
BESIndent::LMarg <<
"input stream: " << (
void *)_inputStrm << endl ;
533 strm <<
BESIndent::LMarg <<
"created input stream? " << _createdInputStrm << endl ;
543 return app.
main( argc, argv ) ;
virtual int initialize(int argC, char **argV)
initialize the BES application
void shutdownClient()
Closes the connection to the OpeNDAP server and closes the output stream.
virtual int initialize(int argC, char **argV)
initialize the BES application
static void SetUp(const string &values)
Sets up debugging for the bes.
static void signalCannotConnect(int sig)
Base application object for all BES applications.
virtual int main(int argC, char **argV)
main method of the BES application
void brokenPipe()
inform the server that there has been a borken pipe
virtual void dump(ostream &strm) const
dumps information about this object
virtual string get_message()
get the error message for this exception
static void signalBrokenPipe(int sig)
#define BES_CMDLN_DEFAULT_TIMEOUT
Abstract exception class for the BES with basic string message.
static void Help(ostream &strm)
Writes help information for so that developers know what can be set for debugging.
static void signalTerminate(int sig)
static ostream & LMarg(ostream &strm)
bool isConnected()
return whether the client is connected to the BES
virtual int run()
the applications functionality is implemented in the run method
static void signalInterrupt(int sig)
virtual void dump(ostream &strm) const
dumps information about this object
string appName(void) const
Returns the name of the application.
void startClient(const string &host, int portVal, int timeout)
Connect the BES client to the BES server.
virtual void dump(ostream &strm) const
dumps information about this object
CmdClient is an object that handles the connection to, sending requests to, and receiving response fr...
void setOutput(ostream *strm, bool created)
Set the output stream for responses from the BES server.
static int initialize(int argc, char **argv)
bool executeCommands(const string &cmd, int repeat)
Send the command(s) specified to the BES server after wrapping in request document.
bool interact()
An interactive BES client that takes BES requests on the command line.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static BESApp * TheApplication(void)
Returns the BESApp application object for this application.