The xxxDetachServiceManager binding function is invoked when the queue is destroyed by ctaDestroyQueue. It is a synchronous function and must return to the dispatcher when detach processing is completed.
Detaching a service manager involves cleaning up all that was done when attaching the service manager to the queue. If memory was allocated during attach, this memory should be freed during detach processing. If a wait object was registered during attach, then it must be unregistered using dispUnregisterWaitObject during detach processing.
The queue specific data passed back to the dispatcher by xxxAttachServiceManager (the queuecontext argument) is passed into xxxDetachServiceManager so that the service manager can clean up these allocated and registered objects.
tik service
<<<< excerpt from tikbnd.c >>>>
/*-------------------------------------------------------------
tikDetachServiceManager
- Undeclare Wait object
- Deallocate Resource object
-------------------------------------------------------------*/
STATIC DWORD NMSAPI tikDetachServiceManager( CTAQUEUEHD ctaqueuehd,
void *queuecontext)
{
TIK_DEVICE_OBJECT *ptikDevice = (TIK_DEVICE_OBJECT *)queuecontext;
TSIIPC_WAIT_OBJ_HD waitobj;
DWORD ret;
/* Needed by Natural Access provided error logging service */
CTABEGIN("tikDetachServiceManager");
/* Get IPC waitobject to un-register. */
if ( tsiIPCGetWaitObject( ptikDevice->connector, &waitobj ) !=
SUCCESS )
{
tikDestroyDevice( ptikDevice );
return CTALOGERROR(
NULL_CTAHD, CTAERR_OS_INTERNAL_ERROR, TIK_SVCID);
}
/* Unregister waitobject with Natural Access. */
else if ( (ret=dispUnregisterWaitObject(
ctaqueuehd, (CTA_WAITOBJ *)&waitobj)) != SUCCESS)
{
tikDestroyDevice( ptikDevice );
return CTALOGERROR( NULL_CTAHD, ret, TIK_SVCID );
}
/* Teardown IPC connection. */
else if ( (ret=tikTeardownIPC( ptikDevice )) != SUCCESS )
{
tikDestroyDevice( ptikDevice );
return CTALOGERROR( NULL_CTAHD, ret, TIK_SVCID );
}
/* Destroy created service manager object. */
else
tikDestroyDevice( ptikDevice );
return SUCCESS;
} /* end tikDetachServiceManager() */