IBR-DTNSuite  0.12
DiscoveryService.cpp
Go to the documentation of this file.
1 /*
2  * DiscoveryService.cpp
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "net/DiscoveryService.h"
23 #include "ibrdtn/data/SDNV.h"
25 #include <string>
26 
27 using namespace dtn::data;
28 
29 namespace dtn
30 {
31  namespace net
32  {
33  DiscoveryService::DiscoveryService()
34  : _service_protocol(dtn::core::Node::CONN_UNDEFINED)
35  {
36  }
37 
38  DiscoveryService::DiscoveryService(const dtn::core::Node::Protocol p, const std::string &parameters)
39  : _service_protocol(p), _service_name(asTag(p)), _service_parameters(parameters)
40  {
41  }
42 
43  DiscoveryService::DiscoveryService(const std::string &name, const std::string &parameters)
44  : _service_protocol(asProtocol(name)), _service_name(name), _service_parameters(parameters)
45  {
46  }
47 
49  {
50  }
51 
53  {
56 
57  return name.getLength() + parameters.getLength();
58  }
59 
61  {
62  return _service_protocol;
63  }
64 
65  const std::string& DiscoveryService::getName() const
66  {
67  return _service_name;
68  }
69 
70  const std::string& DiscoveryService::getParameters() const
71  {
72  return _service_parameters;
73  }
74 
75  void DiscoveryService::update(const std::string &parameters)
76  {
77  _service_parameters = parameters;
78  }
79 
81  {
82  if (tag == "undefined") {
84  }
85  else if (tag == "udpcl") {
87  }
88  else if (tag == "tcpcl") {
90  }
91  else if (tag == "lowpancl") {
93  }
94  else if (tag == "bt") {
96  }
97  else if (tag == "http") {
99  }
100  else if (tag == "file") {
102  }
103  else if (tag == "dgram:udp") {
105  }
106  else if (tag == "dgram:eth") {
108  }
109  else if (tag == "dgram:lowpan") {
111  }
112  else if (tag == "p2p:wifi") {
114  }
115  else if (tag == "p2p:bt") {
117  }
118  else if (tag == "email") {
120  }
121 
123  }
124 
126  {
127  switch (proto)
128  {
130  return "unsupported";
131 
133  return "undefined";
134 
136  return "udpcl";
137 
139  return "tcpcl";
140 
142  return "lowpancl";
143 
145  return "bt";
146 
148  return "http";
149 
151  return "file";
152 
154  return "dgram:udp";
155 
157  return "dgram:eth";
158 
160  return "dgram:lowpan";
161 
163  return "p2p:wifi";
164 
166  return "p2p:bt";
167 
169  return "email";
170  }
171 
172  return "unknown";
173  }
174 
175  std::ostream &operator<<(std::ostream &stream, const DiscoveryService &service)
176  {
177  BundleString name(service._service_name);
178  BundleString parameters(service._service_parameters);
179 
180  stream << name << parameters;
181 
182  return stream;
183  }
184 
185  std::istream &operator>>(std::istream &stream, DiscoveryService &service)
186  {
187  BundleString name;
188  BundleString parameters;
189 
190  stream >> name >> parameters;
191 
192  service._service_protocol = DiscoveryService::asProtocol((const std::string&)name);
193  service._service_name = (const std::string&)name;
194  service._service_parameters = (const std::string&)parameters;
195 
196  return stream;
197  }
198  }
199 }