ocra-recipes
Doxygen documentation for the ocra-recipes repository
ClientCommunications.h
Go to the documentation of this file.
1 #ifndef CLIENT_COMMUNICATIONS_H
2 #define CLIENT_COMMUNICATIONS_H
3 
4 #include <iostream>
5 #include <memory>
6 #include <map>
7 
8 #include <Eigen/Dense>
9 #include <Eigen/Lgsm>
10 
11 
12 // TODO: Should put in defines for yarp independent builds
13 #include <yarp/os/Bottle.h>
14 #include <yarp/os/RpcClient.h>
15 #include <yarp/os/Port.h>
16 #include <yarp/os/Network.h>
17 #include <yarp/os/Log.h>
18 #include <yarp/os/LogStream.h>
19 #include <yarp/os/PortReader.h>
20 #include <yarp/os/ConnectionReader.h>
21 #include <yarp/os/Time.h>
22 
25 #include <ocra/util/Macros.h>
26 
27 
28 namespace ocra_recipes
29 {
30 class ClientCommunications : public yarp::os::PortReader
31 {
33 using TaskPortMap = std::map<std::string, std::shared_ptr<yarp::os::RpcClient> >;
34 
35 public:
37  virtual ~ClientCommunications();
38 
46  bool open(double timeout = 20.0, bool connectToTasks = true);
47 
53  bool close();
54 
60  void close(const std::string& taskName);
61 
69  virtual bool read(yarp::os::ConnectionReader& connection);
70 
76  void parseMessage(yarp::os::Bottle& input);
77 
83  std::vector<std::string> getTaskTypes();
84 
92  yarp::os::Bottle queryController(yarp::os::Bottle& requestBottle);
93 
101  yarp::os::Bottle queryController(const SERVER_COMMUNICATIONS_MESSAGE request);
102 
110  yarp::os::Bottle queryController(const std::vector<SERVER_COMMUNICATIONS_MESSAGE> requestVector);
111 
112  // void queryController(const SERVER_COMMUNICATIONS_MESSAGE request, yarp::os::Bottle& reply);
113 
114  // void queryTask(const std::string& taskName, const SERVER_COMMUNICATIONS_MESSAGE request, yarp::os::Bottle& reply);
115  // void queryTask(const int taskIndex, const SERVER_COMMUNICATIONS_MESSAGE request, yarp::os::Bottle& reply);
116  // void queryTasks(const SERVER_COMMUNICATIONS_MESSAGE request, std::vector<yarp::os::Bottle&>& replies);
117  // void queryTasks(const std::vector<SERVER_COMMUNICATIONS_MESSAGE>& requests, std::vector<yarp::os::Bottle&>& replies);
118  // void queryTasks(const std::vector<SERVER_COMMUNICATIONS_MESSAGE>& requests, std::vector<yarp::os::Bottle&>& replies);
119 
120  // TODO: Finish the documentation for the following methods
121  std::vector<std::string> getTaskPortNames();
122  std::string getTaskPortName(const std::string& taskName);
123 
124  std::vector<std::string> getTaskNames();
125  std::shared_ptr<yarp::os::RpcClient> getTaskClient(const std::string& taskName);
126 
127  std::string getClientPortName() {return rpcClientPort_Name;}
128 
129 
130  bool parseInput(yarp::os::Bottle& input);
131 
132 
138  class InputCallback : public yarp::os::PortReader {
139  private:
140  ClientCommunications& coms;
141 
142  public:
144 
145  virtual bool read(yarp::os::ConnectionReader& connection);
146  };
147 
148 
149 private:
150  bool openServerConnections(double timeout=20.0);
151  bool openTaskConnections();
152 
153 private:
154  yarp::os::RpcClient rpcClientPort;
155  yarp::os::Port inputPort;
156 
157  std::string rpcClientPort_Name;
158  std::string inputPort_Name;
159 
160  int clientNumber;
161  static int CONTROLLER_CLIENT_COUNT;
162 
163  yarp::os::Network yarp;
164  yarp::os::Log yLog;
165 
166  TaskPortMap taskRpcClients;
167 
168  InputCallback inputCallback;
169 
170 
171 };
172 } // namespace ocra_recipes
173 #endif // CLIENT_COMMUNICATIONS_H
void parseMessage(yarp::os::Bottle &input)
virtual bool read(yarp::os::ConnectionReader &connection)
std::vector< std::string > getTaskTypes()
yarp::os::Bottle queryController(yarp::os::Bottle &requestBottle)
std::vector< std::string > getTaskNames()
#define DEFINE_CLASS_POINTER_TYPEDEFS(Class)
Definition: Macros.h:8
virtual bool read(yarp::os::ConnectionReader &connection)
bool parseInput(yarp::os::Bottle &input)
bool open(double timeout=20.0, bool connectToTasks=true)
std::vector< std::string > getTaskPortNames()
std::shared_ptr< yarp::os::RpcClient > getTaskClient(const std::string &taskName)
std::string getTaskPortName(const std::string &taskName)