00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _METADATA_BLOCK_H_
00023 #define _METADATA_BLOCK_H_
00024
00025 #include <oasys/thread/Mutex.h>
00026
00027 #include "BlockInfo.h"
00028 #include "BlockProcessor.h"
00029
00030 namespace dtn {
00031
00035 class MetadataBlock : public BP_Local, public oasys::SerializableObject {
00036 public:
00037
00038
00039 MetadataBlock(): lock_("MetadataBlock"),
00040 id_(MetadataBlock::get_next_index()),
00041 block_(NULL), generated_(false), error_(false),
00042 source_id_(0), source_(false), flags_(0),
00043 ontology_(0), metadata_(NULL), metadata_len_(0) {}
00044
00045 MetadataBlock(BlockInfo *block): lock_("MetadataBlock"),
00046 id_(MetadataBlock::get_next_index()),
00047 block_(block), generated_(false), error_(false),
00048 source_id_(0), source_(false), flags_(0),
00049 ontology_(0), metadata_(NULL), metadata_len_(0) {}
00050
00051 MetadataBlock(u_int64_t type, u_char* buf, u_int32_t len);
00052
00053 MetadataBlock(unsigned int source_id, u_int64_t type,
00054 u_char* buf, u_int32_t len);
00055
00056 MetadataBlock(oasys::Builder& builder): lock_("MetadataBlock"),
00057 id_(MetadataBlock::get_next_index()),
00058 block_(NULL), generated_(false), error_(false),
00059 source_id_(0), source_(false), flags_(0),
00060 ontology_(0), metadata_(NULL), metadata_len_(0)
00061 { (void)builder; }
00062
00063 MetadataBlock(const MetadataBlock& copy);
00064
00065
00066 ~MetadataBlock();
00067
00068
00069 unsigned int id() const { return id_; }
00070 bool generated() const { return generated_; }
00071 bool error() const { return error_; }
00072 unsigned int source_id() const { return source_id_; }
00073 bool source() const { return source_; }
00074 u_int64_t flags() const { return flags_; }
00075 u_int64_t ontology() const { return ontology_; }
00076 u_char * metadata() const { return metadata_; }
00077 u_int32_t metadata_len() const { return metadata_len_; }
00078
00079 oasys::Lock* lock() { return &lock_; }
00080
00081
00082 void set_flags(u_int64_t flags);
00083 void set_block_error() { error_ = true; }
00084 void set_ontology(u_int64_t ontology) { ontology_ = ontology; }
00085 void set_metadata(u_char *buf, u_int32_t len);
00086
00094 bool remove_outgoing_metadata(const LinkRef& link);
00095
00102 bool modify_outgoing_metadata(const LinkRef& link,
00103 u_char* buf, u_int32_t len);
00104
00109 bool metadata_removed(const LinkRef& link);
00110
00115 bool metadata_modified(const LinkRef& link);
00116
00122 bool metadata_modified(const LinkRef& link, u_char** buf, u_int32_t& len);
00123
00127 void delete_outgoing_metadata(const LinkRef& link);
00128
00130 virtual void serialize(oasys::SerializeAction* action) { (void)action; }
00131
00132 void operator=(const MetadataBlock& copy);
00133
00134 static unsigned int get_next_index() { return index_++; }
00135
00136 private:
00137 oasys::Mutex lock_;
00138
00139 unsigned int id_;
00140 BlockInfo * block_;
00141
00142 bool generated_;
00143
00144
00145
00146 bool error_;
00147
00148
00149 unsigned int source_id_;
00150 bool source_;
00151
00152
00153
00154 u_int64_t flags_;
00155
00156
00157 u_int64_t ontology_;
00158 u_char * metadata_;
00159 u_int32_t metadata_len_;
00160
00161 class OutgoingMetadata {
00162 public:
00163
00164 OutgoingMetadata(const LinkRef& link):
00165 link_(link.object(), "OutgoingMetadata"), remove_(true),
00166 metadata_(NULL), metadata_len_(0) {}
00167 OutgoingMetadata(const LinkRef& link, u_char* buf, u_int32_t len);
00168 OutgoingMetadata(const OutgoingMetadata& copy);
00169
00170
00171 ~OutgoingMetadata();
00172
00173 void operator=(const OutgoingMetadata& copy);
00174
00175
00176 const LinkRef& link() const { return link_; }
00177 bool remove() const { return remove_; }
00178 u_char * metadata() const { return metadata_; }
00179 u_int32_t metadata_len() const { return metadata_len_; }
00180
00181 private:
00182 LinkRef link_;
00183 bool remove_;
00184 u_char * metadata_;
00185 u_int32_t metadata_len_;
00186 };
00187
00188 std::vector<OutgoingMetadata> outgoing_metadata_;
00189
00190 OutgoingMetadata* find_outgoing_metadata(const LinkRef& link);
00191 bool has_outgoing_metadata(const LinkRef& link)
00192 { return (find_outgoing_metadata(link) != NULL); }
00193
00194 static unsigned int index_;
00195 };
00196
00200 typedef oasys::Ref<MetadataBlock> MetadataBlockRef;
00201
00205 class MetadataVec : public std::vector<MetadataBlockRef> {
00206 public:
00207 MetadataVec(const std::string& name) : name_(name) {}
00208
00213 void push_back(MetadataBlock* block) {
00214 std::vector<MetadataBlockRef>::
00215 push_back(MetadataBlockRef(block, name_.c_str()));
00216 }
00217
00218 protected:
00219 std::string name_;
00220 };
00221
00226 class LinkMetadataSet {
00227 public:
00228
00229 virtual ~LinkMetadataSet();
00230
00231 MetadataVec* create_blocks(const LinkRef& link);
00232 MetadataVec* find_blocks(const LinkRef& link) const;
00233 void delete_blocks(const LinkRef& link);
00234
00235 private:
00236 struct Entry {
00237 Entry(const LinkRef& link);
00238
00239 MetadataVec* blocks_;
00240 LinkRef link_;
00241 };
00242
00243 typedef std::vector<Entry> Vector;
00244 typedef std::vector<Entry>::iterator iterator;
00245 typedef std::vector<Entry>::const_iterator const_iterator;
00246 Vector entries_;
00247 };
00248
00249 }
00250
00251 #endif