# Setting up the Natural Access environment

Before calling PPX functions, the application must set up the Natural Access environment by performing the following steps:

Step | Action
1 | Initialize the Natural Access application.
2 | Create event queues.
3 | Create contexts and attach them to event queues.
4 | Open services on each context.

Complete the following steps to set up a second Natural Access application that shares a context with the first application:

Step | Action
1 | Initialize the Natural Access application.
2 | Create event queues.
3 | Attach the application to the existing context.

## Initializing Natural Access

Register services in the call to ctaInitialize by specifying the service name (PPX) and the service manager name (PPXMGR). Only the services initialized in the call to ctaInitialize can be opened by the application.

## Creating event queues and contexts

After initializing Natural Access, create the event queues
and contexts
. An event queue is the communication path from a Natural Access service to an application. A Natural Access service generates events indicating certain conditions or state changes. An application retrieves the events from the event queue. Most PPX functions are synchronous, returning when the function is complete and not generating events.

Create one or more event queues by calling ctaCreateQueue. Specify which service managers is attached to each queue. When you attach or bind a service manager to an event queue, you make that service manager available to the event queue.

Natural Access organizes services and accompanying resources around a single processing context. A context usually represents an application instance controlling a single telephone call. Natural Access provides multi-processing support: multiple Natural Access application processes can perform tasks on behalf of the same context (referred to as context sharing). Natural Access applications can transfer control of contexts (for example, contexts associated with individual telephone calls) to other Natural Access applications (referred to as context hand-off).

Create a context by calling ctaCreateContext or ctaCreateContextEx. Provide the queue handle (ctaqueuehd) that was returned from ctaCreateQueue. All events for services on the context are received in the specified queue. ctaCreateContext returns a context handle
(ctahd).

## Opening services

To open services on a context, call ctaOpenServices and pass a context handle and a list of service descriptors. The service descriptor specifies the name of the service and the service manager.

Note: Open the SWI service in a PPX client application only if the application is making calls directly to the SWI service on its own behalf. For example, if a PPX client application sets the telephony bus clocks and stream speeds, it must use SWI functions and must open the SWI service.

Refer to the Natural Access Developer's Reference Manual for details on initializing Natural Access and for programming models you can use.