IBR-DTNSuite  0.10
Block.h
Go to the documentation of this file.
1 /*
2  * Block.h
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 #ifndef BLOCK_H_
23 #define BLOCK_H_
24 
25 #include "ibrdtn/data/EID.h"
26 #include "ibrdtn/data/Exceptions.h"
27 #include "ibrdtn/data/Number.h"
28 #include "ibrdtn/data/Dictionary.h"
29 #include "ibrdtn/data/Serializer.h"
30 #include <ibrcommon/Exceptions.h>
31 #include <list>
32 
33 namespace dtn
34 {
35  namespace data
36  {
37  class BundleBuilder;
38 
39  class Block
40  {
41  friend class BundleBuilder;
42 
43  public:
44  enum ProcFlags
45  {
46  REPLICATE_IN_EVERY_FRAGMENT = 1, // 0 - Block must be replicated in every fragment.
47  TRANSMIT_STATUSREPORT_IF_NOT_PROCESSED = 1 << 0x01, // 1 - Transmit status report if block can't be processed.
48  DELETE_BUNDLE_IF_NOT_PROCESSED = 1 << 0x02, // 2 - Delete bundle if block can't be processed.
49  LAST_BLOCK = 1 << 0x03, // 3 - Last block.
50  DISCARD_IF_NOT_PROCESSED = 1 << 0x04, // 4 - Discard block if it can't be processed.
51  FORWARDED_WITHOUT_PROCESSED = 1 << 0x05, // 5 - Block was forwarded without being processed.
52  BLOCK_CONTAINS_EIDS = 1 << 0x06 // 6 - Block contains an EID-reference field.
53  };
54 
55  typedef std::list<dtn::data::EID> eid_list;
56 
57  virtual ~Block();
58 
62  Block& operator=(const Block &block);
63 
67  bool operator==(const block_t &id) const;
68 
69  virtual void addEID(const dtn::data::EID &eid);
70  virtual void clearEIDs();
71  virtual const eid_list& getEIDList() const;
72 
73  const block_t& getType() const { return _blocktype; }
74 
75  void set(ProcFlags flag, const bool &value);
76  bool get(ProcFlags flag) const;
78 
84  virtual std::ostream &serialize(std::ostream &stream, Length &length) const = 0;
85 
91  virtual std::istream &deserialize(std::istream &stream, const Length &length) = 0;
92 
97  virtual Length getLength() const = 0;
98 
102  virtual Length getLength_strict() const;
103 
109  virtual std::ostream &serialize_strict(std::ostream &stream, Length &length) const;
110 
111  protected:
116  Block(block_t blocktype);
117 
118  // block type of this block
120 
121  // the list of EID references embedded in this block
123 
124  private:
125  // block processing flags
126  Bitset<ProcFlags> _procflags;
127  };
128  }
129 }
130 
131 #endif /* BLOCK_H_ */