Master.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _MASTER_HH_
18 #define _MASTER_HH_
19 
20 #include <string>
21 #include <list>
22 #include <deque>
23 #include <utility>
24 #include <map>
25 #include <boost/shared_ptr.hpp>
26 
27 #include "gazebo/msgs/msgs.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  // Forward declare private data class
34  struct MasterPrivate;
35 
40  {
42  public: typedef
43  std::map<unsigned int, transport::ConnectionPtr> Connection_M;
44 
46  public: typedef
47  std::list< std::pair<msgs::Publish, transport::ConnectionPtr> >
49 
51  public: typedef
52  std::list< std::pair<msgs::Subscribe, transport::ConnectionPtr> >
54 
56  public: Master();
57 
59  public: virtual ~Master();
60 
63  public: void Init(uint16_t _port);
64 
66  public: void Run();
67 
69  public: void RunThread();
70 
72  public: void RunOnce();
73 
75  public: void Stop();
76 
78  public: void Fini();
79 
84  private: void ProcessMessage(const unsigned int _connectionIndex,
85  const std::string &_data);
86 
91  private: void OnRead(const unsigned int _connectionIndex,
92  const std::string &_data);
93 
96  private: void OnAccept(transport::ConnectionPtr _newConnection);
97 
101  private: msgs::Publish GetPublisher(const std::string &_topic);
102 
107  private: transport::ConnectionPtr FindConnection(const std::string &_host,
108  uint16_t _port);
109 
113  private: void RemoveConnection(Connection_M::iterator _connIter);
114 
118  private: void RemovePublisher(const msgs::Publish _pub);
119 
123  private: void RemoveSubscriber(const msgs::Subscribe _sub);
124 
127  private: std::unique_ptr<MasterPrivate> dataPtr;
128  };
129 }
130 #endif
A manager that directs topic connections, enables each gazebo network client to locate one another fo...
Definition: Master.hh:39
std::list< std::pair< msgs::Subscribe, transport::ConnectionPtr > > SubList
Definition: Master.hh:53
boost::shared_ptr< Connection > ConnectionPtr
Definition: Connection.hh:50
std::list< std::pair< msgs::Publish, transport::ConnectionPtr > > PubList
Definition: Master.hh:48
std::map< unsigned int, transport::ConnectionPtr > Connection_M
Definition: Master.hh:43
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:59