BundleList.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-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 _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 
00027 namespace oasys {
00028 class SpinLock;
00029 }
00030 
00031 namespace dtn {
00032 
00033 class Bundle;
00034 class BundleTimestamp;
00035 
00066 class BundleList : public oasys::Logger {
00067 public:
00071     typedef std::list<Bundle*> List;
00072 
00076     typedef List::iterator iterator;
00077     
00081     typedef List::const_iterator const_iterator;
00082 
00086     BundleList(const std::string& name);
00087 
00091     virtual ~BundleList();
00092 
00098     BundleRef front();
00099 
00105     BundleRef back();
00106 
00110     void push_front(Bundle* bundle);
00111 
00115     void push_back(Bundle* bundle);
00116 
00120     typedef enum {
00121         SORT_PRIORITY = 0x1,    
00122         SORT_FRAG_OFFSET        
00123     } sort_order_t;
00124         
00128     void insert_sorted(Bundle* bundle, sort_order_t sort_order);
00129 
00134     void insert_random(Bundle* bundle);
00135     
00146     BundleRef pop_front(bool used_notifier = false);
00147 
00161     BundleRef pop_back(bool used_notifier = false);
00162 
00170     bool erase(Bundle* bundle, bool used_notifier = false);
00171 
00177     bool contains(Bundle* bundle);
00178 
00185     BundleRef find(u_int32_t bundleid);
00186 
00194     BundleRef find(const EndpointID& source_eid,
00195                    const BundleTimestamp& creation_ts);
00196     
00200     void move_contents(BundleList* other);
00201 
00205     void clear();
00206 
00210     size_t size() const;
00211 
00217     iterator begin();
00218     
00224     iterator end();
00225 
00231     const_iterator begin() const;
00232 
00238     const_iterator end() const;
00239 
00243     oasys::SpinLock* lock() const { return lock_; }
00244 
00248     const std::string& name() const { return name_; }
00249 
00253     void set_name(const std::string& name);
00254     
00255 protected:
00259     void add_bundle(Bundle* bundle, const iterator& pos);
00260     
00271     Bundle* del_bundle(const iterator& pos, bool used_notifier);
00272     
00273     std::string name_;
00274     oasys::SpinLock* lock_;
00275     oasys::Notifier* notifier_;
00276     List list_;
00277 };
00278 
00285 class BlockingBundleList : public BundleList {
00286 public:
00287     BlockingBundleList(const std::string& name);
00288 
00289     virtual ~BlockingBundleList();
00290     
00298     BundleRef pop_blocking(int timeout = -1);
00299 
00303     oasys::Notifier* notifier() { return notifier_; }
00304 };
00305 
00306 } // namespace dtn
00307 
00308 #endif /* _BUNDLE_LIST_H_ */

Generated on Thu Jun 7 16:56:48 2007 for DTN Reference Implementation by  doxygen 1.5.1