Example.cpp is the primary source file for this IDL driver example. It contains a simple, startup function called from main.cpp that provides the driver an opportunity to set up an interface device or port if required, as well as initialize anything necessary before the driver starts up. It also contains the sample thread code related to any background processing that a typical IDL driver might need to do. Finally, it contains the code for the callback functions originally registered with the IDL library and any protocol-specific code associated with these callback events.
As seen in the following comments, example.cpp includes a stub function called IdiStart() that can be used to open a port or interface device and perhaps initialize any protocol-specific structures required to run the custom driver.
This source file also includes a simple example of a custom driver function launched on a separate thread called ExampleRxFunction(). Since the IdlInit() function in main.cpp that initiates the driver instance never returns, any custom driver that needs to execute any background processing tasks independent of the callback functions will need to create separate thread(s) for this code. For example, a driver might need a background task that handles incoming, asynchronous packets from devices that are not tied to actions associated with the callback functions. While the ExampleRxFunction() in this sample driver code does not do anything other than continuously suspend via usleep() and restart execution of the thread, its purpose is to illustrate how a custom driver could create separate execution threads if required.
The remainder of example.cpp essentially contains the callback functions previously registered with the IDL library in main.cpp. These callback functions provide entry points for the custom driver to insert code to execute based on various events such as creating a new device using the protocol, provisioning a device, requests to read and write data points and so on. A complete list of available callback functions can be found in the IAP Driver Library (IDL). This example driver contains simple implementations of many of the common callback functions. These example callback functions output basic information to the console when called to assist in understanding the interaction between the IDL library and a custom driver and the basic parameters passed with these functions.