<p>Signals in OO is a powerful concept that allows binding instances together on runtime.</p>

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

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

CC BY-SA 3.0
2016-11-01T13:41:56.057Z
2016-11-01T13:41:56.057Z
Jonas Schnelli
<p>The <code>src/main.cpp</code> has <code>RegisterNodeSignals</code> and <code>UnregisterNodeSignals</code> to register the functions as boost signals as below:</p>

<pre><code>void RegisterNodeSignals(CNodeSignals&amp; nodeSignals)
{
    nodeSignals.GetHeight.connect(&amp;GetHeight);
    nodeSignals.ProcessMessages.connect(&amp;ProcessMessages);
    nodeSignals.SendMessages.connect(&amp;SendMessages);
    nodeSignals.InitializeNode.connect(&amp;InitializeNode);
    nodeSignals.FinalizeNode.connect(&amp;FinalizeNode);
}
</code></pre>

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

<pre><code>GetNodeSignals().InitializeNode(GetId(), this);
</code></pre>

<p>I have the following question:</p>

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

<bitcoind><bitcoin-core><client><protocol>
What is the actual reason for using boost:signals for few functions?
Paarth
# What is the actual reason for using boost:signals for few functions?

(Asked by: username_0 on 2015-12-21)

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`

**Tags:** bitcoind, bitcoin-core, client, protocol


---

## 1 answers

### Answer by username_1 on 2016-11-01. Score: 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.


---

