Node initialization and deinitialization¶
The initialization and deinitialization of nodes is a multi-step process. Not all functions are available in every step.
Initialization¶
init: Right after the node is loaded init is called. A Struct with information about the node (id, name, configuration parameters, ...) is passed to init. All initilialization that can be done at this point, should be done here. When initialization fails,falsemust be returned, which aborts the initialization of that node. Homegear waits forinitto complete for all nodes before continuing with the next step.start: In start there are no restrictions on what is allowed to do. Just note, thatstartmustn't hang (don't sleep or wait). As withinitfalsecan be returned to abort the initialization of that node.- Once
startis finished for all nodes, Homegear callsconfigNodesStarted. This method must not hang as well. - After calling
configNodesStartedon all nodes, Homegear executesstartUpComplete. As with the other start methods,startUpCompleteis not allowed to hang.
Deinitialization¶
stop: The deinitialization is started by Homegear callingstop. Instopall RPC methods and all other nodes are still available. Stop must not hang. For threads that means, you should trigger the stopping of threads instop, but don't join them here. Homegear waits for all calls tostopto finish before continuing.waitForStop: This method is made for one purpose: Joining threads. The stopping of threads should be triggered within stop. Every single thread should be stopped after 1 second and with this construct, all threads are finished after about one second.
Overview¶
See the following table for an overview on what is allowed or available in the initialization/deinitialization methods:
init |
start |
configNodesStarted |
startUpComplete |
stop |
waitForStop |
|
|---|---|---|---|---|---|---|
| Node information available | yes | yes | yes | yes | yes | yes |
| RPC methods available | no | yes | yes | yes | yes | no |
| Get parameters from configuration nodes | no | (yes) | yes | yes | yes | no |
| Must return immediately | yes | yes | yes | yes | yes | no |
| Can abort loading of node | yes | yes | yes | no | no | no |
See the following table on the availability of the initialization/deinitialization methods for different programming languages:
init |
start |
configNodesStarted |
startUpComplete |
stop |
waitForStop |
|
|---|---|---|---|---|---|---|
| PHP (simple) | no | no | no | no | no | no |
| PHP (stateful) | yes | yes | yes | yes | yes | yes |
| JavaScript | no1 | no | no | no | no2 | no |
| Python | no | yes3 | no | yes | yes4 | yes5 |
| C++ | yes | yes | yes | yes | yes | yes |
-
JavaScript nodes are started and available before
initis called on nodes of other languages. ↩ -
JavaScript nodes are stopped after all nodes written in other languages are stopped. ↩
-
The Python script is started in
start. ↩ -
Signal 15 is sent to the Python script in
stop. ↩ -
Node-BLUE waits until the process exits. ↩