servlib/bundling/BPQCache.h
changeset 55 1938118cd06c
child 56 76420d9f6e62
equal deleted inserted replaced
54:4122c50abb39 55:1938118cd06c
       
     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 __BPQ_CACHE__
       
    18 #define __BPQ_CACHE__
       
    19 
       
    20 #ifdef HAVE_CONFIG_H
       
    21 #  include <dtn-config.h>
       
    22 #endif
       
    23 
       
    24 #include "Bundle.h"
       
    25 #include <oasys/debug/Log.h>
       
    26 #include <oasys/util/StringUtils.h>
       
    27 
       
    28 namespace dtn {
       
    29 
       
    30 class BPQBlock;
       
    31 class FragmentState;
       
    32 class EndpointID;
       
    33 class BPQResponse;
       
    34 
       
    35 class BPQCache : public oasys::Logger {
       
    36 public:
       
    37 	BPQCache() :
       
    38         Logger("BPQCache", "/dtn/bundle/bpq") {}
       
    39 
       
    40 	/**
       
    41 	 * Add a new BPQ response to the to the cache
       
    42 	 */
       
    43     bool add_response_bundle(Bundle* bundle, BPQBlock* block);
       
    44 
       
    45     /**
       
    46      * Try to answer a BPQ query with a response in the cache
       
    47      */
       
    48     bool answer_query(Bundle* bundle, BPQBlock* block);
       
    49 
       
    50     /**
       
    51      * Number of bundles in the cache
       
    52      */
       
    53     size_t size() {return bpq_table_.size();}
       
    54 
       
    55     static const size_t MAX_KEY_SIZE = 4096;
       
    56 
       
    57 protected:
       
    58 
       
    59     void create_cache_entry(Bundle* bundle, std::string key);
       
    60     void replace_cache_entry(Bundle* bundle, std::string key);
       
    61     void append_cache_entry(Bundle* bundle, std::string key);
       
    62     int  update_bpq_block(Bundle* bundle, BPQBlock* block);
       
    63 
       
    64     /**
       
    65      * Calculate a hash table key from a bundle
       
    66      * This is a concatenation of the Matching Rule and the Query
       
    67      *
       
    68      * If the query is too long, use a hash of the query
       
    69      */
       
    70     void get_hash_key(Bundle* bundle, std::string* key);
       
    71     void get_hash_key(BPQBlock* block, std::string* key);
       
    72 
       
    73 
       
    74     /**
       
    75      * Table of partial BPQ bundles
       
    76      */
       
    77     typedef oasys::StringHashMap<FragmentState*> Cache;
       
    78     Cache bpq_table_;
       
    79 
       
    80 };
       
    81 
       
    82 } // namespace dtn
       
    83 
       
    84 #endif