Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: ndn_cs.h |
| 3 | * Author: cawka |
| 4 | * |
| 5 | * Created on December 15, 2010, 2:17 PM |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_CS_H |
| 9 | #define NDN_CS_H |
| 10 | |
| 11 | #include "ndn_common.h" |
| 12 | #include "hash_helper.h" |
| 13 | #include <qualnet_mutex.h> |
| 14 | #include <list> |
| 15 | #include <string> |
| 16 | |
| 17 | using namespace std; |
| 18 | |
| 19 | class CsEntry; |
| 20 | typedef list<CsEntry*>::iterator CsLruIterator; |
| 21 | |
| 22 | //structure for CS entry |
| 23 | struct CsEntry |
| 24 | { |
| 25 | string contentName; |
| 26 | int contentSize; |
| 27 | |
| 28 | CsLruIterator lruPosition; |
| 29 | }; |
| 30 | |
| 31 | typedef string_key_hash_t<CsEntry>::point_iterator CsIterator; |
| 32 | typedef string_key_hash_t<CsEntry>::iterator CsRangeIterator; |
| 33 | |
| 34 | // class implementing NDN content store |
| 35 | class NdnCs |
| 36 | { |
| 37 | public: |
| 38 | NdnCs( int max_size=NDN_CONTENT_STORE_SIZE ); |
| 39 | virtual ~NdnCs( ); |
| 40 | |
| 41 | // Find corresponding CS entry for the given content name |
| 42 | CsIterator lookup( const string &prefix ); |
| 43 | bool isValid( const CsIterator &it ) { return it!=_cs.end(); } |
| 44 | |
| 45 | // Add new content to the content store. Old content will be replaced |
| 46 | void add( const string &contentName, int contentSize ); |
| 47 | |
| 48 | // Dump content store entries |
| 49 | void dump( ); |
| 50 | |
| 51 | protected: |
| 52 | //move the given CS entry to the head of the list |
| 53 | void promote( CsEntry &entry ); |
| 54 | |
| 55 | private: |
| 56 | int _maxSize; // maximum number of entries in cache |
| 57 | |
| 58 | string_key_hash_t<CsEntry> _cs; // actual content store |
| 59 | |
| 60 | list<CsEntry*> _lru; // LRU index of the content store |
| 61 | QNThreadMutex _csMutex; // just to make sure we are not |
| 62 | // getting problems with multiple threads |
| 63 | }; |
| 64 | |
| 65 | #endif /* NDN_CS_H */ |