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 2011 Nate Koenig
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  public: Master();
40 
42  public: virtual ~Master();
43 
46  public: void Init(uint16_t _port);
47 
49  public: void Run();
50 
52  public: void RunThread();
53 
55  public: void RunOnce();
56 
58  public: void Stop();
59 
61  public: void Fini();
62 
67  private: void ProcessMessage(const unsigned int _connectionIndex,
68  const std::string &_data);
69 
74  private: void OnRead(const unsigned int _connectionIndex,
75  const std::string &_data);
76 
79  private: void OnAccept(const transport::ConnectionPtr &_newConnection);
80 
84  private: msgs::Publish GetPublisher(const std::string &_topic);
85 
90  private: transport::ConnectionPtr FindConnection(const std::string &_host,
91  uint16_t _port);
92 
93 
96  private: void RemoveConnection(unsigned int _index);
97 
101  private: void RemovePublisher(const msgs::Publish _pub);
102 
106  private: void RemoveSubscriber(const msgs::Subscribe _sub);
107 
109  typedef std::map<unsigned int, transport::ConnectionPtr> Connection_M;
110 
112  typedef std::list< std::pair<msgs::Publish, transport::ConnectionPtr> >
113  PubList;
114 
116  typedef std::list< std::pair<msgs::Subscribe, transport::ConnectionPtr> >
117  SubList;
118 
120  private: PubList publishers;
121 
123  private: SubList subscribers;
124 
126  private: Connection_M connections;
127 
129  private: std::list<std::string> worldNames;
130 
132  private: std::list<std::pair<unsigned int, std::string> > msgs;
133 
135  private: transport::Connection *connection;
136 
138  private: boost::thread *runThread;
139 
141  private: bool stop;
142 
144  private: boost::recursive_mutex *connectionMutex;
145 
147  private: boost::recursive_mutex *msgsMutex;
148  };
149 }
150 #endif