IBR-DTNSuite  0.12
StatusReportBlock.cpp
Go to the documentation of this file.
1 /*
2  * StatusReportBlock.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 
23 #include "ibrdtn/data/Number.h"
26 #include <stdlib.h>
27 #include <sstream>
28 
29 namespace dtn
30 {
31  namespace data
32  {
34  : status(0), reasoncode(0),
35  timeof_receipt(), timeof_custodyaccept(),
36  timeof_forwarding(), timeof_delivery(), timeof_deletion()
37  {
38  }
39 
41  {
42  }
43 
45  {
48 
49  // clear the whole data first
50  stream.clear();
51 
52  char admfield = bundleid.isFragment() ? 17 : 16;
53 
54  (*stream).put(admfield);
55  (*stream).put(status);
56  (*stream).put(reasoncode);
57 
58  if ( bundleid.isFragment() )
59  {
60  (*stream) << bundleid.fragmentoffset;
62  }
63 
65  (*stream) << timeof_receipt;
66 
68  (*stream) << timeof_custodyaccept;
69 
71  (*stream) << timeof_forwarding;
72 
74  (*stream) << timeof_delivery;
75 
77  (*stream) << timeof_deletion;
78 
79  (*stream) << bundleid.timestamp;
80  (*stream) << bundleid.sequencenumber;
81  (*stream) << BundleString(bundleid.source.getString());
82  }
83 
85  {
86  ibrcommon::BLOB::Reference r = p.getBLOB();
88 
89  char admfield;
90  (*stream).get(admfield);
91 
92  // check type field
93  if ((admfield >> 4) != 1) throw WrongRecordException();
94 
95  (*stream).get(status);
96  (*stream).get(reasoncode);
97 
98  if ( admfield & 0x01 )
99  {
100  bundleid.setFragment(true);
101 
102  (*stream) >> bundleid.fragmentoffset;
103 
104  dtn::data::Number tmp;
105  (*stream) >> tmp;
106  bundleid.setPayloadLength(tmp.get<dtn::data::Length>());
107  }
108 
109  if (status & RECEIPT_OF_BUNDLE)
110  (*stream) >> timeof_receipt;
111 
112  if (status & CUSTODY_ACCEPTANCE_OF_BUNDLE)
113  (*stream) >> timeof_custodyaccept;
114 
115  if (status & FORWARDING_OF_BUNDLE)
116  (*stream) >> timeof_forwarding;
117 
118  if (status & DELIVERY_OF_BUNDLE)
119  (*stream) >> timeof_delivery;
120 
121  if (status & DELETION_OF_BUNDLE)
122  (*stream) >> timeof_deletion;
123 
124  (*stream) >> bundleid.timestamp;
125  (*stream) >> bundleid.sequencenumber;
126 
127  BundleString source;
128  (*stream) >> source;
129  bundleid.source = EID(source);
130  }
131 
132  }
133 }