# isdndemo classes

This topic describes the following major global classes used in the isdndemo program:

- Context

- DChannel

- NAI

- Call

- BContext

- Timer

## Context

This abstract class provides a generic mechanism for event processing. Protected constructor Context::Context() creates a unique Natural Access context for each Context class object and its children. Every context is then bound to a single event processing queue (Context::qid).

Each child class overrides two functions of Context to implement some processing logic:

- processEvent. Process a single event that is passed as an argument.

- start. Invoked for each Context object just before entering the main processing loop in the Context::eventLoop function.

Each Context object has a unique index (Context::index) that enables the main processing loop to direct an event to the correct context.

## DChannel

The DChannel is a key class for all of isdndemo. One object of this class is created for each D channel the program uses. During object construction, one NAI object is created for each trunk that a given D channel supports. For a non-NFAS configuration, only one NAI is created. Thus, a single call of the DChannel::DChannel constructor creates a tree of related objects.

DChannel objects perform the following functions in isdndemo:

- Process incoming ISDN call control messages with the processEvent function. Messages are passed to the appropriate Call object for processing.

- Send ISDN call control messages to the board with sendIsdnMessage. DChannel never creates ISDN messages by itself. This function is used only by Call objects.

- Print ACU messages in a form readable to users.

- Print program operation statistics to the screen and to the log file.

## NAI

NAIs tie together DChannel, Call, and BChannel objects. An NAI object supports a list of Call objects, which presents calls associated with a given NAI. A Call object can be obtained by its connection ID (from getCall). The free call with the lowest connection ID can be obtained by invoking the getFreeCall function.

NAI objects also support a list of BChannels associated with a given NAI. These objects can be obtained by their B channel number by invoking getBChannel.

All Call and BChannel objects are created during the creation of an NAI object.

## Call

Call objects implement a reduced version of the NMS ISDN messaging API state machine. A Call object can be in one of the following four states:

State | Description
--- | ---
ST_NULL | Free start. No real call exists.
ST_AWAITING_CONNECT | Objects wait for the connection of the call (ACU_CONN_CO).
ST_ACTIVE | Call is in the connected state.
ST_AWAITING_CLEARANCE | Objects wait for the call to be cleared (ACU_CLEAR_CO).

The following three functions affect the Call object state:

Function | Description
--- | ---
processIsdnMessage | Processes incoming ACU messages and sends the ACU messages in response. A DChannel object associated with the Call object calls this function.
makeCall | Initiates a new outbound call. BChannel calls this function.
hangUp | Hangs up a call in the connected state. BChannel calls this function.

A Call object can have a BChannel object associated with it. In this case, it uses some of BChannel's functions to indicate a Call change of state to a BChannel object.

## BContext

BContext objects provide voice playing and ADI timers associated with a physical B channel. This object can have a single Call object associated with it.

A BContext object can be in one of the following three states:

State | Description
--- | ---
ST_FREE | Not associated with any Call object.
ST_USED | Associated with a Call object.
ST_CALL | Associated with a Call object in the connected state.

Two different modes for BContext objects determine its behavior:

Mode | Description
Outbound | Initiates an outbound ISDN call upon entering the ST_FREE state. It also tries to hang up an existing call after a time interval when in the ST_CALL state.
Inbound | Initiates nothing. This is passive mode.

A Call object can use the following BChannel functions to indicate a change of state:

Function | Description
--- | ---
get | Associate BChannel with a Call object.
free | Disassociate BChannel with a Call object.
startCall | Play voice. Call entered connected state.
stopCall | Stop playing voice. Call left connected state.

## Timer

BContext uses a Timer object to wait for a specific time interval. Timer is a utility class that implements a synchronous timer based on the asynchronous ADI timer. It has three functions:

Function | Description
--- | ---
start | Starts the timer for a given time interval, or restarts a running timer.
stop | Stops running the timer, or does nothing if the timer is not active.
event | Passes an ADI timer event to the Timer object. event returns true if the Timer object has expired. Otherwise, it returns false.