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/debug/DebugUtils.h> 00021 #include <oasys/serialize/Serialize.h> 00022 #include <oasys/serialize/SerializableVector.h> 00023 #include <oasys/util/ScratchBuffer.h> 00024 00025 #include "BP_Local.h" 00026 #include "Dictionary.h" 00027 #include "contacts/Link.h" 00028 00029 namespace dtn { 00030 00031 class BlockProcessor; 00032 class BP_Local; 00033 00038 class BlockInfo : public oasys::SerializableObject { 00039 public: 00043 typedef oasys::ScratchBuffer<u_char*, 64> DataBuffer; 00044 00047 BlockInfo(BlockProcessor* owner, const BlockInfo* source = NULL); 00048 00050 BlockInfo(oasys::Builder& builder); 00051 00053 BlockInfo(const BlockInfo& bi); 00054 00058 virtual ~BlockInfo(); 00059 00063 typedef enum { 00064 LIST_NONE = 0x00, 00065 LIST_RECEIVED = 0x01, 00066 LIST_API = 0x02, 00067 LIST_EXT = 0x03, 00068 LIST_XMIT = 0x04 00069 } list_owner_t; 00070 00072 BlockProcessor* owner() const { return owner_; } 00073 const BlockInfo* source() const { return source_; } 00074 const EndpointIDVector& eid_list() const { return eid_list_; } 00075 const DataBuffer& contents() const { return contents_; } 00076 BP_Local* locals() const { return locals_.object(); } 00077 u_int32_t data_length() const { return data_length_; } 00078 u_int32_t data_offset() const { return data_offset_; } 00079 u_int32_t full_length() const { return (data_offset_ + 00080 data_length_); } 00081 u_char* data() const { return (contents_.buf() + 00082 data_offset_); } 00083 bool complete() const { return complete_; } 00084 bool reloaded() const { return reloaded_; } 00085 bool last_block() const; 00087 00089 void set_owner(BlockProcessor* o) { owner_ = o; } 00090 void set_eid_list(const EndpointIDVector& l) { eid_list_ = l; } 00091 void set_complete(bool t) { complete_ = t; } 00092 void set_data_length(u_int32_t l) { data_length_ = l; } 00093 void set_data_offset(u_int32_t o) { data_offset_ = o; } 00094 DataBuffer* writable_contents() { return &contents_; } 00095 void set_locals(BP_Local* l); 00096 void add_eid(EndpointID e) { eid_list_.push_back(e); } 00097 void set_reloaded(bool t) { reloaded_ = t; } 00099 00102 int type() const; 00103 u_int64_t flags() const; 00104 void set_flag(u_int64_t flag); 00106 00108 virtual void serialize(oasys::SerializeAction* action); 00109 00110 protected: 00111 BlockProcessor* owner_; 00112 u_int16_t owner_type_; 00113 const BlockInfo* source_; 00114 EndpointIDVector eid_list_; 00115 DataBuffer contents_; 00116 00117 BP_LocalRef locals_; 00118 u_int32_t data_length_; 00119 u_int32_t data_offset_; 00120 bool complete_; 00121 bool reloaded_; 00122 00123 00124 }; 00125 00129 class BlockInfoVec : public oasys::SerializableVector<BlockInfo> { 00130 public: 00134 BlockInfoVec(); 00135 00143 BlockInfo* append_block(BlockProcessor* owner, 00144 const BlockInfo* source = NULL); 00145 00151 const BlockInfo* find_block(u_int8_t type) const; 00152 00156 bool has_block(u_int8_t type) const { return find_block(type) != NULL; } 00157 00161 Dictionary* dict() { return &dict_; } 00162 00167 u_int32_t error_major() const { return error_major_; } 00168 u_int32_t error_minor() const { return error_minor_; } 00169 u_int32_t error_debug() const { return error_debug_; } 00170 00175 void set_error_major(u_int32_t e) { error_major_ = e; } 00176 void set_error_minor(u_int32_t e) { error_minor_ = e; } 00177 void set_error_debug(u_int32_t e) { error_debug_ = e; } 00178 00179 protected: 00183 u_int32_t error_major_; 00184 u_int32_t error_minor_; 00185 u_int32_t error_debug_; 00186 00190 Dictionary dict_; 00191 00195 NO_ASSIGN_COPY(BlockInfoVec); 00196 }; 00197 00201 class LinkBlockSet { 00202 public: 00203 LinkBlockSet(oasys::Lock* lock) : lock_(lock) {} 00204 00208 virtual ~LinkBlockSet(); 00209 00215 BlockInfoVec* create_blocks(const LinkRef& link); 00216 00222 BlockInfoVec* find_blocks(const LinkRef& link) const; 00223 00227 void delete_blocks(const LinkRef& link); 00228 00229 protected: 00237 struct Entry { 00238 Entry(const LinkRef& link); 00239 00240 BlockInfoVec* blocks_; 00241 LinkRef link_; 00242 }; 00243 00244 typedef std::vector<Entry> Vector; 00245 typedef std::vector<Entry>::iterator iterator; 00246 typedef std::vector<Entry>::const_iterator const_iterator; 00247 Vector entries_; 00248 oasys::Lock* lock_; 00249 00253 NO_ASSIGN_COPY(LinkBlockSet); 00254 }; 00255 00256 } // namespace dtn 00257 00258 #endif /* _BUNDLEBLOCKINFO_H_ */