cristinik
cristinik

Reputation: 143

OMNeT++ TicToc extension string message

I am starting with OMNeT++ and C++ by going through the TicToc tutorial.

I would now like to make a modification on the behavior of one of the submodules Tic or Toc, specifically in handleMessage().

Currently, messages are handled by forwarding the received message to the other submodule without any manipulation of the message. Now, I would like to change this so that Tic checks the incoming message's string and if the value is "String 1" then if will generate a new message with string value "String 2" and send it to Toc.

However when I do this I get and error "comparison between distinct pointer types 'cMessage' and 'const char*' lacks a cast.

This is the code:

void Tic::handleMessage(cMessage *msg)
{
    if (msg == "String 1")
    {
       cMessage *msg2 = new cMessage ("String 2");
       send(msg2,"out");
    }
}

Any help is appreciated. Thanks.

Upvotes: 2

Views: 1459

Answers (2)

cristinik
cristinik

Reputation: 143

I found the solution:

if (strcmp("String 1", msg->getName())==0)
{}

Upvotes: 3

sehe
sehe

Reputation: 392929

We know very little about cMessage, but perhaps you meant

if (*msg == "String 1")

Because that would compare the value of the cMessage object pointer-to by msg (a pointer), to the string literal value.

As you had it, you try to compare a pointer to a sting literal (which decays to char const* in this context), which makes no sense (see also How to compare pointers?).


Update Upon reading more here http://www.omnetpp.org/doc/omnetpp/api/index.html it doesn't look like the above would work.

In fact, you might want to read some of the member properties (info, detailed info, encapsulated cPacket etc.) in order to inspect the message

Upvotes: 0

Related Questions