# Setting up the Natural Access environment

Before calling functions from the Switching library, set up the Natural Access environment by performing the following steps:

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

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 to the existing context that is to be shared by the applications.

## Initializing Natural Access

Register services in the call to ctaInitialize by specifying the service (SWI) and service manager (SWIMGR). Only the services initialized in the call to ctaInitialize can be opened by the application. Service managers are dynamic link libraries (DLL) in Windows and shared libraries in UNIX that are linked to the application.

## Creating event queues and contexts

After initializing Natural Access, create the event queues
and the contexts. Create one or more event queues by calling ctaCreateQueue and specifying the service manager to attach 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.

To create a context, call ctaCreateContext and provide the queue handle (ctaqueuehd) returned from ctaCreateQueue. All events for services on the context are received in the specified event queue.

ctaCreateContext returns a context handle (ctahd). The context handle is supplied by the application when invoking swiOpenSwitch.

Refer to the Natural Access Developer's Reference Manual for details on the programming models created by the use of contexts and queues.

## 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, service manager, and service-specific arguments.

## Linking with the Switching service

The Natural Access Switching service contains two components, the Switching service interface (swiapi) and the Switching service implementation (swimgr). When building a new Natural Access application that uses the Switching service, link to swiapi.lib (under UNIX, libswiapi.so). The swimgr.dll (under UNIX, libswimgr.so) is dynamically loaded at runtime.

Refer to the Natural Access Service Writer's Manual for information about service implementation.