RSB  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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 "BusConnection.h"
47 #include "ConnectorBase.h"
48 #include "InConnector.h"
49 
50 #include "rsb/rsbexports.h"
51 
52 namespace rsb {
53 namespace transport {
54 namespace socket {
55 
71 class RSB_EXPORT Bus: public eventprocessing::Handler,
72  public boost::enable_shared_from_this<Bus> {
73 friend class BusConnection;
74 public:
75  Bus(boost::asio::io_service& service, bool tcpnodelay = false);
76  virtual ~Bus();
77 
78  void addSink(InConnectorPtr sink);
79  void removeSink(InConnector* sink);
80 
81  void addConnector(ConnectorBase* connector);
82  void removeConnector(ConnectorBase* connector);
83 
91  void addConnection(BusConnectionPtr connection);
92 
99  void removeConnection(BusConnectionPtr connection);
100 
101  bool isTcpnodelay() const;
102 
103  void handle(EventPtr event);
104 protected:
105  typedef std::list<BusConnectionPtr> ConnectionList;
106 
107  ConnectionList getConnections() const;
108  boost::recursive_mutex& getConnectionLock();
109 
110  virtual void handleIncoming(EventPtr event,
111  BusConnectionPtr connection);
112 
113  virtual void suicide();
114 private:
115  typedef std::list<ConnectorBase*> ConnectorList;
116 
117  typedef std::list<boost::weak_ptr<InConnector> > SinkList;
118  typedef std::map<Scope, SinkList> SinkMap;
119 
120  rsc::logging::LoggerPtr logger;
121 
122  boost::asio::io_service& service;
123 
125  boost::recursive_mutex connectionLock;
126 
129  boost::recursive_mutex connectorLock;
130 
132 
133  void printContents(std::ostream& stream) const;
134 };
135 
136 }
137 }
138 }
rsc::logging::LoggerPtr logger
Definition: Bus.h:120
boost::shared_ptr< InConnector > InConnectorPtr
Definition: InConnector.h:87
ConnectionList connections
Definition: Bus.h:124
Instances of this class provide access to a socket-based bus.
Definition: Bus.h:71
boost::shared_ptr< BusConnection > BusConnectionPtr
std::list< boost::weak_ptr< InConnector > > SinkList
Definition: Bus.h:117
ConnectorList connectors
Definition: Bus.h:127
Instances of this class receive events from a bus that is accessed via a socket connection.
Definition: InConnector.h:60
std::list< ConnectorBase * > ConnectorList
Definition: Bus.h:115
This class is intended to be used as a base class for connector classes of the socket-based transport...
Definition: ConnectorBase.h:58
std::map< Scope, SinkList > SinkMap
Definition: Bus.h:118
Instances of this class implement connections to a socket-based bus.
Definition: BusConnection.h:74
boost::recursive_mutex connectorLock
Definition: Bus.h:129
boost::asio::io_service & service
Definition: Bus.h:122
boost::recursive_mutex connectionLock
Definition: Bus.h:125
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:251
std::list< BusConnectionPtr > ConnectionList
Definition: Bus.h:105