OpenClovis Logo

API Usage Examples

Code Examples.

Code Examples.

The following code example shows how to use few of the basic APIs of the buffer library. The following code shows initializing the buffer library, creation of a buffer message, writing and reading to the buffer message and deleting it once the application is done with using it.

ClRcT errorCode = CL_OK;
// Initializes the buffer management library. The application has
// to specify pool configuration through clBufferInitialize() API,
// but if NULL is passed then the Buffer library will choose
// the default configuration for Pool.
errorCode = clBufferInitialize(NULL);
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
// Creates a message. And the message handle will be returned
// in myMessage. To perform any buffer operations on the buffer
// message this buffer message handle should be used.
ClBufferHandleT myMessage = 0;
errorCode = clBufferCreate(&myMessage);
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
//Writes "n" number of bytes into the message
ClUint8T* pByteBuffer = clHeapAllocate(15);
strcpy(pByteBuffer, "Hello Clovis");
errorCode = clBufferNBytesWrite(myMessage, pByteBuffer, 15);
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
//Returns the length of the message
ClUint32T length = 0;
errorCode = clBufferLengthGet(myMessage, &length)
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
//Reads "n" number of bytes from the message
ClUint32T length = 15;
errorCode = clBufferNBytesRead(myMessage, pByteBuffer, &length);
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
//Prepends data to the message
strcpy(pByteBuffer, "ABRAKADABRA");
errorCode = clBufferDataPrepend(myMessage, pByteBuffer,
strlen("ABRAKADABRA")+1);
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
//Deletes the message
errorCode = clBufferDelete(&myMessage);
if(CL_OK != errorCode) {
//error occured. take appropriate action
}
ClRcT clBufferInitialize(const ClBufferPoolConfigT *pConfig)
Initializes the Buffer Management library.
ClPtrT ClBufferHandleT
The type of the handle for the buffer messages.
Definition: clBufferApi.h:82
ClRcT clBufferLengthGet(ClBufferHandleT messageHandle, ClUint32T *pMessageLength)
Returns the length of the message.
ClRcT clBufferNBytesWrite(ClBufferHandleT messageHandle, ClUint8T *pByteBuffer, ClUint32T numberOfBytesToWrite)
Writes the specified number bytes of data from a message.
ClRcT clBufferDelete(ClBufferHandleT *pMessageHandle)
Deletes the Buffers.
ClRcT clBufferDataPrepend(ClBufferHandleT messageHandle, ClUint8T *pByteBuffer, ClUint32T numberOfBytesToWrite)
Prepends specified number of bytes at the begining of message.
ClRcT clBufferCreate(ClBufferHandleT *pMessageHandle)
Creates a new message.
ClRcT clBufferNBytesRead(ClBufferHandleT messageHandle, ClUint8T *pByteBuffer, ClUint32T *pNumberOfBytesToRead)
Reads the specified number of bytes of data from a message.
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
ClPtrT clHeapAllocate(CL_IN ClUint32T size)
Allocates memory of the requested size.

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen