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 #ifndef _BUNDLE_STORE_H_ 00018 #define _BUNDLE_STORE_H_ 00019 00020 #include <oasys/debug/DebugUtils.h> 00021 #include <oasys/serialize/TypeShims.h> 00022 #include <oasys/storage/InternalKeyDurableTable.h> 00023 #include <oasys/util/OpenFdCache.h> 00024 #include <oasys/util/Singleton.h> 00025 #include "DTNStorageConfig.h" 00026 00027 namespace dtn { 00028 00029 class Bundle; 00030 00036 class BundleStore : public oasys::Singleton<BundleStore, false> { 00037 public: 00039 typedef oasys::OpenFdCache<std::string> FdCache; 00040 typedef oasys::InternalKeyDurableTable< 00041 oasys::UIntShim, u_int32_t, Bundle> BundleTable; 00042 typedef BundleTable::iterator iterator; 00043 00048 static int init(const DTNStorageConfig& cfg, 00049 oasys::DurableStore* store); 00050 00054 BundleStore(const DTNStorageConfig& cfg); 00055 00057 bool add(Bundle* bundle); 00058 00060 Bundle* get(u_int32_t bundleid); 00061 00063 bool update(Bundle* bundle); 00064 00066 bool del(Bundle* bundle); 00067 00069 iterator* new_iterator(); 00070 00072 void close(); 00073 00075 const std::string& payload_dir() { return cfg_.payload_dir_; } 00076 u_int64_t payload_quota() { return cfg_.payload_quota_; } 00077 FdCache* payload_fdcache() { return &payload_fdcache_; } 00078 u_int64_t total_size() { return total_size_; } 00080 00081 protected: 00082 friend class BundleDaemon; 00083 00086 void set_total_size(u_int64_t sz) { total_size_ = sz; } 00087 00088 const DTNStorageConfig& cfg_; 00089 BundleTable bundles_; 00090 FdCache payload_fdcache_; 00091 u_int64_t total_size_; 00092 }; 00093 00094 } // namespace dtn 00095 00096 #endif /* _BUNDLE_STORE_H_ */