|
1 /* |
|
2 * Copyright 2007 Baylor University |
|
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 #ifndef _PROPHET_STORE_H_ |
|
18 #define _PROPHET_STORE_H_ |
|
19 |
|
20 #include <oasys/debug/DebugUtils.h> |
|
21 #include <oasys/serialize/TypeShims.h> |
|
22 #include <oasys/storage/InternalKeyDurableTable.h> |
|
23 #include <oasys/util/Singleton.h> |
|
24 #include <oasys/storage/StorageConfig.h> |
|
25 #include "naming/EndpointID.h" |
|
26 #include "routing/ProphetNode.h" |
|
27 |
|
28 namespace dtn { |
|
29 |
|
30 class EndpointIDShim : public EndpointID, |
|
31 public oasys::Formatter { |
|
32 public: |
|
33 EndpointIDShim() |
|
34 : oasys::Formatter() {} |
|
35 EndpointIDShim(EndpointID eid) |
|
36 : EndpointID(eid), |
|
37 oasys::Formatter() {} |
|
38 virtual ~EndpointIDShim() {} |
|
39 |
|
40 int format(char *buf, size_t sz) const { |
|
41 return snprintf(buf, sz, "%s", c_str()); |
|
42 } |
|
43 |
|
44 EndpointID value() const { return *this; } |
|
45 }; |
|
46 |
|
47 class ProphetStore : public oasys::Singleton<ProphetStore, false> { |
|
48 public: |
|
49 typedef oasys::InternalKeyDurableTable< |
|
50 EndpointIDShim,EndpointID,ProphetNode> ProphetDurableTable; |
|
51 typedef ProphetDurableTable::iterator iterator; |
|
52 |
|
53 /** |
|
54 * Boot time initializer |
|
55 */ |
|
56 static int init(const oasys::StorageConfig& cfg, |
|
57 oasys::DurableStore* store); |
|
58 |
|
59 /** |
|
60 * Constructor |
|
61 */ |
|
62 ProphetStore(const oasys::StorageConfig& cfg); |
|
63 |
|
64 /// Add a new ProphetNode |
|
65 bool add(ProphetNode* node); |
|
66 |
|
67 /// Retrieve a ProphetNode |
|
68 ProphetNode* get(const EndpointID& remote_eid); |
|
69 |
|
70 /// Update the ProphetNode data |
|
71 bool update(ProphetNode* node); |
|
72 |
|
73 /// Delete the ProphetNode |
|
74 bool del(ProphetNode* node); |
|
75 |
|
76 /// Return a new iterator. |
|
77 iterator* new_iterator(); |
|
78 |
|
79 /// Close down the table |
|
80 void close(); |
|
81 |
|
82 protected: |
|
83 |
|
84 const oasys::StorageConfig& cfg_; ///< storage configuration |
|
85 ProphetDurableTable nodes_; ///< ProphetNode information base |
|
86 }; |
|
87 |
|
88 } // namespace dtn |
|
89 |
|
90 #endif // _PROPHET_STORE_H_ |