|
1 /* |
|
2 * Copyright 2004-2006 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifdef HAVE_CONFIG_H |
|
18 # include <dtn-config.h> |
|
19 #endif |
|
20 |
|
21 #include "BundleStore.h" |
|
22 #include "bundling/Bundle.h" |
|
23 |
|
24 namespace dtn { |
|
25 |
|
26 template <> |
|
27 BundleStore* oasys::Singleton<BundleStore, false>::instance_ = 0; |
|
28 |
|
29 //---------------------------------------------------------------------- |
|
30 BundleStore::BundleStore(const DTNStorageConfig& cfg) |
|
31 : cfg_(cfg), |
|
32 bundles_("BundleStore", "/dtn/storage/bundles", |
|
33 "bundle", "bundles"), |
|
34 payload_fdcache_("/dtn/storage/bundles/fdcache", |
|
35 cfg.payload_fd_cache_size_), |
|
36 total_size_(0) |
|
37 { |
|
38 } |
|
39 |
|
40 //---------------------------------------------------------------------- |
|
41 int |
|
42 BundleStore::init(const DTNStorageConfig& cfg, |
|
43 oasys::DurableStore* store) |
|
44 { |
|
45 if (instance_ != NULL) { |
|
46 PANIC("BundleStore::init called multiple times"); |
|
47 } |
|
48 instance_ = new BundleStore(cfg); |
|
49 return instance_->bundles_.do_init(cfg, store); |
|
50 } |
|
51 |
|
52 //---------------------------------------------------------------------- |
|
53 bool |
|
54 BundleStore::add(Bundle* bundle) |
|
55 { |
|
56 bool ret = bundles_.add(bundle); |
|
57 if (ret) { |
|
58 total_size_ += bundle->durable_size(); |
|
59 } |
|
60 return ret; |
|
61 } |
|
62 |
|
63 //---------------------------------------------------------------------- |
|
64 Bundle* |
|
65 BundleStore::get(u_int32_t bundleid) |
|
66 { |
|
67 return bundles_.get(bundleid); |
|
68 } |
|
69 |
|
70 //---------------------------------------------------------------------- |
|
71 bool |
|
72 BundleStore::update(Bundle* bundle) |
|
73 { |
|
74 return bundles_.update(bundle); |
|
75 } |
|
76 |
|
77 //---------------------------------------------------------------------- |
|
78 bool |
|
79 BundleStore::del(Bundle* bundle) |
|
80 { |
|
81 bool ret = bundles_.del(bundle->bundleid()); |
|
82 if (ret) { |
|
83 ASSERT(total_size_ >= bundle->durable_size()); |
|
84 total_size_ -= bundle->durable_size(); |
|
85 } |
|
86 return ret; |
|
87 } |
|
88 |
|
89 //---------------------------------------------------------------------- |
|
90 BundleStore::iterator* |
|
91 BundleStore::new_iterator() |
|
92 { |
|
93 return bundles_.new_iterator(); |
|
94 } |
|
95 |
|
96 //---------------------------------------------------------------------- |
|
97 void |
|
98 BundleStore::close() |
|
99 { |
|
100 bundles_.close(); |
|
101 } |
|
102 |
|
103 |
|
104 } // namespace dtn |
|
105 |