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 #include <NodeVector.h>
00038 #include <CommonMessages_m.h>
00039 
00049 typedef std::map<BinaryValue, NodeVector> SiblingVoteMap;
00050 
00051 struct DhtDataEntry
00052 {
00053     BinaryValue value;
00054     uint32_t kind;
00055     uint32_t id;
00056     cMessage* ttlMessage;
00057     bool is_modifiable;
00058     NodeHandle sourceNode;
00059     bool responsible; //is this node responsible for this key ?
00060     friend std::ostream& operator<<(std::ostream& Stream, const DhtDataEntry entry);
00061     SiblingVoteMap siblingVote;
00062 };
00063 
00064 typedef std::vector<std::pair<OverlayKey, DhtDataEntry> > DhtDataVector;
00065 typedef std::vector<DhtDumpEntry> DhtDumpVector;
00066 typedef std::multimap<OverlayKey, DhtDataEntry> DhtDataMap;
00067 
00068 class DHTDataStorage : public cSimpleModule
00069 {
00070   public:
00071 
00072     virtual int numInitStages() const
00073     {
00074         return MAX_STAGE_APP + 1;
00075     }
00076     virtual void initialize(int stage);
00077     virtual void handleMessage(cMessage* msg);
00078 
00084     virtual uint32_t getSize();
00085 
00089     virtual void clear();
00090 
00100     DhtDataEntry* getDataEntry(const OverlayKey& key,
00101                                uint32_t kind, uint32_t id);
00102 
00103 
00113     virtual DhtDataVector* getDataVector(const OverlayKey& key,
00114                                          uint32_t kind = 0,
00115                                          uint32_t id = 0);
00116 
00126     virtual const NodeHandle& getSourceNode(const OverlayKey& key,
00127                                             uint32_t kind, uint32_t id);
00128 
00137     virtual const bool isModifiable(const OverlayKey& key,
00138                                     uint32_t kind, uint32_t id);
00139 
00145     virtual const DhtDataMap::iterator begin();
00146 
00152     virtual const DhtDataMap::iterator end();
00153 
00154 
00167     virtual DhtDataEntry* addData(const OverlayKey& key, uint32_t kind,
00168                                   uint32_t id,
00169                                   BinaryValue value, cMessage* ttlMessage,
00170                                   bool is_modifiable=true,
00171                                   NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE,
00172                                   bool responsible=true);
00173 
00182     virtual void removeData(const OverlayKey& key, uint32_t kind, uint32_t id);
00183 
00184     void display();
00185 
00195     DhtDumpVector* dumpDht(const OverlayKey& key = OverlayKey::UNSPECIFIED_KEY,
00196                            uint32_t kind = 0, uint32_t id = 0);
00197 
00198   protected:
00199     DhtDataMap dataMap; 
00204     void updateDisplayString();
00205 
00209     void updateTooltip();
00210 };
00211 
00212 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3