Previous Topic: Context Structures

Next Topic: Sm_Api_Context_t

Sm_Api_AppSpecificContext_t

This structure contains shared memory information.

Syntax

The syntax of this structure is:

typedef struct
{
   void* pHandle;
   Sm_Api_GetBufferFunc fGetBuffer;
   Sm_Api_AllocBufferFunc fAllocBuffer; 
   Sm_Api_FreeBufferFunc fFreeBuffer;
   Sm_Api_GetBufferSizefunc fGetBufferSize;
} Sm_Api_AppSpecificContext_t;

Field

Description

pHandle

A handle to be passed, required by memory management functions. This handle is obtained from the pAppSpecific field of Sm_Api_Context_t.

fGetBuffer

Function that returns a pointer to the previously allocated request-specific memory or NULL if no memory was allocated.

pHandle is the function's only parameter.

 

fAllocBuffer

Function that allocates request-specific memory and returns a pointer to the allocated buffer. It returns NULL if the buffer has already been allocated or no memory is available.

Parameters are pHandle and an int specifying the size of the buffer.

 

fFreeBuffer

Function that releases any request-specific memory associated with the passed pHandle argument. No value is returned.

 

fGetBufferSize

Function that retrieves the size of the buffer.

 

Function Declarations

In structure Sm_Api_AppSpecificContext_t, the functions fGetBuffer, fAllocBuffer, fFreeBuffer, and fGetBufferSize are declared in SmApi.h as follows:

fGetBuffer

typedef void* (SM_EXTERN *Sm_Api_GetBufferFunc) 
    (const void *pHandle);

fAllocBuffer

typedef void* (SM_EXTERN *Sm_Api_AllocBufferFunc) 
    (const void *pHandle, const int nSize);

fFreeBuffer

typedef void (SM_EXTERN *Sm_Api_FreeBufferFunc) 
   (const void *pHandle);

fGetBufferSize

typedef int (SM_EXTERN *Sm_Api_GetBufferSizeFunc) 
   (const void *pHandle);

Example

// Allocate 64 bytes
char* pBuffer = (char*) lpApiContext->pAppSpecific->fAllocBuffer
                (lpApiContext->pAppSpecific->pHandle, 64);
strcpy (pBuffer, "id=5");
...

// Use it somewhere else
char id[20];
char* pBuffer = (char*) lpApiContext->pAppSpecific->fGetBuffer
                (lpApiContext->pAppSpecific->pHandle);
if (pBuffer != NULL)
{
   strcpy (id, pBuffer);
}

//Free the memory when done
...
(char*) lpApiContext->pAppSpecific->fFreeBuffer
                (lpApiContext->pAppSpecific->pHandle);


Copyright © 2010 CA. All rights reserved. Email CA about this topic