IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
TrackingBlock.cpp
Go to the documentation of this file.
1
/*
2
* TrackingBlock.cpp
3
*
4
* Created on: 15.01.2013
5
* Author: morgenro
6
*/
7
8
#include "
ibrdtn/data/TrackingBlock.h
"
9
#include "
ibrdtn/data/BundleString.h
"
10
11
namespace
dtn
12
{
13
namespace
data
14
{
15
const
dtn::data::block_t
TrackingBlock::BLOCK_TYPE
= 193;
16
17
dtn::data::Block
*
TrackingBlock::Factory::create
()
18
{
19
return
new
TrackingBlock
();
20
}
21
22
TrackingBlock::TrackingBlock
()
23
: dtn::data::
Block
(
TrackingBlock
::
BLOCK_TYPE
)
24
{
25
// set the replicate in every fragment bit
26
set
(
REPLICATE_IN_EVERY_FRAGMENT
,
true
);
27
}
28
29
TrackingBlock::~TrackingBlock
()
30
{
31
}
32
33
Length
TrackingBlock::getLength
()
const
34
{
35
Length
ret = 0;
36
37
// number of elements
38
dtn::data::Number
count(_entries.size());
39
ret += count.
getLength
();
40
41
for
(tracking_list::const_iterator iter = _entries.begin(); iter != _entries.end(); ++iter)
42
{
43
const
TrackingEntry
&entry = (*iter);
44
ret += entry.
getLength
();
45
}
46
47
return
ret;
48
}
49
50
std::ostream&
TrackingBlock::serialize
(std::ostream &stream,
Length
&)
const
51
{
52
// number of elements
53
dtn::data::Number
count(_entries.size());
54
stream << count;
55
56
for
(tracking_list::const_iterator iter = _entries.begin(); iter != _entries.end(); ++iter)
57
{
58
const
TrackingEntry
&entry = (*iter);
59
stream << entry;
60
}
61
62
return
stream;
63
}
64
65
std::istream&
TrackingBlock::deserialize
(std::istream &stream,
const
Length
&)
66
{
67
// number of elements
68
dtn::data::Number
count;
69
70
stream >> count;
71
72
for
(
Number
i = 0; i < count; ++i)
73
{
74
TrackingEntry
entry;
75
stream >> entry;
76
_entries.push_back(entry);
77
}
78
79
return
stream;
80
}
81
82
Length
TrackingBlock::getLength_strict
()
const
83
{
84
return
getLength
();
85
}
86
87
std::ostream&
TrackingBlock::serialize_strict
(std::ostream &stream,
Length
&length)
const
88
{
89
return
serialize
(stream, length);
90
}
91
92
const
TrackingBlock::tracking_list
&
TrackingBlock::getTrack
()
const
93
{
94
return
_entries;
95
}
96
97
void
TrackingBlock::append
(
const
dtn::data::EID
&eid)
98
{
99
TrackingEntry
entry(eid);
100
101
// include timestamp
102
entry.
setFlag
(
TrackingEntry::TIMESTAMP_PRESENT
,
true
);
103
104
// use default timestamp
105
//entry.timestamp.set();
106
107
_entries.push_back(entry);
108
}
109
110
TrackingBlock::TrackingEntry::TrackingEntry
()
111
{
112
}
113
114
TrackingBlock::TrackingEntry::TrackingEntry
(
const
dtn::data::EID
&eid)
115
: endpoint(eid)
116
{
117
}
118
119
TrackingBlock::TrackingEntry::~TrackingEntry
()
120
{
121
}
122
123
bool
TrackingBlock::TrackingEntry::getFlag
(
TrackingBlock::TrackingEntry::Flags
f)
const
124
{
125
return
flags.getBit(f);
126
}
127
128
void
TrackingBlock::TrackingEntry::setFlag
(
TrackingBlock::TrackingEntry::Flags
f,
bool
value)
129
{
130
flags.setBit(f, value);
131
}
132
133
Length
TrackingBlock::TrackingEntry::getLength
()
const
134
{
135
Length
ret = flags.getLength();
136
137
if
(getFlag(
TrackingEntry::TIMESTAMP_PRESENT
)) {
138
ret += timestamp.getLength();
139
}
140
141
ret +=
BundleString
(endpoint.getString()).
getLength
();
142
143
return
ret;
144
}
145
146
std::ostream&
operator<<
(std::ostream &stream,
const
TrackingBlock::TrackingEntry
&entry)
147
{
148
stream << entry.
flags
;
149
150
if
(entry.
getFlag
(
TrackingBlock::TrackingEntry::TIMESTAMP_PRESENT
)) {
151
stream << entry.
timestamp
;
152
}
153
154
dtn::data::BundleString
endpoint(entry.
endpoint
.
getString
());
155
stream << endpoint;
156
return
stream;
157
}
158
159
std::istream&
operator>>
(std::istream &stream,
TrackingBlock::TrackingEntry
&entry)
160
{
161
stream >> entry.
flags
;
162
163
if
(entry.
getFlag
(
TrackingBlock::TrackingEntry::TIMESTAMP_PRESENT
)) {
164
stream >> entry.
timestamp
;
165
}
166
167
BundleString
endpoint;
168
stream >> endpoint;
169
entry.
endpoint
=
dtn::data::EID
((std::string&)endpoint);
170
return
stream;
171
}
172
}
/* namespace data */
173
}
/* namespace dtn */
ibrdtn
ibrdtn
data
TrackingBlock.cpp
Generated on Thu Mar 27 2014 09:26:21 for IBR-DTNSuite by
1.8.4