BaseApp.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 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 __BASEAPP_H_
00025 #define __BASEAPP_H_
00026 
00027 //class GlobalNodeList;
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 <BaseTcpSupport.h>
00039 #include <INotifiable.h>
00040 #include <BaseOverlay.h>
00041 
00042 
00076 class BaseApp : public INotifiable, public BaseRpc, public BaseTcpSupport
00077 {
00078 private:
00079 
00089     void forwardResponse(const OverlayKey& key, cPacket* msg,
00090                          const NodeHandle& nextHopNode);
00091 
00102     void handleCommonAPIMessage(CommonAPIMessage* commonAPIMsg);
00103 
00104 protected:
00108     int numInitStages() const;
00109 
00115     void initialize(int stage);
00116 
00122     virtual void initializeApp(int stage);
00123 
00132     void handleMessage(cMessage* msg);
00133 
00140     virtual void receiveChangeNotification(int category, const cPolymorphic * details);
00141 
00146     virtual void handleTransportAddressChangedNotification();
00147 
00151     virtual void handleNodeLeaveNotification();
00152 
00157     virtual void handleNodeGracefulLeaveNotification();
00158 
00162     void finish();
00163 
00167     virtual void finishApp();
00168 
00169     // common API for structured p2p-overlays
00181     inline void callRoute(const OverlayKey& key, cPacket* msg,
00182                           const TransportAddress& hint
00183                               = TransportAddress::UNSPECIFIED_NODE,
00184                           RoutingType routingType = DEFAULT_ROUTING)
00185     {
00186         std::vector<TransportAddress> sourceRoute;
00187         sourceRoute.push_back(hint);
00188         callRoute(key, msg, sourceRoute, routingType);
00189     }
00190 
00191     void callRoute(const OverlayKey& key, cPacket* msg,
00192                    const std::vector<TransportAddress>& sourceRoute,
00193                    RoutingType routingType = DEFAULT_ROUTING);
00194 
00203     virtual void deliver(OverlayKey& key, cMessage* msg);
00204 
00214     virtual void forward(OverlayKey* key, cPacket** msg,
00215                          NodeHandle* nextHopNode);
00216 
00223     virtual void update(const NodeHandle& node, bool joined);
00224 
00233     inline NodeVector* callLocalLookup(const OverlayKey& key, int num,
00234                                        bool safe)
00235     {
00236         return overlay->local_lookup(key, num, safe);
00237     };
00238 
00244     inline NodeVector* callNeighborSet(int num)
00245     {
00246         return overlay->neighborSet(num);
00247     };
00248 
00264     inline bool isSiblingFor(const NodeHandle& node, const OverlayKey& key,
00265                              int numSiblings, bool* err)
00266     {
00267         return overlay->isSiblingFor(node, key, numSiblings, err);
00268     };
00269 
00277     //virtual void handleTimerEvent(cMessage* msg);
00278 
00284     virtual void handleLowerMessage(cMessage* msg);
00285 
00293     virtual void handleUpperMessage(cMessage* msg);
00294 
00300     virtual void handleUDPMessage(cMessage* msg);
00301 
00307     virtual void handleReadyMessage(CompReadyMessage* msg);
00308 
00312     virtual void bindToPort(int port);
00313 
00317     virtual void sendMessageToUDP(const TransportAddress& destAddr, cPacket *msg);
00318 
00326     virtual void handleTraceMessage(cMessage* msg);
00327 
00333     void sendMessageToLowerTier(cPacket* msg);
00334 
00335     UnderlayConfigurator* underlayConfigurator; 
00338     GlobalNodeList* globalNodeList; 
00341     GlobalStatistics* globalStatistics; 
00344     NotificationBoard* notificationBoard; 
00347     // parameters
00348     bool debugOutput; 
00350     // statistics
00351     int numOverlaySent; 
00352     int bytesOverlaySent; 
00353     int numOverlayReceived; 
00354     int bytesOverlayReceived; 
00355     int numUdpSent; 
00356     int bytesUdpSent; 
00357     int numUdpReceived; 
00358     int bytesUdpReceived; 
00360     simtime_t creationTime; 
00362 public:
00363 
00364     BaseApp();
00365 
00369     virtual ~BaseApp();
00370 
00371 
00372 
00373 protected://methods: rpc handling
00374     bool internalHandleRpcCall(BaseCallMessage* msg);
00375     void internalHandleRpcResponse(BaseResponseMessage* msg,
00376                                    cPolymorphic* context, int rpcId,
00377                                    simtime_t rtt);
00378 
00379     void internalSendRouteRpc(BaseRpcMessage* message,
00380                               const OverlayKey& destKey,
00381                               const std::vector<TransportAddress>&
00382                                   sourceRoute,
00383                               RoutingType routingType);
00384 
00385     virtual CompType getThisCompType();
00386     void sendReadyMessage(bool ready = true);
00387 
00388 private:
00389     void internalSendRpcResponse(BaseCallMessage* call,
00390                                  BaseResponseMessage* response);
00391 };
00392 
00393 #endif