Setting up the Natural Access environment

Before calling any TUP service functions, the application must:

Refer to the Natural Access Developer's Reference Manual for more information about Natural Access.

Initializing the Natural Access environment

The Natural Access environment is initialized by calling ctaInitialize. Initialize Natural Access only once per application, regardless of the number of queues and contexts created.

CTA_INIT_PARMS      tupInitparms       = {0};
CTA_SERVICE_NAME    tupServiceNames[]  = {{"TUP", "TUPMGR"}};
...
tupInitparms.size              = sizeof(CTA_INIT_PARMS);
tupInitparms.traceflags        = CTA_TRACE_ENABLE;
tupInitparms.parmflags         = CTA_PARM_MGMT_SHARED;
tupInitparms.ctacompatlevel    = CTA_COMPATLEVEL;

Ret = ctaInitialize(tupServiceNames, 1, &tupInitparms);
if (Ret != SUCCESS) {
    printf("ERROR code 0x%08x initializing CT Access.", Ret);
    exit( 1 );
}

Creating queues and contexts

The application creates the required Natural Access queues and contexts. The queue must always be created before any associated context is created.

CTAHD       ctaHd;                  /* CTA context handle */
CTAQUEUEHD  ctaQueue;               /* Queue */
...

Ret = ctaCreateQueue( NULL, 0, &ctaQueue );
if ( Ret != SUCCESS )
{
     ctaGetText( NULL_CTAHD, Ret, sErr, sizeof( sErr ) );
     printf( "*ERROR : ctaCreateQueue failed( %s )\n", sErr );
     ...
}

sprintf( contextName, "TupSAP-%d", spId ); /* context name is optional */

Ret = ctaCreateContext( ctaQueue, spId, contextName, &ctaHd );
if ( Ret != SUCCESS )
{
     ctaGetText( NULL_CTAHD, Ret, sErr, sizeof( sErr ) );
     printf( "ERROR : ctaCreateContext failed( %s )\n", sErr );
     ctaDestroyQueue( pSap->ctaQueue );
     ...
}

Binding to the TUP service

Once the queues and contexts are created, the application must bind to each desired TUP user service access point by calling ctaOpenServices once for each binding. The binding operation specifies the following parameters:

Field

Description

board

TX board number.

srcEnt

Calling application entity ID.

srcInst

Calling application instance ID.

suId

Calling application service user ID.

spId

TUP service access point ID on which to bind.

ssn

TUP subsystem number associated with the service access point.


In Natural Access, these parameters are specified in the CTA_SERVICE_ARGS structure, contained in the CTA_SERVICE_DESC structure. An example of the parameter specification is provided:

CTA_SERVICE_DESC tupOpenSvcLst[] = {{{"TUP", "TUPMGR"}, {0}, {0}, {0}}};

tupOpenSvcLst[0].svcargs.args[0] = board;   /* board number           */
tupOpenSvcLst[0].svcargs.args[1] = INST_ID; /* srcInst                */
tupOpenSvcLst[0].svcargs.args[2] = ENT_ID;  /* srcEnt                 */
tupOpenSvcLst[0].svcargs.args[3] = 1;       /* AutoBind? (yes=1,no= 0)*/
tupOpenSvcLst[0].svcargs.args[4] = SAP_ID;  /* spId                   */
tupOpenSvcLst[0].svcargs.args[5] = SAP_ID;  /* suId                   */
tupOpenSvcLst[0].svcargs.args[6] = poolsize /* poolsize               */

ctaOpenServices is an asynchronous function. The return from the function indicates that the bind operation initiated. Once ctaOpenServices completes, a CTAEVN_OPEN_SERVICES_DONE event is returned to the application.

If multiple contexts are assigned to the same queue, all of the contexts must use the same entity ID in the service arguments parameter. Conversely, contexts bound to different queues must specify a unique entity ID.

CTA_EVENT   event;    /* Event structure to wait for TUP events */
...


Ret = ctaOpenServices( ctaHd, tupOpenSvcLst, 1 );
if ( Ret != SUCCESS )
{
    ctaGetText( NULL_CTAHD, Ret, sErr, sizeof( sErr ) );
    printf( "ERROR : ctaOpenServices failed( %s )\n", sErr );
    ctaDestroyQueue( ctaQueue );  /* destroys context too */
    return(...)
}

/* Wait for "open services" to complete; note: this loop 
 * assumes no other contexts are already active on the queue
 * we're waiting on, so no other events will be received that
 * need handling
 */
event.id = CTAEVN_NULL_EVENT;
do
{
    ctaWaitEvent( ctaQueue, &event, 5000 );
}
while( (event.id != CTAEVN_OPEN_SERVICES_DONE) &&
       (event.id != CTAEVN_WAIT_TIMEOUT) );

/* check if binding succeeded */
if( (pSap->event.id != CTAEVN_OPEN_SERVICES_DONE) ||
    (pSap->event.value != CTA_REASON_FINISHED) )
{
    ctaGetText( event.ctahd, event.value, sErr, sizeof( sErr ) );
    printf( "ERROR opening TUP service [%s]\n", sErr );
    ctaDestroyQueue( pSap->ctaQueue );    /* destroys context too */
    return( ... );
}