# Setting up the Natural Access environment

You must set up the Natural Access environment before using NaturalConference. Perform the following steps to set up the Natural Access environment:

- Initialize Natural Access

- Create event queues and contexts

## Initializing Natural Access for NaturalConference

To use NaturalConference, specify the service name CNF in one of the following ways:

- ctaInitialize invocation arguments

- [ctasys] section of the Natural Access configuration file (cta.cfg)

If specified during ctaInitialize, the function's parameters could look like the following:

CTA_SERVICE_NAME service_names[] = {{"cnf", "cnfmgr"},
{"swi", "swimgr"}
};
ret = ctaInitialize(service_names,sizeof(service_names)
/sizeof(CTA_SERVICE_NAME),NULL);

The content of the [ctasys] section is used only when the ctaInitialize parameter specifies the list of manager/service pairs as NULL. The following lines illustrate how that part of the [ctasys] section should look:

[ctasys]
Service = cnf, cnfmgr
Service = swi, swimgr

For more information, see Modifying the Natural Access configuration file.

## Creating event queues and Natural Access contexts

After initializing Natural Access, the application must create a queue, specify a manager to be used with that queue, and create contexts. Use the following functions:

To... | Use this function... | Description
--- | --- | ---
Create an event queue | ctaCreateQueue | Accepts manager lists or uses the default manager list from the [ctasys] section.
Create contexts (ctahd) | ctaCreateContext | Specifies the previously created queue as the queue for receiving the event related to the context.

You can create either one queue per context or one queue for all contexts. A conference is attached to a queue by means of a resource handle (cnfresourcehd) opened by ctahd. The application must choose whether to receive events from conferences on the same queue or on different queues. To receive events from conferences on different queues, the application must create one ctahd and one cnfresourcehd for each conference. The following illustrations show different programming models of queue/conference attachment.

The following illustration shows the basic model where one ctahd is created for all conferences in the system. This model does not allow the management of conferences on separate threads.

This illustration shows the most flexible model, where a unique ctahd is created on a separate queue for each resource handle on which a conference is created. This model allows for the management of conferences on separate threads.

A context obtains access rights for NaturalConference (not for creating conferences) when calling ctaOpenServices on a specified ctahd. The code that performs this should look like the following:

CTA_SERVICE_DESC service_descs[] =
{
{
{"cnf", "cnfmgr"}, /* name of the NaturalConference service */
{0}, /* svcaddr -> reserved */
{0}, /* svcargs -> not used by NaturalConference */
{0} /* mvipaddr -> not used by NaturalConference */
}
};
ret = ctaOpenServices( ctahd, service_descs,
sizeof(service_descs)/sizeof(CTA_SERVICE_DESC) );

To open NaturalConference on a context, initialize a service_descs structure with cnf and cnfmgr in the name field.

## Linking with NaturalConference

When building a new Natural Access application that uses NaturalConference, link to cnfapi.lib (under UNIX, libcnfapi.so). cnfmgr.dll (under UNIX, libcnfmgr.so) is dynamically loaded at runtime.

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