IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
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
"
24
#include "
ibrdtn/data/BundleString.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 ¶meters)
39
: _service_protocol(p), _service_name(asTag(p)), _service_parameters(parameters)
40
{
41
}
42
43
DiscoveryService::DiscoveryService
(
const
std::string &name,
const
std::string ¶meters)
44
: _service_protocol(asProtocol(name)), _service_name(name), _service_parameters(parameters)
45
{
46
}
47
48
DiscoveryService::~DiscoveryService
()
49
{
50
}
51
52
dtn::data::Length
DiscoveryService::getLength
()
const
53
{
54
BundleString
name(
_service_name
);
55
BundleString
parameters(
_service_parameters
);
56
57
return
name.
getLength
() + parameters.
getLength
();
58
}
59
60
dtn::core::Node::Protocol
DiscoveryService::getProtocol
()
const
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 ¶meters)
76
{
77
_service_parameters
= parameters;
78
}
79
80
dtn::core::Node::Protocol
DiscoveryService::asProtocol
(
const
std::string &tag)
81
{
82
if
(tag ==
"undefined"
) {
83
return
dtn::core::Node::CONN_UNDEFINED
;
84
}
85
else
if
(tag ==
"udpcl"
) {
86
return
dtn::core::Node::CONN_UDPIP
;
87
}
88
else
if
(tag ==
"tcpcl"
) {
89
return
dtn::core::Node::CONN_TCPIP
;
90
}
91
else
if
(tag ==
"lowpancl"
) {
92
return
dtn::core::Node::CONN_LOWPAN
;
93
}
94
else
if
(tag ==
"bt"
) {
95
return
dtn::core::Node::CONN_BLUETOOTH
;
96
}
97
else
if
(tag ==
"http"
) {
98
return
dtn::core::Node::CONN_HTTP
;
99
}
100
else
if
(tag ==
"file"
) {
101
return
dtn::core::Node::CONN_FILE
;
102
}
103
else
if
(tag ==
"dgram:udp"
) {
104
return
dtn::core::Node::CONN_DGRAM_UDP
;
105
}
106
else
if
(tag ==
"dgram:eth"
) {
107
return
dtn::core::Node::CONN_DGRAM_ETHERNET
;
108
}
109
else
if
(tag ==
"dgram:lowpan"
) {
110
return
dtn::core::Node::CONN_DGRAM_LOWPAN
;
111
}
112
else
if
(tag ==
"p2p:wifi"
) {
113
return
dtn::core::Node::CONN_P2P_WIFI
;
114
}
115
else
if
(tag ==
"p2p:bt"
) {
116
return
dtn::core::Node::CONN_P2P_BT
;
117
}
118
else
if
(tag ==
"email"
) {
119
return
dtn::core::Node::CONN_EMAIL
;
120
}
121
122
return
dtn::core::Node::CONN_UNSUPPORTED
;
123
}
124
125
std::string
DiscoveryService::asTag
(
const
dtn::core::Node::Protocol
proto)
126
{
127
switch
(proto)
128
{
129
case
dtn::core::Node::CONN_UNSUPPORTED
:
130
return
"unsupported"
;
131
132
case
dtn::core::Node::CONN_UNDEFINED
:
133
return
"undefined"
;
134
135
case
dtn::core::Node::CONN_UDPIP
:
136
return
"udpcl"
;
137
138
case
dtn::core::Node::CONN_TCPIP
:
139
return
"tcpcl"
;
140
141
case
dtn::core::Node::CONN_LOWPAN
:
142
return
"lowpancl"
;
143
144
case
dtn::core::Node::CONN_BLUETOOTH
:
145
return
"bt"
;
146
147
case
dtn::core::Node::CONN_HTTP
:
148
return
"http"
;
149
150
case
dtn::core::Node::CONN_FILE
:
151
return
"file"
;
152
153
case
dtn::core::Node::CONN_DGRAM_UDP
:
154
return
"dgram:udp"
;
155
156
case
dtn::core::Node::CONN_DGRAM_ETHERNET
:
157
return
"dgram:eth"
;
158
159
case
dtn::core::Node::CONN_DGRAM_LOWPAN
:
160
return
"dgram:lowpan"
;
161
162
case
dtn::core::Node::CONN_P2P_WIFI
:
163
return
"p2p:wifi"
;
164
165
case
dtn::core::Node::CONN_P2P_BT
:
166
return
"p2p:bt"
;
167
168
case
dtn::core::Node::CONN_EMAIL
:
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
}
daemon
src
net
DiscoveryService.cpp
Generated on Thu Mar 27 2014 09:26:20 for IBR-DTNSuite by
1.8.4