Version


CTA_INIT_PARMS mtp3Initparms = {0};
CTA_SERVICE_NAME mtp3ServiceNames[] = {{"MTP3", "MTP3MGR"}};
mtp3Initparms.size = sizeof(CTA_INIT_PARMS);
mtp3Initparms.traceflags = CTA_TRACE_ENABLE;
mtp3Initparms.parmflags = CTA_PARM_MGMT_SHARED;
mtp3Initparms.ctacompatlevel = CTA_COMPATLEVEL;
Ret = ctaInitialize(mtp3ServiceNames, 1, &mtp3Initparms);
if (Ret != SUCCESS) {
printf("ERROR code 0x%08x initializing Natural Access.", Ret);
exit( 1 );
}

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, "Mtp3SAP-%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 );
}

CTA_SERVICE_DESC mtp3OpenSvcLst[] = {{{"MTP3","MTP3MGR"}, {0}, {0}, {0}}};
mtp3OpenSvcLst[0].svcargs.args[0] = Board; /* board number */
mtp3OpenSvcLst[0].svcargs.args[1] = Sio; /* Service Information
* Octet */
mtp3OpenSvcLst[0].svcargs.args[2] = NSapNmb; /* network SAP number */
mtp3OpenSvcLst[0].svcargs.args[3] = MyEnt; /* application entity ID */
mtp3OpenSvcLst[0].svcargs.args[4] = DFLT_INST; /* Inst ID */
mtp3OpenSvcLst[0].svcargs.args[5] = SuId; /* Service user ID */
mtp3OpenSvcLst[0].svcargs.args[6] = poolsize; /* Pool size */
CTA_EVENT event; /* Event structure to wait for MTP3 events */
Ret = ctaOpenServices( ctaHd, mtp3OpenSvcLst, 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 MTP3 service [%s]\n", sErr );
ctaDestroyQueue( pSap->ctaQueue ); /* destroys context too */
return( );
}
Note: The previous example is only correct if the application uses a separate queue for each context/service instance. If the application opens multiple service instances against the same queue, either multiple SAPs on the same board or on multiple boards (in a redundant configuration), it must process events (call MTP3RetrieveMessage) for other contexts while waiting for the CTAEVN_OPEN_SERVICES_DONE event. Failure to do so can result in an infinite loop.

Version