VgwStreamFreeTokenFnc


Use the VgwStreamFreeTokenFnc function to release resources, such as memory for data structures, acquired by your token. The Verity engine calls your VgwStreamFreeTokenFnc function after it calls VgwStreamGetTokenFnc to retrieve the token.


Syntax

VdkError VgwStreamFreeTokenFnc(
VgwAppStream   vgwStream,
VdkToken       vdkToken)

Arguments

 


vgwStream

VgwAppStream   The stream handle for the stream associated with this token, which was created in your driver’s VgwStreamNewFnc function.

vdkToken

VdkToken   The token being released.


Returns

This function must return one of the following error codes:

VdkSuccess for success

 

VdkError_* for a standard Verity Developer Kit API error as described in the Verity Developer’s Kit Programming Reference

 

VdkFail for a non-specific error

 


Discussion

In addition to the Verity engine calling your VgwStreamFreeTokenFnc function when their are no more tokens in the stream, you can call VgwStreamFreeTokenFnc also; for example, if your VgwStreamTokenFnc function results in an error, you may need to free resources allocated in VgwStreamTokenFnc before terminating.

There is no guarantee that a token will be freed in the order it was created.

You should free your token, referenced by vdkToken, after first releasing all other resources referenced by it.


Example

static VdkError
VDK_CALLBACK VgwStreamFreeToken(VgwAppStream pStream,
VdkToken pToken)
{
if (!pToken)
return VdkSuccess;

/**************************************************
* free the VDK token created by VgwStreamGetToken
**************************************************/

switch (pToken->type)
{
case VdkTokenType_Eof:
case VdkTokenType_Nop:
break;

case VdkTokenType_Buffer:
if (pToken->data.buf.buffer)
free(pToken->data.buf.buffer);
break;

case VdkTokenType_Field:
if (pToken->data.field.name)
free((void*)pToken->data.field.name);

if( (pToken->data.field.type == VdkFieldType_Text) ||
        (pToken->data.field.type == VdkFieldType_Stream) )
if (pToken->data.field.value.buf.buffer)
free(pToken->data.field.value.buf.buffer);
break;

case VdkTokenType_Zone:
if (pToken->data.zone.name)
free((void*)pToken->data.zone.name);
break;

case VdkTokenType_FileByName:
    /* This sample assumes that the file was not created by the  */
    /* gateway and it is not temporary; otherwise, you must     */
    /* unlink the file here.                                    */
if (pToken->data.file.name)
free((void*)pToken->data.file.name);
break;

case VdkTokenType_NewDoc:
if (pToken->data.newDoc.key)
free((void*)pToken->data.newDoc.key);
if (pToken->data.newDoc.dispatchField)
free((void*)pToken->data.newDoc.dispatchField);
if (pToken->data.newDoc.dispatchFN)
free((void*)pToken->data.newDoc.dispatchFN);
break;

default:
break;
}

free(pToken);
return VdkSuccess;
}