# Setting up the DTM service

Before you can call functions from the DTM service, the application must initialize and open the DTM service on an open context. This topic presents:

- Initializing the DTM service

- Opening the DTM service

## Initializing the DTM service

To initialize the DTM service, include the DTM service and the ADI Service Manager in the call to ctaInitialize.

The following code excerpt demonstrates initializing the DTM service together with the ADI and Voice Message services:

void MyServiceInit()
{
DWORD ret;
CTA_INIT_PARMS initparms = { 0 };
CTA_ERROR_HANDLER hdlr;
CTA_SERVICE_NAME InitServices[] = /* for ctaInitialize */
{ { "ADI", "ADIMGR" },
{ "DTM", "ADIMGR" },
{ "VCE", "VCEMGR" },
};
/* Initialize size of init parms structure */
initparms.size = sizeof(CTA_INIT_PARMS);
if ( ( ret = ctaInitialize(
InitServices,
sizeof(InitServices)/sizeof(InitServices[0]),
&initparms)) != SUCCESS)
{
/* ... handle error conditions here.... */
}
}

After the call to ctaInitialize:

1. Create an event queue attached to the ADI Service Manager by calling ctaCreateQueue. ADIMGR can be explicitly specified in the call. If NULL is passed, all service managers specified in ctaInitialize are attached.

2. Create a context by calling ctaCreateContext.

## Opening the DTM service

The DTM service must be opened on a context in order to use DTM service functions. Opening the DTM service starts the trunk monitor software on the board and enables it to make status information accessible to the application at specific intervals.

Note: Only one instance of the DTM service can be opened on each context.

When the application opens a service, it specifies a board number. When the application opens the trunk monitor, it binds the board to a context.

To open the DTM service on a context, call ctaOpenServices. This function takes an array of CTA_SERVICE_DESC structures as an input argument. Each CTA_SERVICE_DESC structure defines a service (in this case, the DTM service). When a service is opened successfully, CTAEVN_OPEN_SERVICES_DONE with CTA_REASON_FINISHED is delivered to the application. The CTA_SERVICE_DESC structure is defined as follows:

typedef struct CTA_SERVICE_DESC
{
CTA_SERVICE_NAME name; /* service name */
CTA_SERVICE_ADDR svcaddr; /* reserved */
CTA_SERVICE_ARGS svcargs; /* passes service-specific arguments */
CTA_MVIP_ADDR mvipaddr; /* AG board #, stream, timeslot, mode */
}CTA_SERVICE_DESC;

Note: The DTM service does not take any information from the MVIP_ADDR structure. You specify which board, stream, and timeslot to monitor in a DTM function call when you start the trunk monitor, not when you open the DTM service. The CTA_SERVICE_ARGS structure is not used by the DTM service.

The following code sample demonstrates how an application opens the DTM service:

DWORD ret ;
CTA_EVENT event ;
CTA_SERVICE_DESC service[] =
{
{ {"DTM", "ADIMGR"}, { 0 }, { 0 }, { 0 } } ,
} ;
/* open the DTM service */
ret = ctaOpenServices( ctahd, /* a context handle */
services,
1 );
if(ret != SUCCESS)
{
/* opening DTM service failed */
DemoShowError( "ctaOpenServices", ret );
}
else
{
/* wait for the CTAEVN_OPEN_SERVICES_DONE event */
DemoWaitForSpecificEvent(ctahd,
CTAEVN_OPEN_SERVICES_DONE,
& event ) ;
/* check the reason of completion */
if (event.value != CTA_REASON_FINISHED)
{
DemoShowError( "ctaOpenServices", event.value );
}
}