2
votes

in my simulation there is a mobile node composed by the following components from the inet framework:

Now I am working on the UdpApp which is UDPVideoStreamCli.cc which is also given by inet framework as one of example udp application.

Now as you can see from the image I had to access to the lisp module (which is an instance of LispRouting.cc) because I have to read some values or call some public methods of that class...how can I do that? All I know is that I have to start from

getParentModule()->getSubmodule();

but then I don't know how to go on...can you help?

1

1 Answers

8
votes
(LispRouting *)getParentModule()->getSubmodule("lisp")

will do the trick. Be sure to check if the returned pointer is not null.

Generally this is bad design as it hard-codes the name and the relative position of the LispRouting module. Any change in naming/architecture will cause crashes.

A proper design would be to create a parameter that specifies the name/path of the lisp submodule (with default value) and then use

#include "inet/common/ModuleAccess.h"
...
LispRouting *lr = getModuleFromPar<LispRouting>(par("lispModule"), this);

and then add a parameter to the module's NED file:

string lispModule = default("^.lisp");

meaning the default place where you can find the lisp module is: go one level up and then find the submodule named "lisp". This is a much better pattern, because the user can later reconfigure the name/placement of the lisp module without breaking the code.