00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "BundleStore.h"
00019 #include "bundling/Bundle.h"
00020
00021 namespace dtn {
00022
00023 template <>
00024 BundleStore* oasys::Singleton<BundleStore, false>::instance_ = 0;
00025
00026
00027 BundleStore::BundleStore(const DTNStorageConfig& cfg)
00028 : cfg_(cfg),
00029 bundles_("BundleStore", "/dtn/storage/bundles",
00030 "bundle", "bundles"),
00031 payload_fdcache_("/dtn/storage/bundles/fdcache",
00032 cfg.payload_fd_cache_size_),
00033 total_size_(0)
00034 {
00035 }
00036 \
00037
00038 int
00039 BundleStore::init(const DTNStorageConfig& cfg,
00040 oasys::DurableStore* store)
00041 {
00042 if (instance_ != NULL) {
00043 PANIC("BundleStore::init called multiple times");
00044 }
00045 instance_ = new BundleStore(cfg);
00046 return instance_->bundles_.do_init(cfg, store);
00047 }
00048
00049
00050 bool
00051 BundleStore::add(Bundle* bundle)
00052 {
00053 bool ret = bundles_.add(bundle);
00054 if (ret) {
00055 total_size_ += bundle->durable_size();
00056 }
00057 return ret;
00058 }
00059
00060
00061 Bundle*
00062 BundleStore::get(u_int32_t bundleid)
00063 {
00064 return bundles_.get(bundleid);
00065 }
00066
00067
00068 bool
00069 BundleStore::update(Bundle* bundle)
00070 {
00071 return bundles_.update(bundle);
00072 }
00073
00074
00075 bool
00076 BundleStore::del(Bundle* bundle)
00077 {
00078 bool ret = bundles_.del(bundle->bundleid_);
00079 if (ret) {
00080 ASSERT(total_size_ >= bundle->durable_size());
00081 total_size_ -= bundle->durable_size();
00082 }
00083 return ret;
00084 }
00085
00086
00087 BundleStore::iterator*
00088 BundleStore::new_iterator()
00089 {
00090 return bundles_.new_iterator();
00091 }
00092
00093
00094 void
00095 BundleStore::close()
00096 {
00097 bundles_.close();
00098 }
00099
00100
00101 }
00102