RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpreadConnector.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project
4  *
5  * Copyright (C) 2010 by Sebastian Wrede <swrede at techfak dot uni-bielefeld dot de>
6  * Copyright (C) 2012 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
7  *
8  * This file may be licensed under the terms of the
9  * GNU Lesser General Public License Version 3 (the ``LGPL''),
10  * or (at your option) any later version.
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the LGPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the LGPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * The development of this software was supported by:
23  * CoR-Lab, Research Institute for Cognition and Robotics
24  * Bielefeld University
25  *
26  * ============================================================ */
27 
28 #pragma once
29 
30 #include <string>
31 #include <map>
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include <rsc/logging/Logger.h>
36 #include <rsc/misc/UUID.h>
37 
38 #include "../../Scope.h"
39 #include "../../QualityOfServiceSpec.h"
40 
41 #include "../Connector.h"
42 
43 #include "MembershipManager.h"
44 #include "SpreadConnection.h"
45 
46 #include "rsb/rsbexports.h"
47 
48 namespace rsb {
49 namespace spread {
50 
54 class RSB_EXPORT SpreadConnector {
55 public:
56  SpreadConnector(const std::string& host = defaultHost(),
57  unsigned int port = defaultPort());
58 
59  virtual ~SpreadConnector();
60 
61  void activate();
62  void deactivate();
63 
64  void setQualityOfServiceSpecs(const QualityOfServiceSpec& specs);
65 
66  void join(const std::string& name);
67  void leave(const std::string& name);
68 
72  void send(const SpreadMessage& msg);
73  void receive(SpreadMessagePtr msg);
74 
75  void init(const std::string& host, unsigned int port);
76 
77  SpreadConnectionPtr getConnection();
78 
79  SpreadMessage::QOS getMessageQoS() const;
80 
81  const std::vector<std::string>& makeGroupNames(const Scope& scope) const;
82  std::string makeGroupName(const Scope& scope) const;
83 
84 private:
85 
86  rsc::logging::LoggerPtr logger;
87 
88  rsc::misc::UUID id;
89 
90  volatile bool activated;
92 
94 
99 
100  typedef std::map<QualityOfServiceSpec::Ordering, std::map<
102 
107  static const QoSMap qosMapping;
108 
109  static QoSMap buildQoSMapping();
110 
111  mutable boost::shared_mutex groupNameCacheMutex;
112  typedef std::map<Scope, std::vector<std::string> > GroupNameCache;
114 
115 };
116 
117 typedef boost::shared_ptr<SpreadConnector> SpreadConnectorPtr;
118 
119 }
120 }