servlib/storage/BundleStore.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     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 #ifndef _BUNDLE_STORE_H_
       
    18 #define _BUNDLE_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/OpenFdCache.h>
       
    24 #include <oasys/util/Singleton.h>
       
    25 #include "DTNStorageConfig.h"
       
    26 
       
    27 namespace dtn {
       
    28 
       
    29 class Bundle;
       
    30 
       
    31 /**
       
    32  * The class for bundle storage is an instantiation of an oasys
       
    33  * durable table to store the bundle metadata, tracking logic for the
       
    34  * storage total, and other support classes for the payloads.
       
    35  */
       
    36 class BundleStore : public oasys::Singleton<BundleStore, false> {
       
    37 public:
       
    38     /// Helper class typedefs
       
    39     typedef oasys::OpenFdCache<std::string> FdCache;
       
    40     typedef oasys::InternalKeyDurableTable<
       
    41         oasys::UIntShim, u_int32_t, Bundle> BundleTable;
       
    42     typedef BundleTable::iterator iterator;
       
    43     
       
    44     /**
       
    45      * Boot time initializer that takes as a parameter the storage
       
    46      * configuration to use.
       
    47      */
       
    48     static int init(const DTNStorageConfig& cfg,
       
    49                     oasys::DurableStore*    store);
       
    50     
       
    51     /**
       
    52      * Constructor.
       
    53      */
       
    54     BundleStore(const DTNStorageConfig& cfg);
       
    55 
       
    56     /// Add a new bundle
       
    57     bool add(Bundle* bundle);
       
    58 
       
    59     /// Retrieve a bundle
       
    60     Bundle* get(u_int32_t bundleid);
       
    61     
       
    62     /// Update the metabundle for the bundle
       
    63     bool update(Bundle* bundle);
       
    64 
       
    65     /// Delete the bundle
       
    66     bool del(Bundle* bundle);
       
    67 
       
    68     /// Return a new iterator
       
    69     iterator* new_iterator();
       
    70         
       
    71     /// Close down the table
       
    72     void close();
       
    73 
       
    74     /// @{ Accessors
       
    75     const std::string& payload_dir()     { return cfg_.payload_dir_; }
       
    76     u_int64_t          payload_quota()   { return cfg_.payload_quota_; }
       
    77     FdCache*           payload_fdcache() { return &payload_fdcache_; }
       
    78     u_int64_t          total_size()      { return total_size_; }
       
    79     /// @}
       
    80     
       
    81 protected:
       
    82     friend class BundleDaemon;
       
    83 
       
    84     /// When the bundle store is loaded at boot time, we need to reset
       
    85     /// the in-memory total_size_ parameter
       
    86     void set_total_size(u_int64_t sz) { total_size_ = sz; }
       
    87     
       
    88     const DTNStorageConfig& cfg_; ///< Storage configuration
       
    89     BundleTable bundles_;	///< Bundle metabundle table
       
    90     FdCache payload_fdcache_;	///< File descriptor cache
       
    91     u_int64_t total_size_;	///M Total size in the data store
       
    92 };
       
    93 
       
    94 } // namespace dtn
       
    95 
       
    96 #endif /* _BUNDLE_STORE_H_ */