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 <sstream>
00030 
00031 #include <omnetpp.h>
00032 
00033 #include <NodeHandle.h>
00034 #include <InitStages.h>
00035 #include <BinaryValue.h>
00036 
00047 struct DHTData
00048 {
00049     BinaryValue value;
00050     cMessage* ttlMessage;
00051     bool is_modifiable;
00052     NodeHandle sourceNode;
00053     bool responsible; //is this node responsible for this key ?
00054     friend std::ostream& operator<<(std::ostream& Stream, const DHTData entry);
00055 };
00056 
00057 struct DhtDumpEntry
00058 {
00059     OverlayKey key;
00060     BinaryValue value;
00061     int ttl;
00062     NodeHandle owner;
00063     bool is_modifiable;
00064     bool responsible;
00065 };
00066 
00067 typedef std::vector<DhtDumpEntry> DhtDumpVector;
00068 
00069 typedef std::vector<std::pair<OverlayKey, DHTData> > DhtDataVector;
00070 
00071 class DHTDataStorage : public cSimpleModule
00072 {
00073   public:
00074     virtual int numInitStages() const
00075     {
00076         return MAX_STAGE_APP + 1;
00077     }
00078     virtual void initialize(int stage);
00079     virtual void handleMessage(cMessage* msg);
00080 
00086     virtual uint32_t getSize();
00087 
00091     virtual void clear();
00092 
00098     virtual bool isEmpty();
00099 
00106     virtual const BinaryValue& getData(const OverlayKey& key);
00107 
00114     virtual const NodeHandle& getSourceNode(const OverlayKey& key);
00115 
00122     virtual cMessage* getTtlMessage(const OverlayKey& key);
00123 
00130     virtual const bool isModifiable(const OverlayKey& key);
00131 
00132 
00139     virtual const BinaryValue& getDataAtPos(uint32_t pos = 0);
00140 
00146     virtual const std::map<OverlayKey, DHTData>::iterator begin();
00147 
00158     virtual void addData(OverlayKey key, BinaryValue value, cMessage* ttlMessage, bool is_modifiable=true, NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE, bool responsible=true);
00159 
00165     virtual void removeData(OverlayKey key);
00166     void display ();
00167 
00173     DhtDataVector* get_range(const OverlayKey lkey, const OverlayKey rkey);
00174     
00180     DhtDumpVector* dumpDht();
00181 
00182   protected:
00183     std::map<OverlayKey, DHTData> dataMap; 
00188     void updateDisplayString();
00189 
00193     void updateTooltip();
00194 };
00195 
00196 #endif

Generated on Wed Mar 25 16:32:48 2009 for OverSim by  doxygen 1.5.5