command.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  command.hpp - Processes client commands
4  -------------------
5  begin : Wed Aug 9 2006
6  copyright : (C) 2006 Bas Kemper
7  email : kst@ <my name> .be
8 
9  ***************************************************************************
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU Lesser General Public *
12  * License as published by the Free Software Foundation; either *
13  * version 2.1 of the License, or (at your option) any later version. *
14  * *
15  * This library is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18  * Lesser General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU Lesser General Public *
21  * License along with this library; if not, write to the Free Software *
22  * Foundation, Inc., 59 Temple Place, *
23  * Suite 330, Boston, MA 02111-1307 USA *
24  * *
25  ***************************************************************************/
26 
27 #ifndef ORO_COMP_TCP_REPORTING_COMMAND_HPP
28 #define ORO_COMP_TCP_REPORTING_COMMAND_HPP
29 #include <vector>
30 #include <rtt/os/Mutex.hpp>
31 
32 namespace OCL
33 {
34 
35 namespace TCP
36 {
37  class Datasender;
38  class Socket;
39  class Command;
40  class RealCommand;
41 
46  {
47  protected:
48  std::vector<Command*> cmds;
50  unsigned int parseParameters( std::string& ipt, std::string& cmd, std::string** params );
52 
53  public:
60  void process();
61 
65  Datasender* getConnection() const;
66 
70  void setVersion10();
71 
75  const std::vector<Command*>& giveCommands() const;
76 
80  void addCommand( Command* command );
81 
85  void removeCommand( const char* name );
86  };
87 
91  class Command
92  {
93  protected:
94  std::string _name;
95 
96  public:
97  Command( std::string name );
98  virtual ~Command();
99  virtual bool is(std::string& cmd) const;
100 
107  virtual RealCommand* getRealCommand(const std::vector<Command*>& cmds) const = 0;
108 
112  static Command* find(const std::vector<Command*>& cmds, const std::string& cmp);
113 
117  bool operator==(const std::string& cmp) const;
118  bool operator!=(const std::string& cmp) const;
119  bool operator<( const Command& cmp ) const;
120 
124  const std::string& getName() const;
125  };
126 
130  class AliasCommand : public Command
131  {
132  private:
133  std::string _alias;
134 
135  public:
136  AliasCommand( std::string name, std::string alias );
137  virtual ~AliasCommand() {}
138  virtual RealCommand* getRealCommand(const std::vector<Command*>& cmds) const;
139  };
140 
144  class RealCommand : public Command
145  {
146  protected:
148  unsigned int _minargs;
149  unsigned int _maxargs;
150  const char* _syntax;
151 
155  virtual void maincode( int argc, std::string* args ) = 0;
156 
161  bool sendError102() const;
162 
167  bool sendOK() const;
168 
173  void toupper( std::string* args, int index ) const;
174 
180  void toupper( std::string* args, int start, int stop ) const;
181 
186  inline Socket& socket() const;
187 
188  public:
189  RealCommand( std::string name, TcpReportingInterpreter* parent, unsigned int minargs = 0, unsigned int maxargs = 0, const char* syntax = 0);
190  virtual ~RealCommand();
191 
196  virtual bool correctSyntax( unsigned int argc, std::string* args );
197 
201  const char* getSyntax() const;
202 
206  virtual RealCommand* getRealCommand(const std::vector<Command*>& cmds) const;
207 
211  void execute( int argc, std::string* args );
212  };
213 }
214 }
215 #endif
Variable opBinary s not applicable to args
Definition: rtt.cpp:757
unsigned int _minargs
Definition: command.hpp:148
const char * _syntax
Definition: command.hpp:150
unsigned int parseParameters(std::string &ipt, std::string &cmd, std::string **params)
Definition: command.cpp:615
Datasender * getConnection() const
Definition: command.cpp:570
bool operator<(const timespec &a, const timespec &b)
TcpReportingInterpreter(Datasender *parent)
Definition: command.cpp:527
std::vector< Command * > cmds
Definition: command.hpp:48
unsigned int _maxargs
Definition: command.hpp:149
const std::vector< Command * > & giveCommands() const
Definition: command.cpp:565
bool operator==(const AType &a, const AType &b)
void addCommand(Command *command)
Definition: command.cpp:546
std::string _name
Definition: command.hpp:94
std::string _alias
Definition: command.hpp:133
void removeCommand(const char *name)
Definition: command.cpp:644
bool operator!=(const local_allocator< T, A > &, const local_allocator< T, A2 > &)
TcpReportingInterpreter * _parent
Definition: command.hpp:147
RTT::os::MutexRecursive commands
Definition: command.hpp:49
virtual ~AliasCommand()
Definition: command.hpp:137


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27