I don't know whether I don't get the logic behind adding a function to eclipse/omnet++: Tried to simply add a new function "init_func" to the VeinsInetSampleApplication.h Header file
#pragma once
#include "veins_inet.h"
#include "VeinsInetApplicationBase.h"
class VEINS_INET_API VeinsInetSampleApplication : public veins::VeinsInetApplicationBase {
protected:
bool haveForwarded = false;
protected:
virtual bool startApplication() override;
virtual bool stopApplication() override;
virtual void processPacket(std::shared_ptr<inet::Packet> pk) override;
// ADAPTION 2022/05/28
virtual void init_func();
public:
VeinsInetSampleApplication();
~VeinsInetSampleApplication();
};
However when I simply copy the initialization code of the startApplication() function into "init_func()" in VeinsInetSampleApplication.cc "init_func()" is simply ignored by my simulation.
Here's the code snippet which basically shall send a message to all my simulation nodes at time t=5 sec. The only difference to the startApplication() function is that the message sending is triggered at t=5sec. and not at t=10sec. The startApplication() function does its job correctly and even if i comment it out and only make my init_func() function run it is also ignored. (I tried this in order to rule out any issues with the "this" pointer etc. which would suggest there is a "bad interaction" between both functions). So it really seems like my init_func() is not registered. But I don't know. Does anybody have an idea why "init_func()" might be ignored here by Omnet++?
Code of init_func():
void VeinsInetSampleApplication::init_func()
{
// host[0] should stop at t=5s, change in timerManger.create(...)
if (getParentModule()->getIndex() == 0) {
auto callback = [this]() {
getParentModule()->getDisplayString().setTagArg("i", 1, "red");
traciVehicle->setSpeed(0);
auto payload = makeShared<VeinsInetSampleMessage>();
timestampPayload(payload);
payload->setChunkLength(B(100));
payload->setRoadId(traciVehicle->getRoadId().c_str());
auto packet = createPacket("accident");
packet->insertAtBack(payload);
sendPacket(std::move(packet));
};
timerManager.create(veins::TimerSpecification(callback).oneshotAt(SimTime(5, SIMTIME_S)));
}
}
(I also changed return type of "init_func" to bool to further increase similarity. But that of course was also not successful)
Best regards, Lukas