ctaAttachContext

Allows an application to attach to an existing context.

Prototype

DWORD ctaAttachContext ( CTAQUEUEHD ctaqueuehd, unsigned userid, char *descriptor, CTAHD *ctahd)

Argument

Description

ctaqueuehd

Event queue handle returned by ctaCreateQueue.

userid

User-specified value repeated in all events returned for this context.

descriptor

Pointer to a context descriptor created by or obtained from another application.

ctahd

Pointer to a returned context handle.


Return values

Return value

Description

SUCCESS

 

CTAERR_BAD_ARGUMENT

Supplied context name is unavailable.

CTAERR_INCOMPATIBLE_SERVICES

On the server on which the context is created, at least one of the available services conflicts with the same service that is open on another server. A client application can use only one instance of a service at a time.

CTAERR_INVALID_CTAHD

 

CTAERR_INVALID_CTAQUEUEHD

 

CTAERR_NOT_IMPLEMENTED

This function is not available in the execution mode associated with the specified context.

CTAERR_NOT_INITIALIZED

Natural Access is not initialized. Call ctaInitialize first.

CTAERR_SVR_COMM

Server communication error.


Events

None.

Details

This function enables applications using local or remote instances of Natural Access Server (ctdaemon) to share contexts.

The application creating the context must either specify the descriptor with ctaCreateContextEx or obtain the descriptor with ctaGetObjDescriptor. The application passes the descriptor to another application, which can then use ctaAttachContext and the descriptor to attach to the context.

The attaching application can use the returned ctahd to open services on the specified context, or invoke functions for service instances already opened on the context. Whether the attaching application can immediately use the service instances opened on the context is determined by the context access mode set with ctaCreateContextEx.

For more information on descriptors, see ctaGetObjDescriptor.

See also

ctaCreateContext, ctaCreateContextEx, ctaGetObjDescriptor, ctaOpenServices, ctaSetEventSources

Example

typedef struct
{
    unsigned   line;
    unsigned   ag_board;   
    unsigned   mvip_stream;
    unsigned   mvip_slot;
    CTAQUEUEHD ctaqueuehd;
    CTAHD      ctahd;
    VCEHD      demovh;
    SWIHD      demoswihd;
} DEMOCONTEXT ;
/* 
 * Attach a Natural Access context with its own queue, storing handles in 
 * demo context (cx) which was created by the caller. 
 */
void DemoAttachContext(unsigned line, DEMOCONTEXT *cx)
{
    char cxname[12];
    int ret;

    cx->line = line;

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

    /* Create queue and attach all service managers */
    ctaCreateQueue( NULL, 0, &(cx->ctaqueuehd) );

    /* Attach context with address of demo context as userid */
    ret = ctaAttachContext( NULL, cx->ctaqueuehd, (unsigned) cx, 
                      cxname, &(cx->ctahd) );
    if (SUCCESS != ret)
         printf("Unable to attach context\n");
}