Quick Start – Init() and Cleanup() Explained
The code generation wizard generates classes for each subtree handler. The main class has a name that is the name of the project prefixed by a ‘D’. For example, the Garage project has its main class as DGarage.
DGarage has two methods, Init() and Cleanup(). The Init() method iteratively calls the Initialize() method of each subtree handler. If the architecture of the agent requires some system wide initialization code or if it requires to start a thread, this method is the place to put that code.
Similarly, the Cleanup method of the main class would be the ideal place to put cleanup code for when the system is being shutdown.
Individual subtree handlers have their own Initialize() and Cleanup() methods. The Initialize method of each subtree handler can be used to initialize the objects serviced by that subtree handler. An example of DGarageObjects is provided below.
Please note that each subtree handler has a SetReady flag. When this flag is set to true, the objects of the subtree handler are accessible by the agent. If set to false, these objects can not be accessed. One possible use of this flag is when system objects require a long time to initialize. Initially, this flag is set to false, but when the system has initialized, this flag can be set to the ready state.