BundleStore.cc

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 
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 } // namespace dtn
00102 

Generated on Sat Sep 8 08:36:16 2007 for DTN Reference Implementation by  doxygen 1.5.3