OpenClovis Logo

API Usage Examples
Group Membership Service

Code Examples. More...

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 = {
.clGmsClusterTrackCallback = NULL,
.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;
}

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;
}
}

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