OpenClovis Logo

API Usage Examples

Code Examples.

Code Examples.

Example illustrating a simple svn initialize/finalize cycle for gms client

/* SVC handle which will be populated by GMS client */
static ClGmsHandleT handle = 0;
/* Current version supported by gms */
static ClVersionT correct_version = {'B',1,1};
/* Callbacks to be provided by user. Since we are using any of
* these functionality here, we will set all of them to NULL
*/
static ClGmsCallbacksT callbacks = {
.clGmsClusterMemberGetCallback = NULL,
.clGmsGroupTrackCallback = NULL,
.clGmsGroupMemberGetCallback = NULL
};
ClRcT simple_init_finalize_cycle()
{
ClRcT rc = CL_OK;
/* Calling gms intialize with proper values */
rc = clGmsInitialize(&handle, &callbacks, &correct_version);
if (rc != CL_OK)
{
printf("GMS Initialize failed with rc [0x%x]\n",rc);
return rc;
}
/* Calling finalize on the handle */
rc = clGmsFinalize(handle);
if (rc != CL_OK)
{
printf("GMS finalize failed with rc [0x%x]\n",rc);
return rc;
}
return CL_OK;
}
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
ClHandleT ClGmsHandleT
Handle for using the GMS API.
Definition: clClmTmsCommon.h:137
ClRcT clGmsFinalize(CL_IN ClGmsHandleT gmsHandle)
Cleans up the GMS library.
ClRcT clGmsInitialize(CL_OUT ClGmsHandleT *gmsHandle, CL_IN const ClGmsCallbacksT *gmsCallbacks, CL_INOUT ClVersionT *version)
Initializes the GMS library and registers the callback functions.
Version Information for various services.
Definition: clCommon.h:250
This callback structure is provided to the GMS library during Initialization.
Definition: clClmTmsCommon.h:810
ClGmsClusterTrackCallbackT clGmsClusterTrackCallback
This callback is invoked to notify the registered user about any change in the cluster configuratio...
Definition: clClmTmsCommon.h:828

Example showing cluster track and track stop functionality

/* SVC handle which will be populated by GMS client */
static ClHandleT handle = 0;
/* Current version supported by gms */
static ClVersionT correct_version = {'B',1,1};
/* Callbacks to be provided by user. Since we are using any of
* these functionality here, we will set all of them to NULL
*/
/* Flag to indicate whether callback was invoked or not */
static ClBoolT callback_invoked = CL_FALSE;
static void clGmsClusterTrackCallbackFuntion (
CL_IN const ClGmsClusterNotificationBufferT *notificationBuffer,
CL_IN ClUint32T numberOfMembers,
{
callback_invoked = CL_TRUE;
printf("Inside cluster track callback function. \n");
}
static ClGmsCallbacksT callbacks_non_null = {
.clGmsClusterTrackCallback = clGmsClusterTrackCallbackFuntion,
.clGmsClusterMemberGetCallback = NULL,
.clGmsGroupTrackCallback = NULL,
.clGmsGroupMemberGetCallback = NULL
};
ClRcT track_changes_and_changes_only_flag_test()
{
ClRcT rc = CL_OK;
/* Initialize svc client handle */
rc = clGmsInitialize(&handle,&callbacks_non_null,&correct_version);
if (rc != CL_OK)
{
printf("GMS Initialize failed with rc 0x%x\n",rc);
return rc;
}
/* Set the flag to false before triggering the event */
callback_invoked = CL_FALSE;
/* Register for cluster track */
if (rc != CL_OK)
{
printf("GMS cluster track failed with rc 0x%x\n",rc);
return rc;
}
/* NOTE: In the below wait period, bring down a node or bringup a node
* in the cluster. This will trigger the invocation of the callback.*/
/* Wait and see if the callback is called */
sleep(10);
if (callback_invoked != CL_TRUE)
{
printf("Cluster track callback is not invoked\n");
return CL_OK;
}
callback_invoked = CL_FALSE;
/* Now change the flag to TRACK_CHANGES_ONLY flag */
if (rc != CL_OK)
{
printf("clGmsClusterTrack with TRACK_CHANGES_ONLY flag failed with "
"rc = 0x%x",rc);
return rc;
}
/* Trigger an event by killing a node or bringing up another node
* in the cluster */
sleep(10);
if (callback_invoked != CL_TRUE)
{
printf("Cluster track callback is not invoked\n");
return CL_OK;
}
/* Track stop */
rc = clGmsClusterTrackStop(handle);
if (rc != CL_OK)
{
printf("clGmsClusterTrackStop failed with rc = 0x%x",rc);
return rc;
}
/* Finalize */
rc = clGmsFinalize(handle);
if (rc != CL_OK)
{
printf("finalize failed with rc = 0x%x",rc);
return rc;
}
}
#define CL_FALSE
define the False
Definition: clCommon.h:61
#define CL_TRUE
define the Truth
Definition: clCommon.h:59
#define CL_IN
CL_IN macro assists in clearly defining arguments of an API, but has no actual meaning.
Definition: clCommon.h:106
ClRcT clGmsClusterTrackStop(CL_IN ClGmsHandleT gmsHandle)
Stops all the clusters tracking.
ClRcT clGmsClusterTrack(CL_IN ClGmsHandleT gmsHandle, CL_IN ClUint8T trackFlags, CL_INOUT ClGmsClusterNotificationBufferT *notificationBuffer)
Configures the cluster tracking mode.
@ CL_GMS_TRACK_CHANGES
To subscribe for view notifications that includes current view and the recent change.
Definition: clClmTmsCommon.h:183
@ CL_GMS_TRACK_CHANGES_ONLY
To subscribe for delta notifications.
Definition: clClmTmsCommon.h:188
Buffer to convey the view: the list of nodes and their status.
Definition: clClmTmsCommon.h:337

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