This post comes from the discussion in this other one ...
https://groups.google.com/d/msg/omnetpp/iyO5H4OrxBU/7VkEL4gpNmIJI finally created a
Singleton class that inherits from cSimpleModule
In order to make it work I had to include its .ned it into my SNetwork.ned description. I did it like this
network SNetwork extends BaseNetwork
{
parameters:
int numNodes; // total number of hosts in the network
submodules:
node[numNodes]: SNode {
parameters:
@display("p=170,50;i=device/wifilaptop");
}
GlobalMetric: SingletonGlobalMetrics {
@display("p=50,40;i=misc/globe;is=b");
}
connections allowunconnected:
// all connections and gates are to be generated dynamically
}
I
have to point out that, in order to get success with the Singleton
pattern. All variables must be initialized at the Constructor, because this is how the single instance will be called.
The use of the inheritance from cSimpleModule helps to get a call to the destructor once the simulation is over.
As Rudolf pointed out, the destructor is always being called whether the simulation has been successful or not.
For that it requires some extra code to filter that situation, nothing special.
Still I am not fully sure about what I did. For this I Have the following question.
Do we have any other way to subscribe my Singleton-SimpleModule to the simulation without edition the Network.ned?