Master.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 
83  private: void SendSubscribers(const std::string &_topic,
84  const std::string &_buffer);
85 
90  private: void ProcessMessage(const unsigned int _connectionIndex,
91  const std::string &_data);
92 
97  private: void OnRead(const unsigned int _connectionIndex,
98  const std::string &_data);
99 
102  private: void OnAccept(transport::ConnectionPtr _newConnection);
103 
107  private: msgs::Publish GetPublisher(const std::string &_topic);
108 
113  private: transport::ConnectionPtr FindConnection(const std::string &_host,
114  uint16_t _port);
115 
119  private: void RemoveConnection(Connection_M::iterator _connIter);
120 
124  private: void RemovePublisher(const msgs::Publish _pub);
125 
129  private: void RemoveSubscriber(const msgs::Subscribe _sub);
130 
133  private: std::unique_ptr<MasterPrivate> dataPtr;
134  };
135 }
136 #endif
std::map< unsigned int, transport::ConnectionPtr > Connection_M
Definition: Master.hh:43
A manager that directs topic connections, enables each gazebo network client to locate one another fo...
Definition: Master.hh:39
boost::shared_ptr< Connection > ConnectionPtr
Definition: Connection.hh:50
std::list< std::pair< msgs::Subscribe, transport::ConnectionPtr > > SubList
Definition: Master.hh:53
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
std::list< std::pair< msgs::Publish, transport::ConnectionPtr > > PubList
Definition: Master.hh:48
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:59