DHTDataStorage.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #ifndef __DHTDATASTORAGE_H_
00025 #define __DHTDATASTORAGE_H_
00026 
00027 #include <set>
00028 #include <vector>
00029 #include <map>
00030 #include <sstream>
00031 
00032 #include <omnetpp.h>
00033 
00034 #include <NodeHandle.h>
00035 #include <InitStages.h>
00036 #include <BinaryValue.h>
00037 
00038 #include <CommonMessages_m.h>
00039 
00050 struct DhtDataEntry
00051 {
00052     BinaryValue value;
00053     uint32_t kind;
00054     uint32_t id;
00055     cMessage* ttlMessage;
00056     bool is_modifiable;
00057     NodeHandle sourceNode;
00058     bool responsible; //is this node responsible for this key ?
00059     friend std::ostream& operator<<(std::ostream& Stream, const DhtDataEntry entry);
00060 };
00061 
00062 typedef std::vector<std::pair<OverlayKey, DhtDataEntry> > DhtDataVector;
00063 typedef std::vector<DhtDumpEntry> DhtDumpVector;
00064 typedef std::multimap<OverlayKey, DhtDataEntry> DhtDataMap;
00065 
00066 class DHTDataStorage : public cSimpleModule
00067 {
00068   public:
00069 
00070     virtual int numInitStages() const
00071     {
00072         return MAX_STAGE_APP + 1;
00073     }
00074     virtual void initialize(int stage);
00075     virtual void handleMessage(cMessage* msg);
00076 
00082     virtual uint32_t getSize();
00083 
00087     virtual void clear();
00088 
00098     DhtDataEntry* getDataEntry(const OverlayKey& key,
00099                                uint32_t kind, uint32_t id);
00100 
00101 
00111     virtual DhtDataVector* getDataVector(const OverlayKey& key,
00112                                          uint32_t kind = 0,
00113                                          uint32_t id = 0);
00114 
00124     virtual const NodeHandle& getSourceNode(const OverlayKey& key,
00125                                             uint32_t kind, uint32_t id);
00126 
00135     virtual const bool isModifiable(const OverlayKey& key,
00136                                     uint32_t kind, uint32_t id);
00137 
00143     virtual const DhtDataMap::iterator begin();
00144 
00157     virtual void addData(const OverlayKey& key, uint32_t kind, uint32_t id,
00158                          BinaryValue value, cMessage* ttlMessage,
00159                          bool is_modifiable=true,
00160                          NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE,
00161                          bool responsible=true);
00162 
00171     virtual void removeData(const OverlayKey& key, uint32_t kind, uint32_t id);
00172 
00173     void display();
00174 
00184     DhtDumpVector* dumpDht(const OverlayKey& key = OverlayKey::UNSPECIFIED_KEY,
00185                            uint32_t kind = 0, uint32_t id = 0);
00186 
00187   protected:
00188     DhtDataMap dataMap; 
00193     void updateDisplayString();
00194 
00198     void updateTooltip();
00199 };
00200 
00201 #endif

Generated on Tue Sep 8 17:26:52 2009 for OverSim by  doxygen 1.5.8