OverSim
BaseApp.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 
24 #ifndef __BASEAPP_H_
25 #define __BASEAPP_H_
26 
27 //class GlobalNodeList;
28 class GlobalStatistics;
30 class NodeHandle;
31 class OverlayKey;
32 class CommonAPIMessage;
33 
34 #include <omnetpp.h>
35 
36 #include "NodeVector.h"
37 #include <BaseRpc.h>
38 #include <BaseTcpSupport.h>
39 #include <INotifiable.h>
40 #include <BaseOverlay.h>
41 
42 
76 class BaseApp : public INotifiable, public BaseRpc, public BaseTcpSupport
77 {
78 private:
79 
89  void forwardResponse(const OverlayKey& key, cPacket* msg,
90  const NodeHandle& nextHopNode);
91 
102  void handleCommonAPIMessage(CommonAPIMessage* commonAPIMsg);
103 
104 protected:
108  int numInitStages() const;
109 
115  void initialize(int stage);
116 
122  virtual void initializeApp(int stage);
123 
132  void handleMessage(cMessage* msg);
133 
140  virtual void receiveChangeNotification(int category, const cPolymorphic * details);
141 
147 
151  virtual void handleNodeLeaveNotification();
152 
158 
162  void finish();
163 
167  virtual void finishApp();
168 
169  // common API for structured p2p-overlays
181  inline void callRoute(const OverlayKey& key, cPacket* msg,
182  const TransportAddress& hint
184  RoutingType routingType = DEFAULT_ROUTING)
185  {
186  std::vector<TransportAddress> sourceRoute;
187  sourceRoute.push_back(hint);
188  callRoute(key, msg, sourceRoute, routingType);
189  }
190 
191  void callRoute(const OverlayKey& key, cPacket* msg,
192  const std::vector<TransportAddress>& sourceRoute,
193  RoutingType routingType = DEFAULT_ROUTING);
194 
203  virtual void deliver(OverlayKey& key, cMessage* msg);
204 
214  virtual void forward(OverlayKey* key, cPacket** msg,
215  NodeHandle* nextHopNode);
216 
223  virtual void update(const NodeHandle& node, bool joined);
224 
233  inline NodeVector* callLocalLookup(const OverlayKey& key, int num,
234  bool safe)
235  {
236  return overlay->local_lookup(key, num, safe);
237  };
238 
244  inline NodeVector* callNeighborSet(int num)
245  {
246  return overlay->neighborSet(num);
247  };
248 
264  inline bool isSiblingFor(const NodeHandle& node, const OverlayKey& key,
265  int numSiblings, bool* err)
266  {
267  return overlay->isSiblingFor(node, key, numSiblings, err);
268  };
269 
277  //virtual void handleTimerEvent(cMessage* msg);
278 
284  virtual void handleLowerMessage(cMessage* msg);
285 
293  virtual void handleUpperMessage(cMessage* msg);
294 
300  virtual void handleUDPMessage(cMessage* msg);
301 
307  virtual void handleReadyMessage(CompReadyMessage* msg);
308 
312  virtual void bindToPort(int port);
313 
317  virtual void sendMessageToUDP(const TransportAddress& destAddr,
318  cPacket *msg,
319  simtime_t delay = SIMTIME_ZERO);
320 
328  virtual void handleTraceMessage(cMessage* msg);
329 
335  void sendMessageToLowerTier(cPacket* msg);
336 
346  NotificationBoard* notificationBoard;
349  // parameters
350  bool debugOutput;
352  // statistics
362  simtime_t creationTime;
364 public:
365 
366  BaseApp();
367 
371  virtual ~BaseApp();
372 
373 
374 
375 protected://methods: rpc handling
378  cPolymorphic* context, int rpcId,
379  simtime_t rtt);
380 
381  void internalSendRouteRpc(BaseRpcMessage* message,
382  const OverlayKey& destKey,
383  const std::vector<TransportAddress>&
384  sourceRoute,
385  RoutingType routingType);
386 
387  virtual CompType getThisCompType();
388  void sendReadyMessage(bool ready = true,
389  const OverlayKey& nodeId =
391 
392 private:
394  BaseResponseMessage* response);
395 };
396 
397 #endif