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