Home | Previous Page | Next Page   Appendix H. Custom Drivers > Adding a Custom Driver to the onpload Utility >

Preparing the Custom-Driver Code

A driver is implemented as a set of functions, referred to as methods. The methods enable onpload to open, close, read, and write data files. You can create a custom driver that adds more complex functionality to data-file handling of onpload.

A custom driver consists of one or more functions that replace the capability of an existing driver method. The custom driver needs to provide all of the methods for a driver, such as OPEN, READ, WRITE, and CLOSE.

To add to the capability of an existing driver method, the custom driver function calls the existing driver method from the custom function before or after any custom processing, as appropriate.

To replace an existing driver method, the custom function provides all processing that is necessary for that function. The custom driver function does not call the existing standard driver functions.

To prepare the custom-driver code, you must prepare the following two files. You can store the files in any convenient directory.

To prepare the file that provides the driver functionality
  1. Create a file for the driver functions (for example, your_custom_driver.c).
  2. Prepare the driver code.

    This appendix includes an example of driver files, Driver Example. Use this example as a template for building your driver code.

    The driver methods and API functions that you can use are described in Available Driver Methods and Available API Support Functions.

To prepare the plcstdrv.c file
  1. Use the following code as a template to create the plcstdrv.c file. You can copy a template for plcstdrv.c from the $INFORMIXDIR/incl/hpl directory.
    /*******************************************************
     * Start of plcstdrv.c 
     */
    
    /* plcstdrv.h is in $INFORMIXDIR/incl/hpl */
    #include "plcstdrv.h"
    
    /* Your driver configuration function */
    int your_driver_config_function(); 
    
    (*pl_get_user_method(driver, method)) ()
        char *driver;
        int   method;
    {
        /*
         * your_driver_name is the name of your driver 
         */
        if (strcmp(driver, "your_driver_name") == 0)
            {
            /*
             * If onpload is trying to configure the driver, 
             * return the function that will handle the 
             * initialization.
             */
            if (method == PL_MTH_CONFIGURE)
                return(your_driver_config_function);
            }
    /*
         * YYYY is the name of another driver
         * This is how additional custom drivers are configured
         */
        if (strcmp(driver, "YYYY") == 0)
            {
            if (method == PL_MTH_CONFIGURE)
                return(YYYY_driver_config_function);
            }
    }
    /***************** end of plcstdrv.c *******************/
  2. Replace your_driver_name with the name of the driver that you chose in step 1 of Adding the Driver Name to the onpload Database.
  3. Replace your_driver_config_function with the function name of the driver-configuration function that you coded in your_custom_driver.c.
  4. To add multiple custom drivers, repeat the main if statement for each driver.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]