c++omnet++

getDisplayString() in omnet++ doesn't change the displayed string of the message


according to omnet++ docs here, in order to change the display string of a message during the simulation, I have to override the function called getDisplayString() as they said:

◆ getDisplayString()

virtual const char* getDisplayString ( ) const

Override to define a display string for the message. Display string affects message appearance in Qtenv. This default implementation returns "".

so I did as they said and here is the code of my custom message:

class MyMsg_Base : public ::omnetpp::cPacket
{
  protected:
    uint8_t M_Header = 0;
    omnetpp::opp_string M_Payload;
    uint8_t M_Trailer = 0;
    int M_Type = 0;

  private:
    void copy(const MyMsg_Base& other);

  protected:
    bool operator==(const MyMsg_Base&) = delete;

    // make assignment operator protected to force the user override it
    MyMsg_Base& operator=(const MyMsg_Base& other);

  public:
    // make constructors protected to avoid instantiation
    MyMsg_Base(const char *name=nullptr, short kind=0);
    MyMsg_Base(const MyMsg_Base& other);

    virtual ~MyMsg_Base();
    virtual MyMsg_Base *dup() const override {return new MyMsg_Base(*this);}
    virtual void parsimPack(omnetpp::cCommBuffer *b) const override;
    virtual void parsimUnpack(omnetpp::cCommBuffer *b) override;

    virtual uint8_t getM_Header() const;
    virtual void setM_Header(uint8_t M_Header);

    virtual const char * getM_Payload() const;
    virtual void setM_Payload(const char * M_Payload);

    virtual uint8_t getM_Trailer() const;
    virtual void setM_Trailer(uint8_t M_Trailer);

    virtual int getM_Type() const;
    virtual void setM_Type(int M_Type);

    virtual const char *getDisplayString() const override
    {
        EV << "ECHO" << std::endl;
        return "whyyyyyyyyyyyy";

    }
};

but when I simulate this happens: enter image description here

as you can see EV << "ECHO" << std::endl; is executed so this means that getDisplayString() is called successfully as I didn't call EV << "ECHO" << std::endl; anywhere else in the project.

but the display string of the message is "(MyMsg_Base)" and it didn't change as the docs said, so what did I do wrong?


Solution

  • That is NOT the display string you are seeing on the picture. That is the NAME of the message. DisaplyString is meant to change the graphical appearance of the message on Qtenv. (i.e. color, shape etc)