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) {
128 _strmCreated = created;
144 string suppress =
"suppress";
145 if (cmd.compare(0, suppress.length(), suppress) == 0) {
150 string output =
"output to";
151 if (cmd.compare(0, output.length(), output) == 0) {
152 string subcmd = cmd.substr(output.length() + 1);
153 string screen =
"screen";
154 if (subcmd.compare(0, screen.length(), screen) == 0) {
159 string file = subcmd.substr(0, subcmd.length() - 1);
160 ofstream *fstrm =
new ofstream(file.c_str(), ios::app);
161 if (fstrm && !(*fstrm)) {
163 cerr <<
"Unable to set client output to file " << file << endl;
173 string load =
"load";
174 if (cmd.compare(0, load.length(), load) == 0) {
175 string file = cmd.substr(load.length() + 1, cmd.length() - load.length() - 2);
176 ifstream fstrm(file.c_str());
178 cerr <<
"Unable to load commands from file " << file <<
": file does not exist or failed to open file"
188 cerr <<
"Improper client command " << cmd << endl;
203 void StandAloneClient::executeCommand(
const string & cmd,
int repeat)
205 string client =
"client";
206 if (cmd.compare(0, client.length(), client) == 0) {
210 if (repeat < 1) repeat = 1;
211 for (
int i = 0; i < repeat; i++) {
212 ostringstream *show_stream = 0;
214 show_stream =
new ostringstream;
216 BESDEBUG(
"standalone",
"cmdclient sending " << cmd << endl );
227 BESDEBUG(
"standalone",
"BESServerHandler::execute - "
228 <<
"executed successfully" << endl );
233 BESDEBUG(
"standalone",
"BESServerHandler::execute - "
234 "error occurred" << endl );
241 interface->finish_with_error( status );
247 cerr <<
"BES server " << getpid()
248 <<
": Status not OK, dispatcher returned value "
265 *(_strm) << show_stream->str() << endl;
293 _isInteractive =
true;
294 if (repeat < 1) repeat = 1;
300 executeCommand(doc, repeat);
305 _isInteractive =
false;
309 _isInteractive =
false;
332 _isInteractive =
false;
333 if (repeat < 1) repeat = 1;
334 for (
int i = 0; i < repeat; i++) {
336 istrm.seekg(0, ios::beg);
339 while (getline(istrm, line)) {
342 this->executeCommand(cmd, 1);
363 _isInteractive =
true;
365 cout << endl << endl <<
"Type 'exit' to exit the command line client and 'help' or '?' "
366 <<
"to display the help screen" << endl << endl;
371 size_t len = this->readLine(message);
372 if ( message ==
"exit" || message ==
"exit;") {
375 else if (message ==
"help" || message ==
"help;" || message ==
"?") {
378 else if (message.length() > 6 && message.substr(0, 6) ==
"client") {
379 this->executeCommand(message, 1);
381 else if (len != 0 && message !=
"") {
386 this->executeCommand(doc, 1);
391 _isInteractive =
false;
397 _isInteractive =
false;
405 size_t StandAloneClient::readLine(
string & msg)
408 char *buf = (
char *)
NULL;
409 buf = ::readline(
"BESClient> ");
412 #ifdef HAVE_READLINE_HISTORY
416 cerr << __FILE__ << __LINE__ <<
417 ": incoming data buffer exceeds maximum capacity with lenght " << len << endl;
443 void StandAloneClient::displayHelp()
447 cout <<
"BES Command Line Client Help" << endl;
449 cout <<
"Client commands available:" << endl;
450 cout <<
" exit - exit the command line interface" << endl;
451 cout <<
" help - display this help screen" << endl;
452 cout <<
" client suppress; - suppress output from the server" << endl;
453 cout <<
" client output to screen; - display server output to the screen" << endl;
454 cout <<
" client output to <file>; - display server output to specified file" << endl;
456 cout <<
"Any commands beginning with 'client' must end with a semicolon" << endl;
458 cout <<
"To display the list of commands available from the server " <<
"please type the command 'show help;'"
472 strm <<
BESIndent::LMarg <<
"StandAloneClient::dump - (" << (
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.