ctaOpenServices

Opens one or more services on the specified context.

Prototype

DWORD ctaOpenServices ( CTAHD ctahd, CTA_SERVICE_DESC svclist[], unsigned nsvcs)

Argument

Description

ctahd

Context handle.

svclist

List of services to open on the context. The CTA_SERVICE_DESC structure is

typedef struct
{
   CTA_SERVICE_NAMEname;
   CTA_SERVICE_ADDRsvcaddr;
   CTA_SERVICE_ARGSsvcargs;
   CTA_MVIP_ADDR mvipaddr;
} CTA_SERVICE_DESC;

The CTA_SERVICE_NAME structure is:

typedef struct
{
   char *svcname;
   char *svcmgrname;
} CTA_SERVICE_NAME;

The CTA_SERVICE_ADDR structure is reserved and should be initialized to zero (0).

The CTA_SERVICE_ARGS structure is:

typedef struct
{
   charstrarg [40];
   DWORD args [10];
} CTA_SERVICE_ARGS;

The CTA_MVIP_ADDR structure is:

typedef struct
{
   DWORD board;
   DWORD bus;
   DWORD stream;
   DWORD timeslot;
   DWORD mode;
} CTA_MVIP_ADDR;

nsvcs

Number of services in svclist.


Return values

Return value

Description

SUCCESS

 

CTAERR_INVALID_CTAHD

An invalid context handle was passed as an argument to a function, or the context was destroyed by another thread.

CTAERR_INVALID_SEQUENCE

An open or close service is pending on the context.

CTAERR_NOT_FOUND

One of the following conditions occurred:

  • One or more of the services in svclist are not registered with Natural Access.

  • Application requested a service on a local or remote server that is not specified in the server configuration file (for example, cta.cfg).

  • Service manager is not attached to the event queue.

CTAERR_NOT_INITIALIZED

Natural Access is not initialized. Call ctaInitialize first.

CTAERR_SERVICE_IN_USE

One or more of the services are already open on the context.

CTAERR_SVR_COMM

Server communication error.


Events

CTAEVN_OPEN_SERVICES_DONE

The event value field contains the open services completion status. If the value is CTA_REASON_FINISHED, all services successfully opened.

If the event value field is not CTA_REASON_FINISHED, one of the services failed to open. The resources associated with all of the services listed in svclist are de-allocated and the context is returned to the state it was in just before the call to ctaOpenServices.

When opening the ADI service, the following errors can be returned in the event value field:

Error

Description

ADIERR_CANNOT_CREATE_CHANNEL

Out of resources on board.

CTAERR_BAD_ARGUMENT

Invalid MVIP stream, timeslot, or mode.

CTAERR_INVALID_BOARD

Invalid board number. The board was not configured by the configuration utility.

CTAERR_OUTPUT_ACTIVE

DSP timeslot is in use.


Details

ctaOpenServices opens one or more services on the specified context (ctahd). If any service fails to open, all services successfully opened in this call are closed and a service-specific error is returned in the value field of the CTAEVN_OPEN_SERVICES_DONE event.

Note: Ensure that the services you open on a context are services that are specified in the server configuration file.

ctaOpenServices is asynchronous and returns immediately. When all services are successfully opened, a DONE event returns to the application by way of the application event queue.

See also

ctaAttachContext

Example

void DemoOpenPort(
    unsigned    userid,              /* for ctaCreateContext                */
    char       *contextname,         /* for ctaCreateContext                */
    CTA_SERVICE_DESC services[],     /* for ctaOpenServices                 */
    unsigned    numservices,         /* number of "services"                */
    CTAQUEUEHD *pctaqueuehd,         /* returned Natural Access queue handle*/
    CTAHD      *pctahd)              /* returned Natural Access context hd   */
{
    CTA_EVENT event = { 0 };

    /* Open the Natural Access application queue, attaching all defined
     * service managers.
     */
    ctaCreateQueue( NULL, 0, pctaqueuehd );

    /* Create a Natural Access context */
    ctaCreateContext( *pctaqueuehd, userid, contextname, pctahd );

    /* Open services */
    ctaOpenServices( *pctahd, services, numservices );

    /* Wait for the service manager and services to be opened asynchronously */
    do
    {
        ctaWaitEvent( *pctaqueuehd, &event, CTA_WAIT_FOREVER ); 
    } while (event.id != CTAEVN_OPEN_SERVICES_DONE);
      
    if (event.value != CTA_REASON_FINISHED)
        printf ("Opening services failed: val=0x%x\n", event.value );
}

void DemoStartLine(DEMOCONTEXT *cx)
{
    char cxname[12];

    CTA_SERVICE_DESC services[] =        /* for ctaOpenServices */
    {   { {"ADI", "ADIMGR"}, { 0 }, { 0 }, { 0 } },
        { {"SWI", "SWIMGR"}, { 0 }, { 0 }, { 0 } },
        { {"VCE", "VCEMGR"}, { 0 }, { 0 }, { 0 } }
    };

    /* Fill in ADI service (index 0) MVIP address information */
    services[0].mvipaddr.board    = cx->ag_board;
    services[0].mvipaddr.stream   = cx->mvip_stream;
    services[0].mvipaddr.timeslot = cx->mvip_slot;
    services[0].mvipaddr.mode     = ADI_FULL_DUPLEX;

/* Context name will be printed in all trace records for this context */
    sprintf( cxname, "DEMOCX%04d", cx->line );

    DemoOpenPort( 0, "DEMOCONTEXT", services,
                  sizeof(services)/sizeof(services[0]),
                  &(cx->ctaqueuehd), &(cx->ctahd) );
}

 

Note: For QX boards, replace ADIMGR with QDIMGR.