blob: 096b0c0d7fd767b3f927bd711b803870950b5e90 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/*
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
17using namespace std;
18
19class CsEntry;
20typedef list<CsEntry*>::iterator CsLruIterator;
21
22//structure for CS entry
23struct CsEntry
24{
25 string contentName;
26 int contentSize;
27
28 CsLruIterator lruPosition;
29};
30
31typedef string_key_hash_t<CsEntry>::point_iterator CsIterator;
32typedef string_key_hash_t<CsEntry>::iterator CsRangeIterator;
33
34// class implementing NDN content store
35class NdnCs
36{
37public:
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
51protected:
52 //move the given CS entry to the head of the list
53 void promote( CsEntry &entry );
54
55private:
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 */