00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef BASIC_MOBILITY_H
00024 #define BASIC_MOBILITY_H
00025
00026 #include <omnetpp.h>
00027
00028 #include "BasicModule.h"
00029 #include "ChannelControl.h"
00030 #include "Coord.h"
00031 #include "HostMove.h"
00032
00060 class BasicMobility : public BasicModule
00061 {
00062 public:
00069 enum BorderPolicy {
00070 REFLECT,
00071 WRAP,
00072 PLACERANDOMLY,
00073 RAISEERROR
00074 };
00075
00081 enum BasicMobilityMsgKinds {
00082 MOVE_HOST = 1050198237,
00083 MOVE_TO_BORDER,
00084 LAST_BASIC
00085 };
00086
00090 enum BorderHandling {
00091 NOWHERE,
00092 X_SMALLER,
00093 X_BIGGER,
00094 Y_SMALLER,
00095 Y_BIGGER
00096 };
00097
00098 protected:
00100 ChannelControl *cc;
00101
00103 cModule* hostPtr;
00104 int hostId;
00105
00107 HostMove move;
00109 int moveCategory;
00110
00112 double updateInterval;
00113
00115 cMessage* moveMsg;
00116
00118 bool coreDebug;
00119
00120 public:
00121 Module_Class_Members( BasicMobility , BasicModule , 0 );
00122
00124 void handleMessage(cMessage *msg);
00125
00127 virtual void initialize(int);
00128
00130 virtual void finish(){};
00131
00132 protected:
00134 virtual void handleSelfMsg( cMessage* );
00135
00137 virtual void handleBorderMsg( cMessage* );
00138
00148 virtual void makeMove(){
00149 error("BasicMobility does not move the host");
00150 };
00151
00153 virtual Coord getRandomPosition();
00154
00156 void updatePosition();
00157
00159 double playgroundSizeX() const {return cc->getPgs()->x;}
00160
00162 double playgroundSizeY() const {return cc->getPgs()->y;}
00163
00172
00174 bool handleIfOutside(BorderPolicy, Coord&, Coord&, Coord&, double&);
00175
00188 virtual void fixIfHostGetsOutside(){
00189 error("fixIfHostGetsOutside has to be redefined by the user");
00190 };
00191
00196 BorderHandling checkIfOutside( Coord, Coord& );
00197
00199 void goToBorder( BorderPolicy, BorderHandling, Coord&, Coord& );
00200
00205 void reflectIfOutside(BorderHandling, Coord&, Coord&, Coord&, double&);
00206
00211 void wrapIfOutside(BorderHandling, Coord&, Coord&);
00212
00217 void placeRandomlyIfOutside( Coord& );
00218
00221 };
00222
00223 #endif
00224