RSB  0.17.0
Bus.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project
4  *
5  * Copyright (C) 2011, 2012, 2015 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <string>
30 #include <map>
31 #include <list>
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include <boost/thread/recursive_mutex.hpp>
36 
37 #include <rsc/logging/Logger.h>
38 
39 #include "../../Event.h"
40 #include "../../Scope.h"
41 
42 #include "../../eventprocessing/Handler.h"
43 
44 #include "../../protocol/Notification.h"
45 
46 #include "../AsioServiceContext.h"
47 #include "BusConnection.h"
48 
49 #include "rsb/rsbexports.h"
50 
51 namespace rsb {
52 namespace transport {
53 namespace socket {
54 
56 typedef boost::shared_ptr<InConnector> InConnectorPtr;
57 
58 class ConnectorBase;
59 
75 class RSB_EXPORT Bus: public eventprocessing::Handler {
76 friend class BusConnection;
77 public:
78  Bus(AsioServiceContextPtr asioService,
79  bool tcpnodelay = false);
80  virtual ~Bus();
81 
82  virtual void addSink(InConnectorPtr sink);
83  virtual void removeSink(InConnector* sink);
84 
92  virtual void addConnection(BusConnectionPtr connection);
93 
100  virtual void removeConnection(BusConnectionPtr connection);
101 
102  virtual bool isTcpnodelay() const;
103 
104  virtual void handle(EventPtr event);
105 
106  virtual AsioServiceContextPtr getService() const;
107 
108  virtual void printContents(std::ostream& stream) const;
109 
110  virtual const std::string getTransportURL() const;
111 
112 protected:
113  typedef std::list<BusConnectionPtr> ConnectionList;
114 
115  ConnectionList getConnections() const;
116  boost::recursive_mutex& getConnectionLock();
117 
118  virtual void handleIncoming(EventPtr event,
119  BusConnectionPtr connection);
120 
121 private:
122  typedef std::list<boost::weak_ptr<InConnector> > SinkList;
123  typedef std::map<Scope, SinkList> SinkMap;
124 
125  rsc::logging::LoggerPtr logger;
126 
127  // the asio service this bus operates on. Storing this pointer keeps the
128  // service alive as long as this instance is alive
130 
131  ConnectionList connections;
132  boost::recursive_mutex connectionLock;
133 
134  SinkMap sinks;
135  boost::recursive_mutex connectorLock;
136 
138 
139 };
140 
141 }
142 }
143 }
rsc::logging::LoggerPtr logger
Definition: Bus.h:125
ConnectionList connections
Definition: Bus.h:131
boost::shared_ptr< InConnector > InConnectorPtr
Definition: Bus.h:55
Instances of this class provide access to a socket-based bus.
Definition: Bus.h:75
boost::shared_ptr< AsioServiceContext > AsioServiceContextPtr
boost::shared_ptr< BusConnection > BusConnectionPtr
std::list< boost::weak_ptr< InConnector > > SinkList
Definition: Bus.h:122
Instances of this class receive events from a bus that is accessed via a socket connection.
Definition: InConnector.h:61
This class is intended to be used as a base class for connector classes of the socket-based transport...
Definition: ConnectorBase.h:59
AsioServiceContextPtr asioService
Definition: Bus.h:129
std::map< Scope, SinkList > SinkMap
Definition: Bus.h:123
Instances of this class implement connections to a socket-based bus.
Definition: BusConnection.h:74
boost::recursive_mutex connectorLock
Definition: Bus.h:135
boost::recursive_mutex connectionLock
Definition: Bus.h:132
Implementations of this class can be used in contexts where an "event sink" is required.
Definition: Handler.h:48
boost::shared_ptr< Event > EventPtr
Definition: Event.h:264
std::list< BusConnectionPtr > ConnectionList
Definition: Bus.h:113