53 using std::ostringstream;
55 #ifdef HAVE_LIBREADLINE
56 # if defined(HAVE_READLINE_READLINE_H)
57 # include <readline/readline.h>
58 # elif defined(HAVE_READLINE_H)
59 # include <readline.h>
62 char *readline(
const char *);
70 #ifdef HAVE_READLINE_HISTORY
71 # if defined(HAVE_READLINE_HISTORY_H)
72 # include <readline/history.h>
73 # elif defined(HAVE_HISTORY_H)
77 int add_history(
const char *);
78 int write_history(
const char *);
79 int read_history(
const char *);
84 #define SIZE_COMMUNICATION_BUFFER 4096*4096
92 if (_strmCreated && _strm) {
120 if (_strmCreated && _strm) {
127 _strmCreated = created;
144 string suppress =
"suppress" ;
145 if( cmd.compare( 0, suppress.length(), suppress ) == 0 )
151 string output =
"output to" ;
152 if( cmd.compare( 0, output.length(), output ) == 0 )
154 string subcmd = cmd.substr( output.length() + 1 ) ;
155 string screen =
"screen" ;
156 if( subcmd.compare( 0, screen.length(), screen ) == 0 )
163 string file = subcmd.substr( 0, subcmd.length() - 1 ) ;
164 ofstream *fstrm =
new ofstream( file.c_str(), ios::app ) ;
165 if( fstrm && !(*fstrm) )
168 cerr <<
"Unable to set client output to file " << file
180 string load =
"load" ;
181 if( cmd.compare( 0, load.length(), load ) == 0 )
183 string file = cmd.substr( load.length() + 1,
184 cmd.length() - load.length() - 2 ) ;
185 ifstream fstrm( file.c_str() ) ;
188 cerr <<
"Unable to load commands from file " << file
189 <<
": file does not exist or failed to open file" << endl ;
199 cerr <<
"Improper client command " << cmd << endl ;
215 StandAloneClient::executeCommand(
const string & cmd,
int repeat )
217 string client =
"client" ;
218 if( cmd.compare( 0, client.length(), client ) == 0 )
224 if( repeat < 1 ) repeat = 1 ;
225 for(
int i = 0; i < repeat; i++ )
227 ostringstream *show_stream = 0 ;
230 show_stream =
new ostringstream ;
232 BESDEBUG(
"standalone",
"cmdclient sending " << cmd << endl ) ;
246 BESDEBUG(
"standalone",
"BESServerHandler::execute - "
247 <<
"executed successfully" << endl ) ;
252 BESDEBUG(
"standalone",
"BESServerHandler::execute - "
253 "error occurred" << endl ) ;
260 interface->finish_with_error( status ) ;
266 cerr <<
"BES server " << getpid()
267 <<
": Status not OK, dispatcher returned value "
287 *(_strm) << show_stream->str() << endl ;
316 _isInteractive = true ;
317 if( repeat < 1 ) repeat = 1 ;
325 executeCommand( doc, repeat ) ;
331 _isInteractive = false ;
335 _isInteractive = false ;
359 _isInteractive = false ;
360 if( repeat < 1 ) repeat = 1 ;
361 for(
int i = 0; i < repeat; i++ )
364 istrm.seekg( 0, ios::beg ) ;
367 while(getline(istrm, line))
371 this->executeCommand( cmd, 1 ) ;
393 _isInteractive = true ;
396 <<
"Type 'exit' to exit the command line client and 'help' or '?' "
397 <<
"to display the help screen" << endl << endl ;
402 string message =
"" ;
403 size_t len = this->readLine( message ) ;
404 if( message ==
"exit" || message ==
"exit;" )
408 else if( message ==
"help" || message ==
"help;" || message ==
"?" )
410 this->displayHelp() ;
412 else if( message.length() > 6 && message.substr( 0, 6 ) ==
"client" )
414 this->executeCommand( message, 1 ) ;
416 else if( len != 0 && message !=
"" )
424 this->executeCommand( doc, 1 ) ;
430 _isInteractive = false ;
436 _isInteractive = false ;
445 StandAloneClient::readLine(
string & msg)
448 char *buf = (
char *) NULL;
449 buf =::readline(
"BESClient> ");
452 #ifdef HAVE_READLINE_HISTORY
456 cerr << __FILE__ << __LINE__
458 ": incoming data buffer exceeds maximum capacity with lenght "
484 StandAloneClient::displayHelp()
488 cout <<
"BES Command Line Client Help" << endl;
490 cout <<
"Client commands available:" << endl;
492 " exit - exit the command line interface" <<
494 cout <<
" help - display this help screen" <<
497 " client suppress; - suppress output from the server" <<
500 " client output to screen; - display server output to the screen"
503 " client output to <file>; - display server output to specified file"
507 "Any commands beginning with 'client' must end with a semicolon" <<
510 cout <<
"To display the list of commands available from the server "
511 <<
"please type the command 'show help;'" << endl;
526 << (
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.