00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_REPOSITORY_H_
00018 #define _PROPHET_REPOSITORY_H_
00019
00020 #include "Bundle.h"
00021 #include "BundleList.h"
00022 #include "QueuePolicy.h"
00023
00024 #if defined(__GNUC__)
00025 # define PRINTFLIKE(fmt, arg) __attribute__((format (printf, fmt, arg)))
00026 #else
00027 # define PRINTFLIKE(a, b)
00028 #endif
00029
00030 namespace prophet
00031 {
00032
00043 class Repository
00044 {
00045 public:
00046 typedef BundleList::iterator iterator;
00047 typedef BundleList::const_iterator const_iterator;
00048
00053 class BundleCoreRep
00054 {
00055 public:
00056 virtual ~BundleCoreRep() {}
00057 virtual void print_log(const char* name, int level,
00058 const char* fmt, ...)
00059 PRINTFLIKE(4,5) = 0;
00060 virtual void drop_bundle(const Bundle* bundle) = 0;
00061 virtual u_int64_t max_bundle_quota() const = 0;
00062 };
00063
00073 Repository(BundleCoreRep* core, QueueComp* qc = NULL,
00074 const BundleList* list = NULL);
00075
00079 ~Repository();
00080
00087 bool add(const Bundle* bundle);
00088
00095 void del(const Bundle* bundle);
00096
00102 void set_comparator(QueueComp* qc);
00103
00107 const QueueComp* get_comparator() const { return comp_; }
00108
00112 void handle_change_max();
00113
00118 void change_priority(const Bundle* b);
00119
00124 const BundleList& get_bundles() const { return list_; }
00125
00129 bool empty() const { return list_.empty(); }
00130
00134 size_t size() const { return list_.size(); }
00135
00139 u_int get_max() const { return core_->max_bundle_quota(); }
00140
00144 u_int get_current() const { return current_; }
00145
00146 protected:
00150 void evict();
00151
00153 void make_heap(size_t first, size_t last);
00154 void push_heap(size_t first, size_t hole, size_t top, const Bundle* b);
00155 void pop_heap(size_t first, size_t last, size_t result, const Bundle* b);
00156 void adjust_heap(size_t first, size_t hole, size_t len, const Bundle* b);
00157 void remove_and_reheap(size_t hole);
00159
00163 bool find(const Bundle* b, iterator& i);
00164
00165 BundleCoreRep* core_;
00166 QueueComp* comp_;
00167 BundleList list_;
00168 u_int current_;
00169 };
00170
00171 };
00172
00173 #endif // _PROPHET_REPOSITORY_H_