OrocosComponentLibrary
2.7.0
|
00001 /*************************************************************************** 00002 00003 command.hpp - Processes client commands 00004 ------------------- 00005 begin : Wed Aug 9 2006 00006 copyright : (C) 2006 Bas Kemper 00007 email : kst@ <my name> .be 00008 00009 *************************************************************************** 00010 * This library is free software; you can redistribute it and/or * 00011 * modify it under the terms of the GNU Lesser General Public * 00012 * License as published by the Free Software Foundation; either * 00013 * version 2.1 of the License, or (at your option) any later version. * 00014 * * 00015 * This library is distributed in the hope that it will be useful, * 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00018 * Lesser General Public License for more details. * 00019 * * 00020 * You should have received a copy of the GNU Lesser General Public * 00021 * License along with this library; if not, write to the Free Software * 00022 * Foundation, Inc., 59 Temple Place, * 00023 * Suite 330, Boston, MA 02111-1307 USA * 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