#include <P2pnsCache.h>
Definition at line 55 of file P2pnsCache.h.
Public Member Functions | |
| virtual int | numInitStages () const |
| virtual void | initialize (int stage) |
| virtual void | handleMessage (cMessage *msg) |
| virtual uint32_t | getSize () |
| Returns number of stored data items in the map. | |
| virtual void | clear () |
| Clears all stored data items. | |
| virtual bool | isEmpty () |
| Checks if the data storage map is empty. | |
| virtual const BinaryValue & | getData (const BinaryValue &name) |
| Returns the value of a stored data item with a given name. | |
| virtual cMessage * | getTtlMessage (const BinaryValue &name) |
| Returns the ttlMessage of a stored data item with a given name. | |
| virtual const BinaryValue & | getDataAtPos (uint32_t pos=0) |
| Returns the value of the data item stored at position pos. | |
| virtual void | addData (BinaryValue name, BinaryValue value, cMessage *ttlMessage=NULL) |
| Store a new data item in the map. | |
| virtual void | removeData (const BinaryValue &name) |
| Removes a certain data item from the map. | |
| void | display () |
Protected Member Functions | |
| void | updateDisplayString () |
| Updates the display string. | |
| void | updateTooltip () |
| Updates the tooltip. | |
Protected Attributes | |
| std::map< BinaryValue, P2pnsCacheEntry > | cache |
| internal representation of the cache | |
| virtual int P2pnsCache::numInitStages | ( | void | ) | const [inline, virtual] |
| void P2pnsCache::initialize | ( | int | stage | ) | [virtual] |
Definition at line 44 of file P2pnsCache.cc.
00045 { 00046 if (stage != MIN_STAGE_APP) 00047 return; 00048 00049 WATCH_MAP(cache); 00050 }
| void P2pnsCache::handleMessage | ( | cMessage * | msg | ) | [virtual] |
| uint32_t P2pnsCache::getSize | ( | ) | [virtual] |
Returns number of stored data items in the map.
Definition at line 67 of file P2pnsCache.cc.
00068 { 00069 return cache.size(); 00070 }
| void P2pnsCache::clear | ( | ) | [virtual] |
Clears all stored data items.
Definition at line 57 of file P2pnsCache.cc.
00058 { 00059 map<BinaryValue, P2pnsCacheEntry>::iterator iter; 00060 for( iter = cache.begin(); iter != cache.end(); iter++ ) { 00061 cancelAndDelete(iter->second.ttlMessage); 00062 } 00063 cache.clear(); 00064 }
| bool P2pnsCache::isEmpty | ( | ) | [virtual] |
Checks if the data storage map is empty.
Definition at line 72 of file P2pnsCache.cc.
00073 { 00074 if (cache.size() == 0) 00075 return true; 00076 else 00077 return false; 00078 }
| const BinaryValue & P2pnsCache::getData | ( | const BinaryValue & | name | ) | [virtual] |
Returns the value of a stored data item with a given name.
| name | The name of the data item |
Definition at line 80 of file P2pnsCache.cc.
00080 { 00081 00082 std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.find(name); 00083 00084 if (it == cache.end()) 00085 return BinaryValue::UNSPECIFIED_VALUE; 00086 else 00087 return it->second.value; 00088 }
| cMessage * P2pnsCache::getTtlMessage | ( | const BinaryValue & | name | ) | [virtual] |
Returns the ttlMessage of a stored data item with a given name.
| name | The name of the data item |
Definition at line 92 of file P2pnsCache.cc.
00092 { 00093 std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.find(name); 00094 00095 if (it == cache.end()) 00096 return NULL; 00097 else 00098 return it->second.ttlMessage; 00099 }
| const BinaryValue & P2pnsCache::getDataAtPos | ( | uint32_t | pos = 0 |
) | [virtual] |
Returns the value of the data item stored at position pos.
| pos | position in data storage map |
Definition at line 102 of file P2pnsCache.cc.
Referenced by updateTooltip().
00103 { 00104 if (pos >= cache.size()) { 00105 error("Index out of bound (P2pnsCache, getDataAtPos())"); 00106 } 00107 00108 std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.begin(); 00109 for (uint32_t i= 0; i < pos; i++) { 00110 it++; 00111 if (i == (pos-1)) 00112 return it->second.value; 00113 } 00114 return it->second.value; 00115 }
| void P2pnsCache::addData | ( | BinaryValue | name, | |
| BinaryValue | value, | |||
| cMessage * | ttlMessage = NULL | |||
| ) | [virtual] |
Store a new data item in the map.
| name | The name of the data item to be stored | |
| value | The value of the data item to be stored | |
| ttlMessage | The self-message sent for the ttl expiration |
Definition at line 118 of file P2pnsCache.cc.
Referenced by P2pns::handleDHTgetCAPIResponse(), and P2pns::p2pnsRegisterRpc().
00119 { 00120 P2pnsCacheEntry entry; 00121 entry.value = value; 00122 entry.ttlMessage = ttlMessage; 00123 // replace with new value 00124 cache.erase(name); 00125 cache.insert(make_pair(name, entry)); 00126 }
| void P2pnsCache::removeData | ( | const BinaryValue & | name | ) | [virtual] |
Removes a certain data item from the map.
| name | The name of the data item to be removed |
Definition at line 128 of file P2pnsCache.cc.
00129 { 00130 cache.erase(name); 00131 }
| void P2pnsCache::display | ( | ) |
Definition at line 170 of file P2pnsCache.cc.
00171 { 00172 cout << "Content of P2pnsCache:" << endl; 00173 for (std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.begin(); 00174 it != cache.end(); it++) { 00175 cout << "name: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->getArrivalTime() << endl; 00176 } 00177 }
| void P2pnsCache::updateDisplayString | ( | ) | [protected] |
Updates the display string.
Definition at line 133 of file P2pnsCache.cc.
00134 { 00135 // FIXME: doesn't work without tcl/tk 00136 //if (ev.isGUI()) { 00137 if (1) { 00138 char buf[80]; 00139 00140 if (cache.size() == 1) { 00141 sprintf(buf, "1 data item"); 00142 } else { 00143 sprintf(buf, "%zi data items", cache.size()); 00144 } 00145 00146 getDisplayString().setTagArg("t", 0, buf); 00147 getDisplayString().setTagArg("t", 2, "blue"); 00148 } 00149 00150 }
| void P2pnsCache::updateTooltip | ( | ) | [protected] |
Updates the tooltip.
Definition at line 152 of file P2pnsCache.cc.
00153 { 00154 if (ev.isGUI()) { 00155 std::stringstream str; 00156 for (uint32_t i = 0; i < cache.size(); i++) { 00157 str << getDataAtPos(i); 00158 00159 if ( i != cache.size() - 1 ) 00160 str << endl; 00161 } 00162 00163 00164 char buf[1024]; 00165 sprintf(buf, "%s", str.str().c_str()); 00166 getDisplayString().setTagArg("tt", 0, buf); 00167 } 00168 }
std::map<BinaryValue, P2pnsCacheEntry> P2pnsCache::cache [protected] |
internal representation of the cache
Definition at line 127 of file P2pnsCache.h.
Referenced by addData(), clear(), display(), getData(), getDataAtPos(), getSize(), getTtlMessage(), initialize(), isEmpty(), removeData(), updateDisplayString(), and updateTooltip().
1.5.5