00001 /* 00002 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By 00003 * downloading, copying, installing or using the software you agree to 00004 * this license. If you do not agree to this license, do not download, 00005 * install, copy or use the software. 00006 * 00007 * Intel Open Source License 00008 * 00009 * Copyright (c) 2004 Intel Corporation. All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are 00013 * met: 00014 * 00015 * Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 00018 * Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 00022 * Neither the name of the Intel Corporation nor the names of its 00023 * contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 00030 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00031 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00032 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00033 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00034 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00035 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00036 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 */ 00038 #ifndef _BUNDLE_LIST_H_ 00039 #define _BUNDLE_LIST_H_ 00040 00041 #include <list> 00042 #include <oasys/compat/inttypes.h> 00043 #include <oasys/thread/Notifier.h> 00044 00045 #include "BundleRef.h" 00046 #include "naming/EndpointID.h" 00047 00048 namespace oasys { 00049 class SpinLock; 00050 } 00051 00052 namespace dtn { 00053 00054 class Bundle; 00055 class BundleTimestamp; 00056 00087 class BundleList : public oasys::Logger { 00088 public: 00092 typedef std::list<Bundle*> List; 00093 00097 typedef List::iterator iterator; 00098 00102 typedef List::const_iterator const_iterator; 00103 00107 BundleList(const std::string& name); 00108 00112 virtual ~BundleList(); 00113 00119 BundleRef front(); 00120 00126 BundleRef back(); 00127 00131 void push_front(Bundle* bundle); 00132 00136 void push_back(Bundle* bundle); 00137 00141 typedef enum { 00142 SORT_PRIORITY = 0x1, 00143 SORT_FRAG_OFFSET 00144 } sort_order_t; 00145 00149 void insert_sorted(Bundle* bundle, sort_order_t sort_order); 00150 00155 void insert_random(Bundle* bundle); 00156 00167 BundleRef pop_front(bool used_notifier = false); 00168 00182 BundleRef pop_back(bool used_notifier = false); 00183 00191 bool erase(Bundle* bundle, bool used_notifier = false); 00192 00198 bool contains(Bundle* bundle); 00199 00206 BundleRef find(u_int32_t bundleid); 00207 00215 BundleRef find(const EndpointID& source_eid, 00216 const BundleTimestamp& creation_ts); 00217 00221 void move_contents(BundleList* other); 00222 00226 void clear(); 00227 00231 size_t size() const; 00232 00238 iterator begin(); 00239 00245 iterator end(); 00246 00252 const_iterator begin() const; 00253 00259 const_iterator end() const; 00260 00264 oasys::SpinLock* lock() const { return lock_; } 00265 00269 const std::string& name() const { return name_; } 00270 00271 protected: 00275 void add_bundle(Bundle* bundle, const iterator& pos); 00276 00287 Bundle* del_bundle(const iterator& pos, bool used_notifier); 00288 00289 std::string name_; 00290 oasys::SpinLock* lock_; 00291 oasys::Notifier* notifier_; 00292 List list_; 00293 }; 00294 00301 class BlockingBundleList : public BundleList { 00302 public: 00303 BlockingBundleList(const std::string& name); 00304 00305 virtual ~BlockingBundleList(); 00306 00314 BundleRef pop_blocking(int timeout = -1); 00315 00319 oasys::Notifier* notifier() { return notifier_; } 00320 }; 00321 00322 } // namespace dtn 00323 00324 #endif /* _BUNDLE_LIST_H_ */