49 class prefixbuf :
public std::streambuf
56 prefixbuf( std::streambuf* opt ) : _opt(opt)
75 if( _opt->sputn(
"300 ", 4) != 4 )
81 int ret = _opt->sputc(c);
82 newline = ( c ==
'\n' );
90 return _opt->pubsync();
97 class prefixstr :
public std::ostream
100 prefixstr(std::ostream& opt)
101 :
std::ostream( new prefixbuf( opt.rdbuf() ) )
113 char to_upper (
const char c)
124 void maincode(
int, std::string* )
126 std::vector<std::string> list = _parent->getConnection()->getMarshaller()->getReporter()->getReport()->list();
127 for(
unsigned int i=0;i<list.size();i++)
128 socket()<<
"305 "<<list[i]<<std::endl;
129 socket() <<
"306 End of list" << std::endl;
155 const std::vector<Command*> &cmds = _parent->giveCommands();
156 socket() <<
"Use HELP <command>" << std::endl;
157 for(
unsigned int i = 0; i < cmds.size(); i++ )
159 if( cmds[i] == cmds[i]->getRealCommand( cmds ) )
161 socket() << cmds[i]->
getName() <<
'\n';
164 socket() <<
'.' << std::endl;
170 void printHelpFor(
const std::string& name,
const RealCommand* command )
172 socket() <<
"Name: " << name << std::endl;
173 socket() <<
"Usage: " << name;
178 socket() << std::endl;
184 void printHelpFor(
const std::string& cmd )
186 const std::vector<Command*> &cmds = _parent->giveCommands();
187 for(
unsigned int i = 0; i < cmds.size(); i++ )
189 if( cmds[i]->getName() == cmd )
191 printHelpFor( cmd, cmds[i]->getRealCommand( cmds ) );
198 void maincode(
int argc, std::string* params )
204 printHelpFor(params[0]);
209 :
RealCommand(
"HELP", parent, 0, 1,
"[nothing | <command name>]" )
217 void maincode(
int, std::string* )
219 socket() <<
"103 none" << std::endl;
232 void maincode(
int, std::string* )
252 void maincode(
int, std::string*
args )
256 unsigned long long limit = strtoull( args[0].c_str(), &tailptr, 10 );
257 if( *tailptr !=
'\0' || ( errno != olderr && errno == ERANGE ) )
261 _parent->getConnection()->setLimit(limit);
268 :
RealCommand(
"SETLIMIT", parent, 1, 1,
"<frameid>" )
279 void maincode(
int, std::string* args )
282 if( args[0] ==
"ON" )
284 _parent->getConnection()->silence(
true);
285 }
else if( args[0] ==
"OFF") {
286 _parent->getConnection()->silence(
false);
291 socket() <<
"107 Silence " << args[0] << std::endl;
296 :
RealCommand(
"SILENCE", parent, 1, 1,
"[ON | OFF]" )
310 void maincode(
int, std::string* args )
312 if( _parent->getConnection()->addSubscription(args[0]) )
314 socket() <<
"302 " << args[0] << std::endl;
316 socket() <<
"301 " << args[0] << std::endl;
322 :
RealCommand(
"SUBSCRIBE", parent, 1, 1,
"<source name>" )
330 void maincode(
int, std::string* )
332 _parent->getConnection()->listSubscriptions();
345 void maincode(
int, std::string* args )
347 if( _parent->getConnection()->removeSubscription(args[0]) )
349 socket() <<
"303 " << args[0] << std::endl;
351 socket() <<
"304 " << args[0] << std::endl;
357 :
RealCommand(
"UNSUBSCRIBE", parent, 1, 1,
"<source name>" )
365 void maincode(
int, std::string* args )
367 if( args[0] ==
"1.0" )
369 _parent->setVersion10();
372 socket() <<
"106 Not supported" << std::endl;
394 Command::Command( std::string name )
405 for(
unsigned int j = 0; j < cmds.size(); j++ )
407 if( *cmds[j] == cmp )
441 :
Command( name ), _alias( alias )
456 unsigned int maxargs,
const char* syntax )
457 :
Command( name ), _parent( parent ), _minargs( minargs ), _maxargs( maxargs ), _syntax( syntax )
483 socket() <<
"101 OK" << std::endl;
489 if( argc < _minargs || argc >
_maxargs )
511 std::transform( args[i].begin(), args[i].end(), args[i].begin(), to_upper );
516 for(
int i = start; i <= stop; i++ )
538 for( std::vector<Command*>::iterator i = cmds.begin();
551 std::vector<Command*>::iterator i = cmds.begin();
552 while( i != cmds.end() && *command < **i ) {
557 if( i != cmds.end() && *command == (*i)->
getName() )
561 cmds.insert( i, command );
590 std::transform( cmd.begin(), cmd.end(), cmd.begin(), to_upper );
593 bool correct =
false;
601 rcommand->
execute( argc, params );
616 std::string& ipt, std::string& cmd, std::string** params )
618 unsigned int argc = 0;
619 std::string::size_type pos = ipt.find_first_of(
"\t ", 0);
620 while( pos != std::string::npos )
622 pos = ipt.find_first_of(
"\t ", pos + 1);
627 *params =
new std::string[argc];
628 pos = ipt.find_first_of(
"\t ", 0);
629 cmd = ipt.substr(0, pos);
631 for(
unsigned int i = 0; i < argc; i++ )
633 npos = ipt.find_first_of(
"\t ", pos + 1);
634 (*params)[i] = ipt.substr(pos+1,npos - pos - 1);
647 std::vector<Command*>::iterator i = cmds.begin();
648 while( i != cmds.end() && **i != ipt ) {
651 if( i == cmds.end() )
Variable opBinary s not applicable to args
void toupper(std::string *args, int index) const
virtual RealCommand * getRealCommand(const std::vector< Command * > &cmds) const =0
void execute(int argc, std::string *args)
bool operator==(const std::string &cmp) const
unsigned int parseParameters(std::string &ipt, std::string &cmd, std::string **params)
virtual void maincode(int argc, std::string *args)=0
Datasender * getConnection() const
const char * getSyntax() const
bool operator!=(const std::string &cmp) const
TcpReportingInterpreter(Datasender *parent)
virtual RealCommand * getRealCommand(const std::vector< Command * > &cmds) const
AliasCommand(std::string name, std::string alias)
virtual bool correctSyntax(unsigned int argc, std::string *args)
std::vector< Command * > cmds
~TcpReportingInterpreter()
static Command * find(const std::vector< Command * > &cmds, const std::string &cmp)
virtual bool is(std::string &cmd) const
Socket & getSocket() const
bool operator<(const Command &cmp) const
const std::string & getName() const
virtual RealCommand * getRealCommand(const std::vector< Command * > &cmds) const
bool sendError102() const
static std::ostream & endl(std::ostream &__os)
const std::vector< Command * > & giveCommands() const
void addCommand(Command *command)
RealCommand(std::string name, TcpReportingInterpreter *parent, unsigned int minargs=0, unsigned int maxargs=0, const char *syntax=0)
void removeCommand(const char *name)
void silence(bool newstate)
TcpReportingInterpreter * _parent
RTT::os::MutexRecursive commands