IBR-DTNSuite  0.12
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 
10 
11 namespace dtn
12 {
13  namespace data
14  {
16 
18  {
19  return new TrackingBlock();
20  }
21 
23  : dtn::data::Block(TrackingBlock::BLOCK_TYPE)
24  {
25  // set the replicate in every fragment bit
27  }
28 
30  {
31  }
32 
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 
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 
93  {
94  return _entries;
95  }
96 
98  {
99  TrackingEntry entry(eid);
100 
101  // include timestamp
103 
104  // use default timestamp
105  //entry.timestamp.set();
106 
107  _entries.push_back(entry);
108  }
109 
111  {
112  }
113 
115  : endpoint(eid)
116  {
117  }
118 
120  {
121  }
122 
124  {
125  return flags.getBit(f);
126  }
127 
129  {
130  flags.setBit(f, value);
131  }
132 
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 
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 
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 */