servlib/storage/ProphetStore.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     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 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include <oasys/debug/Log.h>
       
    22 #include "ProphetStore.h"
       
    23 
       
    24 namespace dtn {
       
    25 
       
    26 template <>
       
    27 ProphetStore* oasys::Singleton<ProphetStore,false>::instance_ = 0;
       
    28 
       
    29 //----------------------------------------------------------------------
       
    30 ProphetStore::ProphetStore(const oasys::StorageConfig& cfg)
       
    31     : cfg_(cfg),
       
    32       nodes_("ProphetStore","/dtn/storage/prophet",
       
    33              "ProphetNode","prophet")
       
    34 {
       
    35 }
       
    36 
       
    37 //----------------------------------------------------------------------
       
    38 int
       
    39 ProphetStore::init(const oasys::StorageConfig& cfg,
       
    40                    oasys::DurableStore*        store)
       
    41 {
       
    42     if (instance_ != NULL)
       
    43     {
       
    44         PANIC("ProphetStore::init called multiple times");
       
    45     }
       
    46     instance_ = new ProphetStore(cfg);
       
    47     return instance_->nodes_.do_init(cfg,store);
       
    48 }
       
    49 
       
    50 //----------------------------------------------------------------------
       
    51 bool
       
    52 ProphetStore::add(ProphetNode* node)
       
    53 {
       
    54     ProphetNode* n = new ProphetNode(*node);
       
    55     bool ok = nodes_.add(n);
       
    56     delete n;
       
    57     return ok;
       
    58 }
       
    59 
       
    60 //----------------------------------------------------------------------
       
    61 ProphetNode*
       
    62 ProphetStore::get(const EndpointID& eid)
       
    63 {
       
    64     log_debug_p("/dtn/route/store","get(%s)",eid.c_str());
       
    65     return nodes_.get(eid);
       
    66 }
       
    67 
       
    68 //----------------------------------------------------------------------
       
    69 bool
       
    70 ProphetStore::update(ProphetNode* node)
       
    71 {
       
    72     ProphetNode* n = new ProphetNode(*node);
       
    73     bool ok = nodes_.update(n);
       
    74     delete n;
       
    75     return ok;
       
    76 }
       
    77 
       
    78 //----------------------------------------------------------------------
       
    79 bool
       
    80 ProphetStore::del(ProphetNode* node)
       
    81 {
       
    82     EndpointID eid(node->dest_id());
       
    83     return nodes_.del(eid);
       
    84 }
       
    85 
       
    86 //----------------------------------------------------------------------
       
    87 ProphetStore::iterator*
       
    88 ProphetStore::new_iterator()
       
    89 {
       
    90     return nodes_.new_iterator();
       
    91 }
       
    92 
       
    93 //----------------------------------------------------------------------
       
    94 void
       
    95 ProphetStore::close()
       
    96 {
       
    97     nodes_.close();
       
    98 }
       
    99 
       
   100 } // namespace dtn