Signal_.h

00001 #ifndef SIGNAL_H_
00002 #define SIGNAL_H_
00003 
00004 #include <omnetpp.h>
00005 #include "Move.h"
00006 #include "Mapping.h"
00007 #include <list>
00008 
00034 class Signal {
00035 public:
00041   typedef ConcatConstMapping<std::multiplies<double> > MultipliedMapping;
00043   typedef std::list<ConstMapping*> ConstMappingList;
00044 
00045 protected:
00046 
00048   simtime_t signalStart;
00050   simtime_t signalLength;
00052   simtime_t propDelay;
00053 
00055   Move senderMovement;
00056 
00058   ConstMapping* power;
00059 
00061   Mapping* bitrate;
00062 
00064   Mapping* txBitrate;
00065 
00067   ConstMappingList attenuations;
00068 
00070   MultipliedMapping* rcvPower;
00071 
00072 protected:
00079   void markRcvPowerOutdated() {
00080     if(rcvPower){
00081       if(propDelay != 0) {
00082         assert(rcvPower->getRefMapping() != power);
00083         delete rcvPower->getRefMapping();
00084       }
00085       delete rcvPower;
00086       rcvPower = 0;
00087     }
00088   }
00089 public:
00090 
00094   Signal(simtime_t start = -1.0, simtime_t length = -1.0);
00095 
00100   Signal(const Signal& o);
00101 
00106   const Signal& operator=(const Signal& o);
00107 
00111   ~Signal();
00112 
00118   simtime_t getSignalStart() const;
00119 
00123   Move getMove() const;
00124 
00128   void setMove(Move& move);
00129 
00133   simtime_t getSignalLength() const;
00134 
00138   simtime_t getPropagationDelay() const;
00139 
00145   void setPropagationDelay(simtime_t delay);
00146 
00153   void setTransmissionPower(ConstMapping* power);
00154 
00160   void setBitrate(Mapping* bitrate);
00161 
00167   void addAttenuation(ConstMapping* att) {
00168     //assert the attenuation wasn't already added to the list before
00169     assert(std::find(attenuations.begin(), attenuations.end(), att) == attenuations.end());
00170 
00171     attenuations.push_back(att);
00172 
00173     if(rcvPower)
00174       rcvPower->addMapping(att);
00175   }
00176 
00184   ConstMapping* getTransmissionPower() {
00185     return power;
00186   }
00187 
00195   const ConstMapping* getTransmissionPower() const {
00196     return power;
00197   }
00198 
00203   Mapping* getBitrate() {
00204     return bitrate;
00205   }
00206 
00211   const ConstMappingList& getAttenuation() const {
00212     return attenuations;
00213   }
00214 
00222   MultipliedMapping* getReceivingPower() {
00223     if(!rcvPower)
00224     {
00225       ConstMapping* tmp = power;
00226       if(propDelay != 0) {
00227         tmp = new ConstDelayedMapping(power, propDelay);
00228       }
00229       rcvPower = new MultipliedMapping(tmp,
00230                         attenuations.begin(),
00231                         attenuations.end(),
00232                         false, 0.0);
00233     }
00234 
00235     return rcvPower;
00236   }
00237 };
00238 
00239 #endif /*SIGNAL_H_*/