Main.cpp is the entry point for this IDL driver example. The primary purpose for main.cpp is:
- to create a new IDL driver instance (IDI) with the underlying IDL library
- to register the callback functions IDL will use to interact with this custom driver instance
- to start up and initialize the driver
In addition, in main.cpp your custom driver code will typically create any independent Linux POSIX threads that your driver might require to perform any background processing. For example, you might need to define a thread to handle incoming, asynchronous communications packets from the protocol that your driver needs to capture. A stub example of this is included in this sample driver.
Any source files that reference or use functions or data structures defined in the IAP IDL Library must include the header file for the IDL library libidl.h. For reference, this header file can be found on the SmartServer IoT under the /usr/include/ directory. In addition to including the library header file, main.cpp includes the header file for the custom driver source itself, as well as the standard POSIX <pthread.h> header file, since an example thread is created in main.cpp as well.
Main.cpp starts by creating a new driver instance. It then registers any callback functions it supports with this instance so IDL can pass data and control to the custom driver code when actions associated with this protocol occur. This includes such actions as creating a new device that uses this protocol, provisioning a device, reading data points from a device, and so on.
Main.cpp then calls a generic startup function IdiStart() located in example.cpp which provides a way for the custom driver to perform any required startup actions, such as opening a serial port or initializing some structures. It then creates an example thread to handle background processing that might be required by the driver, and finally initializes the driver instance itself using the parameters defined in the example-idl.conf configuration file.