BaseApp.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __BASEAPP_H_
00025 #define __BASEAPP_H_
00026
00027
00028 class GlobalStatistics;
00029 class UnderlayConfigurator;
00030 class NodeHandle;
00031 class OverlayKey;
00032 class CommonAPIMessage;
00033
00034 #include <omnetpp.h>
00035
00036 #include "NodeVector.h"
00037 #include <BaseRpc.h>
00038 #include <INotifiable.h>
00039 #include <BaseOverlay.h>
00040
00041
00075 class BaseApp : public INotifiable, public BaseRpc
00076 {
00077 private:
00078
00088 void forwardResponse(const OverlayKey& key, cPacket* msg,
00089 const NodeHandle& nextHopNode);
00090
00101 void handleCommonAPIMessage(CommonAPIMessage* commonAPIMsg);
00102
00103 protected:
00107 int numInitStages() const;
00108
00114 void initialize(int stage);
00115
00121 virtual void initializeApp(int stage);
00122
00131 void handleMessage(cMessage* msg);
00132
00139 virtual void receiveChangeNotification(int category, const cPolymorphic * details);
00140
00145 virtual void handleTransportAddressChangedNotification();
00146
00150 virtual void handleNodeLeaveNotification();
00151
00156 virtual void handleNodeGracefulLeaveNotification();
00157
00161 void finish();
00162
00166 virtual void finishApp();
00167
00168
00180 inline void callRoute(const OverlayKey& key, cPacket* msg,
00181 const TransportAddress& hint
00182 = TransportAddress::UNSPECIFIED_NODE,
00183 RoutingType routingType = DEFAULT_ROUTING)
00184 {
00185 std::vector<TransportAddress> sourceRoute;
00186 sourceRoute.push_back(hint);
00187 callRoute(key, msg, sourceRoute, routingType);
00188 }
00189
00190 void callRoute(const OverlayKey& key, cPacket* msg,
00191 const std::vector<TransportAddress>& sourceRoute,
00192 RoutingType routingType = DEFAULT_ROUTING);
00193
00202 virtual void deliver(OverlayKey& key, cMessage* msg);
00203
00213 virtual void forward(OverlayKey* key, cPacket** msg,
00214 NodeHandle* nextHopNode);
00215
00222 virtual void update(const NodeHandle& node, bool joined);
00223
00232 inline NodeVector* callLocalLookup(const OverlayKey& key, int num,
00233 bool safe)
00234 {
00235 return overlay->local_lookup(key, num, safe);
00236 };
00237
00243 inline NodeVector* callNeighborSet(int num)
00244 {
00245 return overlay->neighborSet(num);
00246 };
00247
00263 inline bool isSiblingFor(const NodeHandle& node, const OverlayKey& key,
00264 int numSiblings, bool* err)
00265 {
00266 return overlay->isSiblingFor(node, key, numSiblings, err);
00267 };
00268
00276
00277
00283 virtual void handleLowerMessage(cMessage* msg);
00284
00292 virtual void handleUpperMessage(cMessage* msg);
00293
00299 virtual void handleUDPMessage(cMessage* msg);
00300
00306 virtual void handleReadyMessage(CompReadyMessage* msg);
00307
00311 virtual void bindToPort(int port);
00312
00316 virtual void sendMessageToUDP(const TransportAddress& destAddr, cPacket *msg);
00317
00325 virtual void handleTraceMessage(cMessage* msg);
00326
00332 void sendMessageToLowerTier(cPacket* msg);
00333
00334 UnderlayConfigurator* underlayConfigurator;
00337 GlobalNodeList* globalNodeList;
00340 GlobalStatistics* globalStatistics;
00343 NotificationBoard* notificationBoard;
00346
00347 bool debugOutput;
00349
00350 int numOverlaySent;
00351 int bytesOverlaySent;
00352 int numOverlayReceived;
00353 int bytesOverlayReceived;
00354 int numUdpSent;
00355 int bytesUdpSent;
00356 int numUdpReceived;
00357 int bytesUdpReceived;
00359 simtime_t creationTime;
00361 public:
00362
00363 BaseApp();
00364
00368 virtual ~BaseApp();
00369
00370
00371
00372 protected:
00373 bool internalHandleRpcCall(BaseCallMessage* msg);
00374 void internalHandleRpcResponse(BaseResponseMessage* msg,
00375 cPolymorphic* context, int rpcId,
00376 simtime_t rtt);
00377
00378 void internalSendRouteRpc(BaseRpcMessage* message,
00379 const OverlayKey& destKey,
00380 const std::vector<TransportAddress>&
00381 sourceRoute,
00382 RoutingType routingType);
00383
00384 virtual CompType getThisCompType();
00385 void sendReadyMessage(bool ready = true);
00386
00387 private:
00388 void internalSendRpcResponse(BaseCallMessage* call,
00389 BaseResponseMessage* response);
00390 };
00391
00392 #endif