ctaQueryServerContexts

Obtains a list of available contexts on a server.

Prototype

DWORD ctaQueryServerContexts ( CTAHD ctahd, CTA_CNXT_INFO *buffer, unsigned bufsize, unsigned *ncontexts)

Argument

Description

ctahd

Context handle that specifies the server on which commands are executed. ctahd can be a void context handle.

buffer

Pointer to the CTA_CNXT_INFO structure for the context information:

typedef struct
{
    CTAHD ctahd;
    CTAQUEUEHD ctaqueuehd;
    char contextname[CTA_CONTEXT_NAME_LEN];
    DWORD flags;
    DWORD nclients;
    DWORD nsvcs;
} CTA_CNXT_INFO;

See the Details section for a description of these fields.

bufsize

Size of the CTA_CNXT_INFO array passed. Set to zero (0) to determine the number of contexts created on a Natural Access Server.

ncontexts

Pointer to the returned number of contexts.


Return values

Return value

Description

SUCCESS

 

CTAERR_BAD_ARGUMENT

Invalid server address.

CTAERR_NOT_IMPLEMENTED

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.


Details

ctaQueryServerContexts obtains a list of contexts available on the Natural Access Server (ctdaemon) specified by ctahd. CTA_CNXT_INFO is returned for every context. If the size of buffer is less than the current number of contexts on a server (but not zero), the maximum possible number of contexts are returned.

The returned CTA_CNXT_INFO structure contains the following fields:

Field

Description

ctahd

Server context handle.

ctaqueuehd

Server queue handle.

flags

Context flags.

nclients

Number of active clients attached to the context.

nsvcs

Number of services open on the context.


See also

ctaAttachContext, ctaCreateContext

Example

int DemoQueryContexts(CTAHD ctahd)
{
     unsigned size, count; 
     DWORD ret;
     /* Obtain the number of contexts on the server */
     ret = ctaQueryServerContexts(ctahd,NULL,0,&size);
     if ( ret != SUCCESS )
          return ret;
     CTA_CNXT_INFO* buffer = (CTA_CNXT_INFO*) 
          malloc(size * sizeof(CTA_CNXT_INFO));

     /* Retrieve the list of contexts */
     ret = ctaQueryServerContexts(ctahd,buffer,size,&count);
     if ( ret != SUCCESS )
          return ret;
     for (unsigned i = 0;i < count; i++)
            printf("Context %s with %d clients and %d services\n",
               
     buffer[i].contextname,buffer[i].nclients,buffer[i].nsvcs);
     free(buffer);
     return SUCCESS;
}