00001 /* 00002 * Copyright 2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _BUNDLEBLOCKINFO_H_ 00018 #define _BUNDLEBLOCKINFO_H_ 00019 00020 #include <oasys/serialize/Serialize.h> 00021 #include <oasys/serialize/SerializableVector.h> 00022 #include <oasys/util/ScratchBuffer.h> 00023 00024 namespace dtn { 00025 00026 class BlockProcessor; 00027 class Link; 00028 00033 class BlockInfo : public oasys::SerializableObject { 00034 public: 00038 typedef oasys::ScratchBuffer<u_char*, 64> DataBuffer; 00039 00042 BlockInfo(BlockProcessor* owner, const BlockInfo* source = NULL); 00043 00045 BlockInfo(oasys::Builder& builder); 00046 00048 BlockProcessor* owner() const { return owner_; } 00049 const BlockInfo* source() const { return source_; } 00050 const DataBuffer& contents() const { return contents_; } 00051 u_int32_t data_length() const { return data_length_; } 00052 u_int32_t data_offset() const { return data_offset_; } 00053 u_int32_t full_length() const { return data_offset_ + data_length_; } 00054 u_char* data() const { return contents_.buf() + data_offset_; } 00055 bool complete() const { return complete_; } 00056 bool primary_block() const; 00057 bool payload_block() const; 00058 bool last_block() const; 00060 00062 void set_complete(bool t) { complete_ = t; } 00063 void set_data_length(u_int32_t l) { data_length_ = l; } 00064 void set_data_offset(u_int32_t o) { data_offset_ = o; } 00065 DataBuffer* writable_contents() { return &contents_; } 00067 00070 u_int8_t type() const; 00071 u_int8_t flags() const; 00072 void set_flag(u_int8_t flag); 00074 00076 virtual void serialize(oasys::SerializeAction* action); 00077 00078 protected: 00079 BlockProcessor* owner_; 00080 u_int16_t owner_type_; 00081 const BlockInfo* source_; 00082 DataBuffer contents_; 00083 00084 u_int32_t data_length_; 00085 u_int32_t data_offset_; 00086 bool complete_; 00087 }; 00088 00092 class BlockInfoVec : public oasys::SerializableVector<BlockInfo> { 00093 public: 00099 const BlockInfo* find_block(u_int8_t type) const; 00100 00104 bool has_block(u_int8_t type) const { return find_block(type) != NULL; } 00105 }; 00106 00110 class LinkBlockSet { 00111 public: 00115 virtual ~LinkBlockSet(); 00116 00122 BlockInfoVec* create_blocks(Link* link); 00123 00129 BlockInfoVec* find_blocks(Link* link); 00130 00134 void delete_blocks(Link* link); 00135 00136 protected: 00144 struct Entry { 00145 Entry(Link* link); 00146 00147 BlockInfoVec* blocks_; 00148 Link* link_; 00149 }; 00150 00151 typedef std::vector<Entry> Vector; 00152 typedef std::vector<Entry>::iterator iterator; 00153 Vector entries_; 00154 }; 00155 00156 } // namespace dtn 00157 00158 #endif /* _BUNDLEBLOCKINFO_H_ */