%description: Test if ownership of a message can be manually transferred from one module to the other. Such functionality is needed for one particular project, it's rarely if ever useful for normal simulation models. %file: test.ned simple First { } simple Second { } network Test { submodules: first: First; second: Second; } %file: modules.cc #include using namespace omnetpp; namespace @TESTNAME@ { class First : public cSimpleModule { public: First() : cSimpleModule(16384) { } virtual void activity() override; }; class Second : public cSimpleModule { protected: cMessage *receivedMsg; public: Second() : cSimpleModule(16384) { } virtual void activity() override; public: void accept(cMessage *msg); // stores in 'receivedMsg' member }; Define_Module(First); Define_Module(Second); void First::activity() { Second *other = check_and_cast(getParentModule()->getSubmodule("second")); cMessage *msg = new cMessage("hello"); EV << "before: " << msg->getFullPath() << endl; EV << " owner: " << msg->getOwner()->getFullPath() << endl; other->accept(msg); EV << "after: " << msg->getFullPath() << endl; EV << " owner: " << msg->getOwner()->getFullPath() << endl; } void Second::accept(cMessage *msg) { receivedMsg = msg; take(msg); } void Second::activity() { wait(1.0); // until accept() surely takes place EV << "receivedMsg: " << receivedMsg->getFullPath() << endl; EV << " owner: " << receivedMsg->getOwner()->getFullPath() << endl; } }; //namespace %contains: stdout before: Test.first.hello owner: Test.first after: Test.second.hello owner: Test.second %contains: stdout Test.second (Second, id=3) receivedMsg: Test.second.hello owner: Test.second