ZZ1
ZZ1

Reputation: 3

In omnet++ can handleMessage handle any class other than cMessage?

I want to pass a variable of type MyPacket to handleMessage it gives error.

packet MyPacket
{  string msg;
 int srcAddress;
 int destAddress;
};

Upvotes: 0

Views: 385

Answers (1)

Jerzy D.
Jerzy D.

Reputation: 7002

Your MyPacket will be converted into a C++ class MyPacket which inhertis from cPacket. And cPacket inherits from cMessage so it will be handled by handleMessage. However, in handleMessage you have to recognize and cast your packet, for example this way:

void YourSimpleModule::handleMessage(cMessage *msg) {
   MyPacket * packet = dynamic_cast<MyPacket*> (msg);
   if (packet != nullptr) {
       // it is MyPacket
   } else {
       // other message
   } 

Upvotes: 2

Related Questions