Skip to content

Commit

Permalink
make Veins compatible with OMNeT++ 5
Browse files Browse the repository at this point in the history
  • Loading branch information
sommer committed Mar 22, 2016
1 parent 89c8a10 commit 12c71ce
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/veins/base/connectionManager/ChannelAccess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ simtime_t ChannelAccess::calculatePropagationDelay(const NicEntry* nic) {
return receiverPos.distance(sendersPos) / BaseWorldUtility::speedOfLight();
}

void ChannelAccess::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj)
void ChannelAccess::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject* details)
{
if(signalID == mobilityStateChangedSignal) {
ChannelMobilityPtrType const mobility = check_and_cast<ChannelMobilityPtrType>(obj);
Expand Down
2 changes: 1 addition & 1 deletion src/veins/base/connectionManager/ChannelAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class MIXIM_API ChannelAccess : public BatteryAccess, protected ChannelMobilityA
* ChannelAccess is subscribed to position changes and informs the
* ConnectionManager.
*/
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj);
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject* details);

/**
* @brief Returns the host's mobility module.
Expand Down
2 changes: 1 addition & 1 deletion src/veins/base/modules/BaseMacLayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void BaseMacLayer::handleLowerControl(cMessage* msg)
}
}

Signal* BaseMacLayer::createSignal(simtime_t_cref start, simtime_t_cref length, double power, double bitrate)
Signal* BaseMacLayer::createSimpleSignal(simtime_t_cref start, simtime_t_cref length, double power, double bitrate)
{
simtime_t end = start + length;
//create signal with start at current simtime and passed length
Expand Down
6 changes: 3 additions & 3 deletions src/veins/base/modules/BaseMacLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,21 @@ class MIXIM_API BaseMacLayer : public BaseLayer
* transmission-power is still zero at the exact start and end.
* Please see the method MappingUtils::addDiscontinuity for the reason.
*/
virtual Signal* createSignal(simtime_t_cref start, simtime_t_cref length, double power, double bitrate);
virtual Signal* createSimpleSignal(simtime_t_cref start, simtime_t_cref length, double power, double bitrate);

/**
* @brief Creates a simple Mapping with a constant curve
* progression at the passed value.
*
* Used by "createSignal" to create the bitrate mapping.
* Used by "createSimpleSignal" to create the bitrate mapping.
*/
Mapping* createConstantMapping(simtime_t_cref start, simtime_t_cref end, Argument::mapped_type_cref value);

/**
* @brief Creates a simple Mapping with a constant curve
* progression at the passed value and discontinuities at the boundaries.
*
* Used by "createSignal" to create the power mapping.
* Used by "createSimpleSignal" to create the power mapping.
*/
Mapping* createRectangleMapping(simtime_t_cref start, simtime_t_cref end, Argument::mapped_type_cref value);

Expand Down
2 changes: 1 addition & 1 deletion src/veins/base/modules/BaseModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void BaseModule::initialize(int stage) {
}
}

void BaseModule::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj) {
void BaseModule::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject* details) {
Enter_Method_Silent();
if (signalID == catHostStateSignal) {
const HostState *const pHostState = dynamic_cast<const HostState *const>(obj);
Expand Down
6 changes: 5 additions & 1 deletion src/veins/base/modules/BaseModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ class MIXIM_API BaseModule: public cSimpleModule, public cListener {
* In this base class just handle the host state switching and
* some debug notifications
*/
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj);
using cListener::receiveSignal;
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject* details);
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj) {
receiveSignal(source, signalID, obj, 0);
}
};

#endif
2 changes: 1 addition & 1 deletion src/veins/base/utils/FindModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FindModule
static T findSubModule(const cModule *const top)
{
for (cModule::SubmoduleIterator i(top); !i.end(); i++) {
cModule *const sub = i();
cModule *const sub = SUBMODULE_ITERATOR_TO_MODULE(i);
// this allows also a return type of read only pointer: const cModule *const
T dCastRet = dynamic_cast<T>(sub);
if (dCastRet != NULL)
Expand Down
8 changes: 8 additions & 0 deletions src/veins/base/utils/MiXiMDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ inline bool hasGUI() {return cSimulation::getActiveEnvir()->isGUI();}
#define SIMTIME_MAX MAXTIME
#endif

// Around OMNeT++ 5, SubmoduleIterator changed from using () to * to get the module
#if OMNETPP_VERSION < 0x500
#define SUBMODULE_ITERATOR_TO_MODULE(x) x()
#else
#define SUBMODULE_ITERATOR_TO_MODULE(x) *x
#endif


#if defined(MIXIM_EXPORT)
# define MIXIM_API OPP_DLLEXPORT
#elif defined(MIXIM_IMPORT)
Expand Down
2 changes: 1 addition & 1 deletion src/veins/modules/analogueModel/NakagamiFading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void NakagamiFading::filterSignal(AirFrame *frame, const Coord& senderPos, const
}

// calculate average RX power
double recvPower_mW = gamma_d(m, sendPower_mW/1000 / m) * 1000.0;
double recvPower_mW = (RNGCONTEXT gamma_d(m, sendPower_mW/1000 / m)) * 1000.0;
if (recvPower_mW > sendPower_mW) {
recvPower_mW = sendPower_mW;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ WaveShortMessage* BaseWaveApplLayer::prepareWSM(std::string name, int lengthBit
return wsm;
}

void BaseWaveApplLayer::receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj) {
void BaseWaveApplLayer::receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj, cObject* details) {
Enter_Method_Silent();
if (signalID == mobilityStateChangedSignal) {
handlePositionUpdate(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BaseWaveApplLayer : public BaseApplLayer {
virtual void initialize(int stage);
virtual void finish();

virtual void receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj);
virtual void receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj, cObject* details);

enum WaveApplMessageKinds {
SERVICE_PROVIDER = LAST_BASE_APPL_MESSAGE_KIND,
Expand Down
2 changes: 1 addition & 1 deletion src/veins/modules/application/traci/TraCIDemo11p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void TraCIDemo11p::sendMessage(std::string blockedRoadId) {
wsm->setWsmData(blockedRoadId.c_str());
sendWSM(wsm);
}
void TraCIDemo11p::receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj) {
void TraCIDemo11p::receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj, cObject* details) {
Enter_Method_Silent();
if (signalID == mobilityStateChangedSignal) {
handlePositionUpdate(obj);
Expand Down
2 changes: 1 addition & 1 deletion src/veins/modules/application/traci/TraCIDemo11p.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using Veins::AnnotationManager;
class TraCIDemo11p : public BaseWaveApplLayer {
public:
virtual void initialize(int stage);
virtual void receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj);
virtual void receiveSignal(cComponent* source, simsignal_t signalID, cObject* obj, cObject* details);
protected:
TraCIMobility* mobility;
TraCICommandInterface* traci;
Expand Down
2 changes: 1 addition & 1 deletion src/veins/modules/application/traci/TraCITestApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void TraCITestApp::handleLowerMsg(cMessage* msg) {
delete msg;
}

void TraCITestApp::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj) {
void TraCITestApp::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject* details) {
if (signalID == mobilityStateChangedSignal) {
handlePositionUpdate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/veins/modules/application/traci/TraCITestApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TraCITestApp : public BaseApplLayer {
void handleSelfMsg(cMessage*);
void handleLowerMsg(cMessage*);

void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj);
void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject* details);

void handlePositionUpdate();
};
Expand Down
28 changes: 14 additions & 14 deletions src/veins/modules/mobility/traci/TraCIScenarioManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TraCIScenarioManager::TypeMapping TraCIScenarioManager::parseMappings(std::strin
//and check that there exists at least one
if (typeMappings.size() == 0) {
if (!allowEmpty)
opp_error("parameter \"%s\" is empty", parameterName.c_str());
throw cRuntimeError("parameter \"%s\" is empty", parameterName.c_str());
else
return map;
}
Expand All @@ -101,7 +101,7 @@ TraCIScenarioManager::TypeMapping TraCIScenarioManager::parseMappings(std::strin
//"a b=c": this is not
if (typeMappings.size() != 1)
//stop simulation with an error
opp_error("parameter \"%s\" includes multiple mappings, but \"%s\" is not mapped to any vehicle type", parameterName.c_str(), mapping[0].c_str());
throw cRuntimeError("parameter \"%s\" includes multiple mappings, but \"%s\" is not mapped to any vehicle type", parameterName.c_str(), mapping[0].c_str());
else
//all vehicle types should be instantiated with this module type
map["*"] = mapping[0];
Expand All @@ -110,10 +110,10 @@ TraCIScenarioManager::TypeMapping TraCIScenarioManager::parseMappings(std::strin

//check that mapping is valid (a=b and not like a=b=c)
if (mapping.size() != 2)
opp_error("invalid syntax for mapping \"%s\" for parameter \"%s\"", typeMapping.c_str(), parameterName.c_str());
throw cRuntimeError("invalid syntax for mapping \"%s\" for parameter \"%s\"", typeMapping.c_str(), parameterName.c_str());
//check that the mapping does not already exist
if (map.find(mapping[0]) != map.end())
opp_error("duplicated mapping for vehicle type \"%s\" for parameter \"%s\"", mapping[0].c_str(), parameterName.c_str());
throw cRuntimeError("duplicated mapping for vehicle type \"%s\" for parameter \"%s\"", mapping[0].c_str(), parameterName.c_str());

//finally save the mapping
map[mapping[0]] = mapping[1];
Expand Down Expand Up @@ -164,7 +164,7 @@ void TraCIScenarioManager::parseModuleTypes() {
std::back_inserter(intersection)
);
if (intersection.size() != typeKeys.size() || intersection.size() != nameKeys.size())
opp_error("keys of mappings of moduleType and moduleName are not the same");
throw cRuntimeError("keys of mappings of moduleType and moduleName are not the same");

if (displayStringKeys.size() == 0)
return;
Expand All @@ -176,7 +176,7 @@ void TraCIScenarioManager::parseModuleTypes() {
std::back_inserter(intersection)
);
if (intersection.size() != displayStringKeys.size())
opp_error("keys of mappings of moduleType and moduleName are not the same");
throw cRuntimeError("keys of mappings of moduleType and moduleName are not the same");

}

Expand Down Expand Up @@ -432,7 +432,7 @@ void TraCIScenarioManager::addModule(std::string nodeId, std::string type, std::

// pre-initialize TraCIMobility
for (cModule::SubmoduleIterator iter(mod); !iter.end(); iter++) {
cModule* submod = iter();
cModule* submod = SUBMODULE_ITERATOR_TO_MODULE(iter);
ifInetTraCIMobilityCallPreInitialize(submod, nodeId, position, road_id, speed, angle);
TraCIMobility* mm = dynamic_cast<TraCIMobility*>(submod);
if (!mm) continue;
Expand All @@ -444,7 +444,7 @@ void TraCIScenarioManager::addModule(std::string nodeId, std::string type, std::

// post-initialize TraCIMobility
for (cModule::SubmoduleIterator iter(mod); !iter.end(); iter++) {
cModule* submod = iter();
cModule* submod = SUBMODULE_ITERATOR_TO_MODULE(iter);
TraCIMobility* mm = dynamic_cast<TraCIMobility*>(submod);
if (!mm) continue;
mm->changePosition();
Expand Down Expand Up @@ -686,7 +686,7 @@ void TraCIScenarioManager::processSimSubscription(std::string objectId, TraCIBuf

cModule* mod = getManagedModule(idstring);
for (cModule::SubmoduleIterator iter(mod); !iter.end(); iter++) {
cModule* submod = iter();
cModule* submod = SUBMODULE_ITERATOR_TO_MODULE(iter);
TraCIMobility* mm = dynamic_cast<TraCIMobility*>(submod);
if (!mm) continue;
mm->changeParkingState(true);
Expand All @@ -706,7 +706,7 @@ void TraCIScenarioManager::processSimSubscription(std::string objectId, TraCIBuf

cModule* mod = getManagedModule(idstring);
for (cModule::SubmoduleIterator iter(mod); !iter.end(); iter++) {
cModule* submod = iter();
cModule* submod = SUBMODULE_ITERATOR_TO_MODULE(iter);
TraCIMobility* mm = dynamic_cast<TraCIMobility*>(submod);
if (!mm) continue;
mm->changeParkingState(false);
Expand Down Expand Up @@ -852,23 +852,23 @@ void TraCIScenarioManager::processVehicleSubscription(std::string objectId, TraC
if (iType == moduleType.end()) {
iType = moduleType.find("*");
if (iType == moduleType.end())
opp_error("cannot find a module type for vehicle type \"%s\"", vType.c_str());
throw cRuntimeError("cannot find a module type for vehicle type \"%s\"", vType.c_str());
}
mType = iType->second;
//search for module name
iName = moduleName.find(vType);
if (iName == moduleName.end()) {
iName = moduleName.find(std::string("*"));
if (iName == moduleName.end())
opp_error("cannot find a module name for vehicle type \"%s\"", vType.c_str());
throw cRuntimeError("cannot find a module name for vehicle type \"%s\"", vType.c_str());
}
mName = iName->second;
if (moduleDisplayString.size() != 0) {
iDisplayString = moduleDisplayString.find(vType);
if (iDisplayString == moduleDisplayString.end()) {
iDisplayString = moduleDisplayString.find("*");
if (iDisplayString == moduleDisplayString.end())
opp_error("cannot find a module display string for vehicle type \"%s\"", vType.c_str());
throw cRuntimeError("cannot find a module display string for vehicle type \"%s\"", vType.c_str());
}
mDisplayString = iDisplayString->second;
}
Expand All @@ -883,7 +883,7 @@ void TraCIScenarioManager::processVehicleSubscription(std::string objectId, TraC
} else {
// module existed - update position
for (cModule::SubmoduleIterator iter(mod); !iter.end(); iter++) {
cModule* submod = iter();
cModule* submod = SUBMODULE_ITERATOR_TO_MODULE(iter);
ifInetTraCIMobilityCallNextPosition(submod, p, edge, speed, angle);
TraCIMobility* mm = dynamic_cast<TraCIMobility*>(submod);
if (!mm) continue;
Expand Down
10 changes: 5 additions & 5 deletions src/veins/modules/obstacle/ObstacleControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void ObstacleControl::handleSelfMsg(cMessage *msg) {
void ObstacleControl::addFromXml(cXMLElement* xml) {
std::string rootTag = xml->getTagName();
if (rootTag != "obstacles") {
opp_error("Obstacle definition root tag was \"%s\", but expected \"obstacles\"", rootTag.c_str());
throw cRuntimeError("Obstacle definition root tag was \"%s\", but expected \"obstacles\"", rootTag.c_str());
}

cXMLElementList list = xml->getChildren();
Expand Down Expand Up @@ -121,7 +121,7 @@ void ObstacleControl::addFromXml(cXMLElement* xml) {
add(obs);
}
else {
opp_error("Found unknown tag in obstacle definition: \"%s\"", tag.c_str());
throw cRuntimeError("Found unknown tag in obstacle definition: \"%s\"", tag.c_str());
}


Expand All @@ -131,7 +131,7 @@ void ObstacleControl::addFromXml(cXMLElement* xml) {

void ObstacleControl::addFromTypeAndShape(std::string id, std::string typeId, std::vector<Coord> shape) {
if (!isTypeSupported(typeId)) {
opp_error("Unsupported obstacle type: \"%s\"", typeId.c_str());
throw cRuntimeError("Unsupported obstacle type: \"%s\"", typeId.c_str());
}
Obstacle obs(id, typeId, getAttenuationPerCut(typeId), getAttenuationPerMeter(typeId));
obs.setShape(shape);
Expand Down Expand Up @@ -183,10 +183,10 @@ double ObstacleControl::calculateAttenuation(const Coord& senderPos, const Coord
Enter_Method_Silent();

if ((perCut.size() == 0) || (perMeter.size() == 0)) {
opp_error("Unable to use SimpleObstacleShadowing: No obstacle types have been configured");
throw cRuntimeError("Unable to use SimpleObstacleShadowing: No obstacle types have been configured");
}
if (obstacles.size() == 0) {
opp_error("Unable to use SimpleObstacleShadowing: No obstacles have been added");
throw cRuntimeError("Unable to use SimpleObstacleShadowing: No obstacles have been added");
}

// return cached result, if available
Expand Down
Loading

0 comments on commit 12c71ce

Please sign in to comment.