00001 /* 00002 * Copyright 2007 Baylor University 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 #ifdef HAVE_CONFIG_H 00018 # include <dtn-config.h> 00019 #endif 00020 00021 #include <oasys/debug/Log.h> 00022 #include "ProphetStore.h" 00023 00024 namespace dtn { 00025 00026 template <> 00027 ProphetStore* oasys::Singleton<ProphetStore,false>::instance_ = 0; 00028 00029 //---------------------------------------------------------------------- 00030 ProphetStore::ProphetStore(const oasys::StorageConfig& cfg) 00031 : cfg_(cfg), 00032 nodes_("ProphetStore","/dtn/storage/prophet", 00033 "ProphetNode","prophet") 00034 { 00035 } 00036 00037 //---------------------------------------------------------------------- 00038 int 00039 ProphetStore::init(const oasys::StorageConfig& cfg, 00040 oasys::DurableStore* store) 00041 { 00042 if (instance_ != NULL) 00043 { 00044 PANIC("ProphetStore::init called multiple times"); 00045 } 00046 instance_ = new ProphetStore(cfg); 00047 return instance_->nodes_.do_init(cfg,store); 00048 } 00049 00050 //---------------------------------------------------------------------- 00051 bool 00052 ProphetStore::add(ProphetNode* node) 00053 { 00054 ProphetNode* n = new ProphetNode(*node); 00055 bool ok = nodes_.add(n); 00056 delete n; 00057 return ok; 00058 } 00059 00060 //---------------------------------------------------------------------- 00061 ProphetNode* 00062 ProphetStore::get(const EndpointID& eid) 00063 { 00064 log_debug_p("/dtn/route/store","get(%s)",eid.c_str()); 00065 return nodes_.get(eid); 00066 } 00067 00068 //---------------------------------------------------------------------- 00069 bool 00070 ProphetStore::update(ProphetNode* node) 00071 { 00072 ProphetNode* n = new ProphetNode(*node); 00073 bool ok = nodes_.update(n); 00074 delete n; 00075 return ok; 00076 } 00077 00078 //---------------------------------------------------------------------- 00079 bool 00080 ProphetStore::del(ProphetNode* node) 00081 { 00082 EndpointID eid(node->dest_id()); 00083 return nodes_.del(eid); 00084 } 00085 00086 //---------------------------------------------------------------------- 00087 ProphetStore::iterator* 00088 ProphetStore::new_iterator() 00089 { 00090 return nodes_.new_iterator(); 00091 } 00092 00093 //---------------------------------------------------------------------- 00094 void 00095 ProphetStore::close() 00096 { 00097 nodes_.close(); 00098 } 00099 00100 } // namespace dtn