50 using std::ostringstream;
52 #ifdef HAVE_LIBREADLINE
53 # if defined(HAVE_READLINE_READLINE_H)
54 # include <readline/readline.h>
55 # elif defined(HAVE_READLINE_H)
56 # include <readline.h>
59 char *readline(
const char *);
67 #ifdef HAVE_READLINE_HISTORY
68 # if defined(HAVE_READLINE_HISTORY_H)
69 # include <readline/history.h>
70 # elif defined(HAVE_HISTORY_H)
74 int add_history(
const char *);
75 int write_history(
const char *);
76 int read_history(
const char *);
81 #define SIZE_COMMUNICATION_BUFFER 4096*4096
89 if (_strmCreated && _strm) {
117 if (_strmCreated && _strm) {
124 _strmCreated = created;
141 string suppress =
"suppress" ;
142 if( cmd.compare( 0, suppress.length(), suppress ) == 0 )
148 string output =
"output to" ;
149 if( cmd.compare( 0, output.length(), output ) == 0 )
151 string subcmd = cmd.substr( output.length() + 1 ) ;
152 string screen =
"screen" ;
153 if( subcmd.compare( 0, screen.length(), screen ) == 0 )
160 string file = subcmd.substr( 0, subcmd.length() - 1 ) ;
161 ofstream *fstrm =
new ofstream( file.c_str(), ios::app ) ;
162 if( fstrm && !(*fstrm) )
165 cerr <<
"Unable to set client output to file " << file
177 string load =
"load" ;
178 if( cmd.compare( 0, load.length(), load ) == 0 )
180 string file = cmd.substr( load.length() + 1,
181 cmd.length() - load.length() - 2 ) ;
182 ifstream fstrm( file.c_str() ) ;
185 cerr <<
"Unable to load commands from file " << file
186 <<
": file does not exist or failed to open file" << endl ;
196 cerr <<
"Improper client command " << cmd << endl ;
212 StandAloneClient::executeCommand(
const string & cmd,
int repeat )
214 string client =
"client" ;
215 if( cmd.compare( 0, client.length(), client ) == 0 )
221 if( repeat < 1 ) repeat = 1 ;
222 for(
int i = 0; i < repeat; i++ )
224 ostringstream *show_stream = 0 ;
227 show_stream =
new ostringstream ;
229 BESDEBUG(
"standalone",
"cmdclient sending " << cmd << endl ) ;
243 BESDEBUG(
"standalone",
"BESServerHandler::execute - "
244 <<
"executed successfully" << endl ) ;
249 BESDEBUG(
"standalone",
"BESServerHandler::execute - "
250 "error occurred" << endl ) ;
257 interface->finish_with_error( status ) ;
263 cerr <<
"BES server " << getpid()
264 <<
": Status not OK, dispatcher returned value "
284 *(_strm) << show_stream->str() << endl ;
313 _isInteractive = true ;
314 if( repeat < 1 ) repeat = 1 ;
322 executeCommand( doc, repeat ) ;
328 _isInteractive = false ;
332 _isInteractive = false ;
356 _isInteractive = false ;
357 if( repeat < 1 ) repeat = 1 ;
358 for(
int i = 0; i < repeat; i++ )
361 istrm.seekg( 0, ios::beg ) ;
363 while( !istrm.eof() )
367 istrm.getline( line, 4096,
'\n' ) ;
370 this->executeCommand( cmd, 1 ) ;
392 _isInteractive = true ;
395 <<
"Type 'exit' to exit the command line client and 'help' or '?' "
396 <<
"to display the help screen" << endl << endl ;
401 string message =
"" ;
402 size_t len = this->readLine( message ) ;
403 if( len == -1 || message ==
"exit" || message ==
"exit;" )
407 else if( message ==
"help" || message ==
"help;" || message ==
"?" )
409 this->displayHelp() ;
411 else if( message.length() > 6 && message.substr( 0, 6 ) ==
"client" )
413 this->executeCommand( message, 1 ) ;
415 else if( len != 0 && message !=
"" )
423 this->executeCommand( doc, 1 ) ;
429 _isInteractive = false ;
435 _isInteractive = false ;
444 StandAloneClient::readLine(
string & msg)
447 char *buf = (
char *) NULL;
448 buf =::readline(
"BESClient> ");
451 #ifdef HAVE_READLINE_HISTORY
455 cerr << __FILE__ << __LINE__
457 ": incoming data buffer exceeds maximum capacity with lenght "
483 StandAloneClient::displayHelp()
487 cout <<
"BES Command Line Client Help" << endl;
489 cout <<
"Client commands available:" << endl;
491 " exit - exit the command line interface" <<
493 cout <<
" help - display this help screen" <<
496 " client suppress; - suppress output from the server" <<
499 " client output to screen; - display server output to the screen"
502 " client output to <file>; - display server output to specified file"
506 "Any commands beginning with 'client' must end with a semicolon" <<
509 cout <<
"To display the list of commands available from the server "
510 <<
"please type the command 'show help;'" << endl;
525 << (
void *)
this <<
")" << endl;
#define BES_SYNTAX_USER_ERROR
void executeCommands(const string &cmd_list, int repeat)
Send the command(s) specified to the BES server after wrapping in request document.
virtual int execute_request(const string &from)
Override execute_request in order to register memory pool.
void setOutput(ostream *strm, bool created)
Set the output stream for responses from the BES server.
#define BES_INTERNAL_ERROR
virtual void dump(ostream &strm) const
dumps information about this object
#define BES_FORBIDDEN_ERROR
static void set_show(bool val)
static string translate(const string &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 ostream & LMarg(ostream &strm)
#define SIZE_COMMUNICATION_BUFFER
#define BES_INTERNAL_FATAL_ERROR
Entry point into BES using xml document requests.
#define BES_NOT_FOUND_ERROR
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
void executeClientCommand(const string &cmd)
Executes a client side command.