IBR-DTNSuite  0.10
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  : AdministrativeBlock(16), status(0), reasoncode(0),
35  fragment_length(0), 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  (*stream).put(_admfield);
53  (*stream).put(status);
54  (*stream).put(reasoncode);
55 
56  if ( refsFragment() )
57  {
58  (*stream) << bundleid.offset;
59  (*stream) << fragment_length;
60  }
61 
63  (*stream) << timeof_receipt;
64 
66  (*stream) << timeof_custodyaccept;
67 
69  (*stream) << timeof_forwarding;
70 
72  (*stream) << timeof_delivery;
73 
75  (*stream) << timeof_deletion;
76 
77  (*stream) << bundleid.timestamp;
78  (*stream) << bundleid.sequencenumber;
79  (*stream) << BundleString(bundleid.source.getString());
80  }
81 
83  {
84  ibrcommon::BLOB::Reference r = p.getBLOB();
86 
87  (*stream).get(_admfield);
88 
89  // check type field
90  if ((_admfield >> 4) != 1) throw WrongRecordException();
91 
92  (*stream).get(status);
93  (*stream).get(reasoncode);
94 
95  if ( refsFragment() )
96  {
97  bundleid.fragment = true;
98 
99  (*stream) >> bundleid.offset;
100  (*stream) >> fragment_length;
101  }
102 
103  if (status & RECEIPT_OF_BUNDLE)
104  (*stream) >> timeof_receipt;
105 
106  if (status & CUSTODY_ACCEPTANCE_OF_BUNDLE)
107  (*stream) >> timeof_custodyaccept;
108 
109  if (status & FORWARDING_OF_BUNDLE)
110  (*stream) >> timeof_forwarding;
111 
112  if (status & DELIVERY_OF_BUNDLE)
113  (*stream) >> timeof_delivery;
114 
115  if (status & DELETION_OF_BUNDLE)
116  (*stream) >> timeof_deletion;
117 
118  (*stream) >> bundleid.timestamp;
119  (*stream) >> bundleid.sequencenumber;
120 
121  BundleString source;
122  (*stream) >> source;
123  bundleid.source = EID(source);
124  }
125 
126  }
127 }