Hardware Resource Manager Plug-in Tutorial

This tutorial describes how to write the plug-ins for HWRM.


Symbian developers must implement the CHWRMPluginService in their plug-in. The HWRM plug-in must create a new instance of the CHWRMPluginServices using CHWRMPluginService::NewL() method. A string and a callback pointer are passed as the parameters. The common strings used to identify the plug-in are HWRMLight, HWRMVibra and HWRMPower. The callback pointer is provided by the MHWRMPluginCallback class.

The client APIs requests are forwarded to the plug-in using a CHWRMPluginServices::ProcessCommandL(). Command ID, transaction ID and command data are passed as parameters. The plug-in communicates with the hardware using proprietary software developed by the licensees and convert the client requests into hardware control commands. After processing a request, the plug-in acknowledges the server by calling the MHWRMPluginCallback::ProcessResponseL() callback function. The same command ID and transaction ID are passed as the parameters. An error code is also included in the acknowledgement message.

Every MHWRMPluginCallback::ProcessResponseL() is associated with an CHWRMPluginServices::ProcessCommandL() request. Both functions can use asynchronous calls and leave. The HWRM server can cancel a CHWRMPluginServices::ProcessCommandL() request by calling a CHWRMPluginService::CancelCommandL().

Plug-in Configuration

Configure HWRM plug-ins as an ECom plug-in. To load the plug-in correctly, the resource files must be configured carefully.

The following code illustrates a sample resource file for Light and Vibra plug-ins:

#include "RegistryInfoV2.rh"

//Sample resource file for Light and Vibra plug-ins

    resource_format_version = RESOURCE_FORMAT_VERSION_2;
    dll_uid = 0x12345678;
    interfaces = 
            // UID of interface that is implemented
            interface_uid = 0x10205028;
            implementations = 
                    implementation_uid = 0x11223344;
                    version_no = 1;
                    display_name = "Light plugin stub";
                    default_data = "HWRMLight";      
                    opaque_data = "";
                    rom_only = 1;
                    implementation_uid = 0x55667788;
                    version_no = 1;
                    display_name = "Vibra plugin stub";
                    default_data = "HWRMVibra";      
                    opaque_data = "";
                    rom_only = 1;

Note: The value of rom_only must always be 1. The default data must be HWRMLight, HWRMVibra, HWRMPower.

Sample Light plug-in example

The following code snippet illustrates how a light plug-in is called by the HWRM server:

#include "HWRMpluginService.h"

_LIT8( KHWRMLightApiEComMatch, "HWRMLight" );

iPlugin = CHWRMPluginService::NewL( KHWRMLightApiEComMatch, this );
iTransCounter = 0;
. . .
HWRMLightCommand::TLightsOnData pluginCommand;
pluginCommand.iTarget = 0x00000001; // Set target to primary display 
pluginCommand.iIntensity = 50;
pluginCommand.iFadeIn = EFalse;    
HWRMLightCommand::TLightsOnCmdPackage pckg( pluginCommand );
iPlugin->ProcessCommandL( HWRMLightCommand::ELightsOnCmdId, iTransCounter++, pckg );

//Example of how ProcessResponseL() or EventL() might be handled

HWRMLightCommand::TErrorCodeResponsePackage errPckg;
errPckg.Copy( aData );
TInt pluginErr = errPckg();

// Handle error here