Q:

How to access the submodule name in omnet++?

For example, I define the module Sample in .ned file as follow.
simple Sample
{
    parameters:
        @display(...);
    gates:
        inout InOut;
}

And then I define two submodules as follow.
S1: Sample {
     @display(...);
}
S2: Sample {
     @display(...);
}

in .cc file, I define the class Sample as follow.
class Sample: public cSimpleModule
{
  protected:
    virtual void handleMessage(cMessage *msg) override;
};

Now, how can I access the submodule name in the function handleMessage?
For example, I need the following code.
void Sample::handleMessage(cMessage *msg)
{
    if(strcmp("S1", this->getSubModuleName()) == 0){
        ...
    }
}

A:

To obtain the name of current object (i.e. module, submodule) use getName(). However, to check whether the name is equal to a given string one may use convenient method isName(), for example:
if (isName("S1")) {
    // name is "S1"
}

Reference: OMNeT++ API

