OverSim
Scribe.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
25 #ifndef __SCRIBE_H_
26 #define __SCRIBE_H_
27 
28 #include <map>
29 #include <string>
30 
31 #include "BaseApp.h"
32 #include "CommonMessages_m.h"
33 #include "GlobalNodeList.h"
34 #include "NodeHandle.h"
35 
36 #include "ScribeGroup.h"
37 #include "ScribeMessage_m.h"
38 
39 // Output function for grouplist, needed for WATCH
40 std::ostream& operator<< (std::ostream& o, std::map<OverlayKey, ScribeGroup> m )
41 {
42  for (std::map<OverlayKey, ScribeGroup>::iterator it = m.begin(); it != m.end(); ++it) {
43  o << it->first << "\n";
44  o << " Parent: " << it->second.getParent() << "\n";
45  o << " Status: " << (it->second.getSubscription() ? "Subscriber\n" : "Forwarder\n");
46  o << " Children (" << it->second.numChildren() << "):\n";
47  std::set<NodeHandle>::iterator iit = it->second.getChildrenBegin();
48  for (int i = it->second.numChildren(); i > 0; --i) {
49  o << " " << *iit << "\n";
50  ++iit;
51  }
52  }
53  return o;
54 }
55 
56 
57 class Scribe : public BaseApp
58 {
59  private:
60  typedef std::map<OverlayKey, ScribeGroup> GroupList;
62  typedef std::multimap<NodeHandle, ScribeTimer*> ChildTimeoutList;
64 
67 
69 
70  // statistics
71  int numJoins;
82 
83  public:
84  Scribe( );
85  ~Scribe( );
86 
87  // see BaseOverlay.h
88  virtual void initializeApp( int stage );
89 
90  virtual void handleUpperMessage( cMessage *msg );
91  virtual void handleReadyMessage( CompReadyMessage* msg );
92 
93  virtual void handleTimerEvent( cMessage *msg );
94 
95  virtual bool handleRpcCall( BaseCallMessage* msg );
96  virtual void handleRpcResponse( BaseResponseMessage* msg,
97  cPolymorphic* context,
98  int rpcId, simtime_t rtt );
99 
100  virtual void forward(OverlayKey* key, cPacket** msg,
101  NodeHandle* nextHopNode);
102 
103  virtual void deliver(OverlayKey& key, cMessage* msg);
104  virtual void update( const NodeHandle& node, bool joined );
105 
106  virtual void finishApp( );
107 
108  protected:
112  void handleJoinResponse( ScribeJoinResponse* joinResponse );
113 
121  void handleJoinCall( ScribeJoinCall* joinMsg);
122 
129  void handlePublishCall( ScribePublishCall* publishCall );
130 
137  void handlePublishResponse( ScribePublishResponse* publishResponse );
138 
142  void handleJoinMessage( ScribeJoinCall* joinMsg, bool amIRoot);
143 
147  void handleLeaveMessage( ScribeLeaveMessage* leaveMsg );
148 
154  void subscribeToGroup( const OverlayKey& groupId );
155 
161  void leaveGroup( const OverlayKey& group );
162 
170  void startTimer( ScribeTimer* timer );
171 
175  void addChildToGroup( const NodeHandle& child, ScribeGroup& group );
176 
180  void removeChildFromGroup( const NodeHandle& child, ScribeGroup& group );
181 
188  void removeChildFromGroup( ScribeTimer* timer );
189 
193  void checkGroupEmpty( ScribeGroup& group );
194 
201  void refreshChildTimer( NodeHandle& child, OverlayKey& groupId );
202 
206  void deliverALMDataToGroup( ScribeDataMessage* dataMsg );
207 
214  void deliverALMDataToRoot( ALMMulticastMessage* mcastMsg );
215 };
216 
217 #endif