servlib/bundling/BPQBlock.h
changeset 66 e1101c5d54a1
parent 65 333724f2f7cf
equal deleted inserted replaced
65:333724f2f7cf 66:e1101c5d54a1
    20 #ifdef HAVE_CONFIG_H
    20 #ifdef HAVE_CONFIG_H
    21 #  include <dtn-config.h>
    21 #  include <dtn-config.h>
    22 #endif
    22 #endif
    23 
    23 
    24 #include "BlockInfo.h"
    24 #include "BlockInfo.h"
       
    25 #include "BPQFragmentList.h"
    25 #include <oasys/debug/Log.h>
    26 #include <oasys/debug/Log.h>
    26 namespace dtn {
    27 namespace dtn {
    27 
    28 
    28 class BPQFragment{
       
    29 public:
       
    30 	BPQFragment(size_t offset , size_t length) :
       
    31 		offset_(offset),
       
    32 		length_(length) {}
       
    33 
    29 
    34     ~BPQFragment() {}
       
    35 
       
    36     /// @{ Accessors
       
    37     size_t offset() const { return offset_; }
       
    38     size_t length() const { return length_; }
       
    39     /// @}
       
    40 
       
    41 private:
       
    42     size_t offset_;              ///< Fragment offset
       
    43     size_t length_;              ///< Fragment length
       
    44 };
       
    45 
    30 
    46 class BPQBlock : public oasys::Logger
    31 class BPQBlock : public oasys::Logger
    47 {
    32 {
    48 public:
    33 public:
    49     BPQBlock(const Bundle* bundle);
    34     BPQBlock(const Bundle* bundle);
    64     const EndpointID& 		source()        const { return source_; }
    49     const EndpointID& 		source()        const { return source_; }
    65     u_int           		query_len()     const { return query_len_; }
    50     u_int           		query_len()     const { return query_len_; }
    66     u_char*        		 	query_val()     const { return query_val_; }
    51     u_char*        		 	query_val()     const { return query_val_; }
    67     u_int           		length()        const;
    52     u_int           		length()        const;
    68     u_int					frag_len()		const { return fragments_.size(); }
    53     u_int					frag_len()		const { return fragments_.size(); }
       
    54     const BPQFragmentList& 	fragments()  	const { return fragments_; }
    69     /// @}
    55     /// @}
    70 
    56 
    71     bool    match(const BPQBlock* other)  const;
    57     bool match				(const BPQBlock* other)  const;
    72     void add_fragment(BPQFragment fragment) {fragments_.push_back(fragment);}
       
    73 
    58 
    74     /// @{ Typedefs and wrappers for the BPQFragment vector and iterators
    59     /**
    75     typedef std::vector<BPQFragment> BPQFragmentVec;
    60      * Add the new fragment in sorted order
    76     typedef BPQFragmentVec::iterator iterator;
    61      */
    77     typedef BPQFragmentVec::const_iterator const_iterator;
    62     void add_fragment (BPQFragment* fragment);
    78 
       
    79     bool                           empty() const { return fragments_.empty(); }
       
    80     BPQFragmentVec::iterator       begin()       { return fragments_.begin(); }
       
    81     BPQFragmentVec::iterator       end()         { return fragments_.end();   }
       
    82     BPQFragmentVec::const_iterator begin() const { return fragments_.begin(); }
       
    83     BPQFragmentVec::const_iterator end()   const { return fragments_.end();   }
       
    84     /// @}
       
    85 
    63 
    86 private:
    64 private:
    87     int initialise(BlockInfo* block, bool created_locally, const Bundle* bundle);       ///< Wrapper function called by constructor
    65     int initialise(BlockInfo* block, bool created_locally, const Bundle* bundle);       ///< Wrapper function called by constructor
    88 
    66 
    89     void log_block_info(BlockInfo* block);
    67     void log_block_info(BlockInfo* block);
    99     u_int matching_rule_;       	///< Exact
    77     u_int matching_rule_;       	///< Exact
   100     BundleTimestamp creation_ts_;	///< Original Creation Timestamp
    78     BundleTimestamp creation_ts_;	///< Original Creation Timestamp
   101     EndpointID source_;				///< Original Source EID
    79     EndpointID source_;				///< Original Source EID
   102     u_int query_len_;           	///< Length of the query value
    80     u_int query_len_;           	///< Length of the query value
   103     u_char* query_val_;         	///< Query value
    81     u_char* query_val_;         	///< Query value
   104     BPQFragmentVec fragments_;  	///< List of fragments returned
    82     BPQFragmentList fragments_;  	///< List of fragments returned
   105 };
    83 };
   106 
    84 
   107 } // namespace dtn
    85 } // namespace dtn
   108 
    86 
   109 #endif /* _BPQ_BLOCK_H_ */
    87 #endif /* _BPQ_BLOCK_H_ */