OpenClovis Logo

API Usage Examples
Buffer Management

Code Examples. More...

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
}

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