Chapter 7. OpenHPI Plugin Development Guide

This chapter is a developer's guide to writing an openhpi plug-in. The hope is that by providing this documentation in addition to the source code in CVS, developers will have all the tools needed to enable support for a given platform under openhpi.

7.1. General plug-in concepts

As explained earlier in this manual, plug-ins are at the heart of openhpi. They serve as the proxy to hardware management interfaces and protocols. A plug-in has two main roles. First, to interface with the hardware management interface and gather data. Second, format that data into HPI data structures and send them up to the main openHpi library. Further, as openHpi based application need to communicate commands to the hardware, the infrastructure library uses the 'abi' interface functions to communicate with a plug-in and send commands and/or data to the hardware.

Every plug-in in openhpi requires the following: struct oh_abi_v2 declaration such as:


static struct oh_abi_v2 my_plugin = {
        .open                           = my_open,
        .close                          = my_close,
        .get_event                      = my_get_event,
        .discover_resources             = my_discover_resources,
        .get_self_id                    = my_get_self_id,
        .get_sel_info                   = my_get_sel_info,
        .set_sel_time                   = my_set_sel_time,
        .add_sel_entry                  = my_add_sel_entry,
        .del_sel_entry                  = my_del_sel_entry,
        .get_sel_entry                  = my_get_sel_entry,
        .get_sensor_data                = my_get_sensor_data,
        .get_sensor_thresholds          = my_get_sensor_thresholds,
        .set_sensor_thresholds          = my_set_sensor_thresholds,
        .get_sensor_event_enables       = my_get_sensor_event_enables,
        .set_sensor_event_enables       = my_set_sensor_event_enables,
        .get_control_state              = my_get_control_state,
        .set_control_state              = my_set_control_state,
};
    


This C99 style structure relates to the function pointers defined in plugin.h and is the entry point into plug-in functions. The sesond requirement is the get_interface function which is called when a plug-in is initialized by the infrastructure. It exposes the internal (above) functions a plug-in supports/implements. The functions looks like:

int get_interface(void **pp, uuid_t uuid)
{
        if (uuid_compare(uuid, UUID_OH_ABI_V2)==0) {
                *pp = &oh_my_plugin;
                return 0;
        }

        *pp = NULL;
        return -1;
}
    


I will try to describe the plug-in interface (ABI) functions needed to get a plug-in started. Remember that the implementation of these functions is usually dependent on the hardware management protocol and platform you're enabling