# Creating NaturalAccess contexts and queues

Before calling functions from the MSPP API, initialize NaturalAccess, by invoking ctaInitialize and specifying the names of the services and service managers that the application will use. For a list of standard NaturalAccess services, refer to the Dialogic® NaturalAccess™ Software Developer’s Manual.

After initializing Natural Access and its services, create event queues and contexts
with the following functions:

Function | Description
ctaCreateQueue | Creates an event queues and specifies the service managers to attach to the queue (for example, the MSPP service uses the MSPMGR).
ctaCreateContext | Creates a context and associated with a queue handle (ctaqueuehd) returned from ctaCreateQueue. All events for services on the context are received in the attached event queue.

ctaCreateContext returns a context handle (ctahd). When an application invokes MSPP functions, it must specify a context handle. Events communicated back to the application are associated with the specified handle. Refer to the Dialogic® NaturalAccess™ Software Developer’s Manual for more information about NaturalAccess programming models and managing contexts and queues.

## Opening MSPP service instances

ctaOpenServices opens one or more service instances on a particular context. To open an MSPP service instance on a context, invoke ctaOpenServices with the following:

- A ctahd.

- Service name (MSP) and associated service manager (MSPMGR).

- The board number, stream and timeslot, and mode to associate with the service instance.

For more information about arguments, errors, and events, refer to the Dialogic® NaturalAccess™ Software Developer’s Manual.

### Example: Opening the ADI service and MSPP services on a context

In some cases, the application must open multiple services on the contexts associated with MSPP service instances. For example, when an application wants to perform silence detection with the voice data the passes through MSPP connections, it must open an ADI service instance with each context it uses to create DS0 endpoints. To do this, the application must open the MSPP and ADI services on the context and specify (in the CTA_MVIP_ADDR structure) following address and mode information for the ADI service:

CTA_MVIP_ADDR parameter | Value | Description
services[0].mvipaddr.board | NA | Name of the CG board on which to open the service.
svclist.mvipaddr.stream | 0 | Stream associated with the DSP port. Dialogic recommends using stream 0.
svclist.mvipaddr.timeslot | 0 - 127 | Timeslot associated with the DSP port.
svclist.mvipaddr.mode | ADI_VOICE_DUPLEX | Mode of operation for DSP resources allocated to the service instance. For more information ADI service instances, refer to the Dialogic® NaturalAccess™ Alliance Device Interface API Developer's Manual.

Note: When the application uses mspCreateEndpoint to create DS0 endpoints, it must specify the same timeslot in the DS0_ENDPOINT_ADDR structure that it specified in the CTA_MVIP_ADDR substructure when it opened the MSPP API on the context.