Error Handling

When your driver is first loaded, the Verity engine calls your new driver callback function allowing you to retrieve and store parameters provided to the driver. Two of the parameters are the error callback parameter, which specifies the function pointer for the error callback function, and the error argument parameter, which specifies additional information, such as the driver context for the message.

You should store these parameters for use by all of your callback functions, so that they can provide feedback in the event of an error. The following code shows how these parameters are retrieved from the driver’s attributes array, vdkAttrs, and stored in the callback argument, pdrvHandle. The callback argument can then be made available to each of your callback functions.

static VdkError
VDK_CALLBACK VdkDrvNew(VdkCBArg* pdrvHandle,
VdkInt2 argc, VdkCString* argv, VdkVoidp* vdkAttrs)
{
VdkError error = VdkSuccess;
VdkVoidp* pAttrs = vdkAttrs;
VdkDrvObjs pDrvObjs;
assert(pdrvHandle);
  assert(pAttrs);
for( ; *pAttrs; pAttrs+=2 ){
    if (VGW_StrEq(VdkDrvNew_ErrFunc, pAttrs[0]))
pDrvObjs->ErrorCB = (VdkDrvErrorCBFnc)pAttrs[1];
else if (VGW_StrEq(VdkDrvNew_ErrArg, pAttrs[0]))
pDrvObjs->ErrorArg = (VdkCBArg)pAttrs[1];
  ...
  *pdrvHandle = pDrvObjs;
  return error;
}

For more information about the new driver callback function, see the description of VdkDrvNewCBFnc in Driver Interface.

When any of your callback functions needs to write a message to the log file, it can do so by calling the function pointer associated with the VdkDrvNew_ErrFunc parameter, and passing it the error callback argument, a message type level, and the actual message to display, as in the following example:

if( pDrvObjs && pDrvObjs->ErrorCB )
(*pDrvObjs->ErrorCB)(pDrvObjs->ErrorArg, VdkMessageType_Error,
(VdkCString)"Failed in VgwSessionNew");