00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BUNDLE_LIST_H_
00018 #define _BUNDLE_LIST_H_
00019
00020 #include <list>
00021 #include <oasys/compat/inttypes.h>
00022 #include <oasys/thread/Notifier.h>
00023
00024 #include "BundleRef.h"
00025 #include "naming/EndpointID.h"
00026 #include "GbofId.h"
00027
00028 namespace oasys {
00029 class SpinLock;
00030 }
00031
00032 namespace dtn {
00033
00034 class Bundle;
00035 class BundleTimestamp;
00036
00067 class BundleList : public oasys::Logger {
00068 private:
00073 typedef std::list<Bundle*> List;
00074
00075 public:
00081 typedef List::iterator iterator;
00082
00086 BundleList(const std::string& name, oasys::SpinLock* lock = NULL);
00087
00091 virtual ~BundleList();
00092
00098 BundleRef front() const;
00099
00105 BundleRef back() const;
00106
00110 void push_front(Bundle* bundle);
00111
00115 void push_front(const BundleRef& bundle)
00116 {
00117 return push_front(bundle.object());
00118 }
00119
00123 void push_back(Bundle* bundle);
00124
00128 void push_back(const BundleRef& bundle)
00129 {
00130 return push_back(bundle.object());
00131 }
00132
00136 typedef enum {
00137 SORT_PRIORITY = 0x1,
00138 SORT_FRAG_OFFSET
00139 } sort_order_t;
00140
00144 void insert_sorted(Bundle* bundle, sort_order_t sort_order);
00145
00150 void insert_random(Bundle* bundle);
00151
00162 BundleRef pop_front(bool used_notifier = false);
00163
00177 BundleRef pop_back(bool used_notifier = false);
00178
00186 bool erase(Bundle* bundle, bool used_notifier = false);
00187
00188 bool erase(const BundleRef& bundle, bool used_notifier = false) {
00189 return erase(bundle.object(), used_notifier);
00190 }
00191
00195 void erase(iterator& iter, bool used_notifier = false);
00196
00202 bool contains(Bundle* bundle) const;
00203
00209 bool contains(const BundleRef& bundle) const
00210 {
00211 return contains(bundle.object());
00212 }
00213
00220 BundleRef find(u_int32_t bundleid) const;
00221
00229 BundleRef find(const EndpointID& source_eid,
00230 const BundleTimestamp& creation_ts) const;
00231
00237 BundleRef find(GbofId& gbof_id) const;
00238
00245 BundleRef find(const GbofId& gbof_id,
00246 const BundleTimestamp& extended_id) const;
00247
00251 void move_contents(BundleList* other);
00252
00256 void clear();
00257
00261 size_t size() const;
00262
00266 bool empty() const;
00267
00273 iterator begin() const;
00274
00280 iterator end() const;
00281
00285 oasys::SpinLock* lock() const { return lock_; }
00286
00290 const std::string& name() const { return name_; }
00291
00295 void set_name(const std::string& name);
00296
00297 private:
00301 void add_bundle(Bundle* bundle, const iterator& pos);
00302
00313 Bundle* del_bundle(const iterator& pos, bool used_notifier);
00314
00315 std::string name_;
00316 List list_;
00317
00318 protected:
00319 oasys::SpinLock* lock_;
00320 bool own_lock_;
00321 oasys::Notifier* notifier_;
00322 };
00323
00330 class BlockingBundleList : public BundleList {
00331 public:
00332 BlockingBundleList(const std::string& name);
00333
00334 virtual ~BlockingBundleList();
00335
00343 BundleRef pop_blocking(int timeout = -1);
00344
00348 oasys::Notifier* notifier() { return notifier_; }
00349 };
00350
00351 }
00352
00353 #endif