All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Master.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 "msgs/msgs.hh"
28 #include "transport/Connection.hh"
29 
30 namespace gazebo
31 {
36  class Master
37  {
39  typedef std::map<unsigned int, transport::ConnectionPtr> Connection_M;
40 
41 
43  public: Master();
44 
46  public: virtual ~Master();
47 
50  public: void Init(uint16_t _port);
51 
53  public: void Run();
54 
56  public: void RunThread();
57 
59  public: void RunOnce();
60 
62  public: void Stop();
63 
65  public: void Fini();
66 
71  private: void ProcessMessage(const unsigned int _connectionIndex,
72  const std::string &_data);
73 
78  private: void OnRead(const unsigned int _connectionIndex,
79  const std::string &_data);
80 
83  private: void OnAccept(const transport::ConnectionPtr &_newConnection);
84 
88  private: msgs::Publish GetPublisher(const std::string &_topic);
89 
94  private: transport::ConnectionPtr FindConnection(const std::string &_host,
95  uint16_t _port);
96 
97 
101  private: void RemoveConnection(Connection_M::iterator _connIter);
102 
106  private: void RemovePublisher(const msgs::Publish _pub);
107 
111  private: void RemoveSubscriber(const msgs::Subscribe _sub);
112 
114  typedef std::list< std::pair<msgs::Publish, transport::ConnectionPtr> >
115  PubList;
116 
118  typedef std::list< std::pair<msgs::Subscribe, transport::ConnectionPtr> >
119  SubList;
120 
122  private: PubList publishers;
123 
125  private: SubList subscribers;
126 
128  private: Connection_M connections;
129 
131  private: std::list<std::string> worldNames;
132 
134  private: std::list<std::pair<unsigned int, std::string> > msgs;
135 
137  private: transport::Connection *connection;
138 
140  private: boost::thread *runThread;
141 
143  private: bool stop;
144 
146  private: boost::recursive_mutex *connectionMutex;
147 
149  private: boost::recursive_mutex *msgsMutex;
150  };
151 }
152 #endif