# Shutting down services

Service shutdown occurs when ctaCloseServices is called. The following binding functions are called:

- xxxCloseService

- xxxCloseServiceManager

## xxxCloseService

The xxxCloseService binding function is invoked when a service is closed on a context. This function can shut down the managed resource.

If your service will use the Natural Access runtime control features (described in the Natural Access runtime control section), invoke dispRemoveRTC, dispUnregisterRTCAlias, or both functions during the execution of xxxCloseService.

tik service

<<<< excerpt from tikbnd.c >>>>

/*----------------------------------------------------------
tikCloseService
- shut down the managed resource
----------------------------------------------------------*/
STATIC DWORD NMSAPI tikCloseService ( CTAHD ctahd,
void *mgrcontext,
char *svcname,
unsigned svcid )
{
TIK_CHANNEL_OBJECT *ptikChannel = (TIK_CHANNEL_OBJECT*)mgrcontext;
DWORD ret;
/* Needed by Natural Access provided error logging service */
CTABEGIN("tikCloseService");
ASSERT( svcid == TIK_SVCID );
/* Perform graceful unwinding prior to service close. */
if( (ret=tikHandleCloseService( ptikChannel )) != SUCCESS )
{
return CTALOGERROR( ctahd, ret, TIK_SVCID );
}
return SUCCESS;
} /* end tikCloseService() */

## xxxCloseServiceManager

Closing a service manager involves cleaning up all that was done when opening the service manager to the queue. If memory was allocated during the open, this memory should be freed during close processing. If a wait object was registered during open, then it must be unregistered using dispUnregisterWaitObject.

tik service

<<<< excerpt from tikbnd.c >>>>

/*-------------------------------------------------------------
tikCloseServiceManager
- Deallocate Service Manager specific data (a manager context)
-------------------------------------------------------------*/
STATIC DWORD NMSAPI tikCloseServiceManager( CTAHD ctahd,
void *mgrcontext )
{
TIK_CHANNEL_OBJECT *ptikChannel= (TIK_CHANNEL_OBJECT *)mgrcontext;
tikDestroyChannel( ptikChannel );
return SUCCESS;
} /* end tikCloseServiceManager() */