What is the actual reason for using boost:signals for few functions?

3

The src/main.cpp has RegisterNodeSignals and UnregisterNodeSignals to register the functions as boost signals as below:

void RegisterNodeSignals(CNodeSignals& nodeSignals)
{
    nodeSignals.GetHeight.connect(&GetHeight);
    nodeSignals.ProcessMessages.connect(&ProcessMessages);
    nodeSignals.SendMessages.connect(&SendMessages);
    nodeSignals.InitializeNode.connect(&InitializeNode);
    nodeSignals.FinalizeNode.connect(&FinalizeNode);
}

Let us pick InitializeNode as an example. The actual invocation happens in src/net.cpp which invokes the function defined in src/main.cpp:

GetNodeSignals().InitializeNode(GetId(), this);

I have the following question:

  • Why cannot we simply call this function? Why should we complicate with boost library and signals?
  • Has it got to do with performance of threads? If yes, then why only the 5 functions in RegisterNodeSignals

Paarth

Posted 2015-12-21T07:58:31.900

Reputation: 105

Answers

1

Signals in OO is a powerful concept that allows binding instances together on runtime.

The signals concept allows to keep code modular and bind multiple instances on one signal emitter.

Just calling a function can work (for the 1-to-n you would at least need another vector of instances, etc.), but would reduce the flexibility and modularity of the code.

Jonas Schnelli

Posted 2015-12-21T07:58:31.900

Reputation: 5 465