00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ORO_COMP_TCP_REPORTING_COMMAND_HPP
00028 #define ORO_COMP_TCP_REPORTING_COMMAND_HPP
00029 #include <vector>
00030 #include <rtt/os/Mutex.hpp>
00031
00032 namespace OCL
00033 {
00034
00035 namespace TCP
00036 {
00037 class Datasender;
00038 class Socket;
00039 class Command;
00040 class RealCommand;
00041
00045 class TcpReportingInterpreter
00046 {
00047 protected:
00048 std::vector<Command*> cmds;
00049 RTT::os::MutexRecursive commands;
00050 unsigned int parseParameters( std::string& ipt, std::string& cmd, std::string** params );
00051 Datasender* _parent;
00052
00053 public:
00058 TcpReportingInterpreter(Datasender* parent);
00059 ~TcpReportingInterpreter();
00060 void process();
00061
00065 Datasender* getConnection() const;
00066
00070 void setVersion10();
00071
00075 const std::vector<Command*>& giveCommands() const;
00076
00080 void addCommand( Command* command );
00081
00085 void removeCommand( const char* name );
00086 };
00087
00091 class Command
00092 {
00093 protected:
00094 std::string _name;
00095
00096 public:
00097 Command( std::string name );
00098 virtual ~Command();
00099 virtual bool is(std::string& cmd) const;
00100
00107 virtual RealCommand* getRealCommand(const std::vector<Command*>& cmds) const = 0;
00108
00112 static Command* find(const std::vector<Command*>& cmds, const std::string& cmp);
00113
00117 bool operator==(const std::string& cmp) const;
00118 bool operator!=(const std::string& cmp) const;
00119 bool operator<( const Command& cmp ) const;
00120
00124 const std::string& getName() const;
00125 };
00126
00130 class AliasCommand : public Command
00131 {
00132 private:
00133 std::string _alias;
00134
00135 public:
00136 AliasCommand( std::string name, std::string alias );
00137 virtual ~AliasCommand() {}
00138 virtual RealCommand* getRealCommand(const std::vector<Command*>& cmds) const;
00139 };
00140
00144 class RealCommand : public Command
00145 {
00146 protected:
00147 TcpReportingInterpreter* _parent;
00148 unsigned int _minargs;
00149 unsigned int _maxargs;
00150 const char* _syntax;
00151
00155 virtual void maincode( int argc, std::string* args ) = 0;
00156
00161 bool sendError102() const;
00162
00167 bool sendOK() const;
00168
00173 void toupper( std::string* args, int index ) const;
00174
00180 void toupper( std::string* args, int start, int stop ) const;
00181
00186 inline Socket& socket() const;
00187
00188 public:
00189 RealCommand( std::string name, TcpReportingInterpreter* parent, unsigned int minargs = 0, unsigned int maxargs = 0, const char* syntax = 0);
00190 virtual ~RealCommand();
00191
00196 virtual bool correctSyntax( unsigned int argc, std::string* args );
00197
00201 const char* getSyntax() const;
00202
00206 virtual RealCommand* getRealCommand(const std::vector<Command*>& cmds) const;
00207
00211 void execute( int argc, std::string* args );
00212 };
00213 }
00214 }
00215 #endif