OrocosComponentLibrary  2.9.0
command.hpp
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;
49  RTT::os::MutexRecursive commands;
50  unsigned int parseParameters( std::string& ipt, std::string& cmd, std::string** params );
51  Datasender* _parent;
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:
147  TcpReportingInterpreter* _parent;
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
This class manages the connection with one single client.
Definition: datasender.hpp:59
TcpReportingInterpreter(Datasender *parent)
After setup, the interpreter will only recognize the command &#39;VERSION 1.0&#39; by default.
Definition: command.cpp:527
Reads a line from the client and interprete it.
Definition: command.hpp:45
Datasender * getConnection() const
Get the marshaller associated with the current connection.
Definition: command.cpp:570
const std::vector< Command * > & giveCommands() const
Return a reference to the command list.
Definition: command.cpp:565
Another name for a command.
Definition: command.hpp:130
The Orocos Component Library.
Definition: Component.hpp:43
Command pattern.
Definition: command.hpp:91
void removeCommand(const char *name)
Remove support for the given command name.
Definition: command.cpp:644
Real command which can be executed.
Definition: command.hpp:144
void setVersion10()
Accept all valid commands (except &#39;VERSION 1.0&#39;)
Definition: command.cpp:662
void addCommand(Command *command)
Add support for the given command.
Definition: command.cpp:546