RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpreadMessage.cpp
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  *
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 #include "SpreadMessage.h"
28 
29 #include <stdexcept>
30 
31 #include <string.h>
32 
33 #include <rsc/logging/Logger.h>
34 
35 #include <sp.h>
36 
37 using namespace std;
38 using namespace rsc::logging;
39 
40 namespace {
41 LoggerPtr logger(Logger::getLogger("rsb.spread.SpreadMessage"));
42 }
43 
44 namespace rsb {
45 namespace spread {
46 
47 SpreadMessage::SpreadMessage() :
48  type(OTHER), qos(UNRELIABLE) {
49 }
50 
52  type(mt), qos(UNRELIABLE) {
53 }
54 
55 SpreadMessage::SpreadMessage(const string& d) :
56  data(d), type(OTHER), qos(UNRELIABLE) {
57 }
58 
59 SpreadMessage::SpreadMessage(const char* buf) :
60  data(buf), type(OTHER), qos(UNRELIABLE) {
61 }
62 
64 }
65 
66 void SpreadMessage::setData(const std::string& doc) {
67  data = doc;
68 }
69 
70 void SpreadMessage::setData(const char* buf) {
71  data = string(buf);
72 }
73 
75  return data;
76 }
77 
78 const char* SpreadMessage::getData() const {
79  return data.c_str();
80 }
81 
83  return data.length();
84 }
85 
87  type = mt;
88 }
89 
91  return type;
92 }
93 
94 void SpreadMessage::addGroup(const std::string& name) {
95  if (strlen(name.c_str()) > MAX_GROUP_NAME - 1) {
96  throw invalid_argument(
97  "Group name '" + name + "' is too long for spread.");
98  }
99  groups.push_back(name);
100 }
101 
102 unsigned int SpreadMessage::getGroupCount() const {
103  return groups.size();
104 }
105 
106 list<string>::const_iterator SpreadMessage::getGroupsBegin() const {
107  return groups.begin();
108 }
109 
110 list<string>::const_iterator SpreadMessage::getGroupsEnd() const {
111  return groups.end();
112 }
113 
115  return qos;
116 }
117 
118 void SpreadMessage::setQOS(const QOS& qos) {
119  this->qos = qos;
120 }
121 
123  type = OTHER;
124  data.clear();
125  qos = UNRELIABLE;
126  groups.clear();
127 }
128 
129 }
130 }