/*******************************************************************************
Utility API: clTcActivateReplica

Descrition :

This API is utility related, used to set the local checkpoint as the active
replica.  The checkpoint data is retrieved and replica activate called only if
the checkpoint creation flag is ASYNC and COLLOCATED

*******************************************************************************/
static int
clTcActivateReplica ( ClTcCkptDataT *ckpt_data )
{
	ClRcT ret_code = CL_OK;
	ClCkptCheckpointDescriptorT ckpt_desc;

	ret_code = clCkptCheckpointStatusGet((ClCkptHdlT)ckpt_data->ckpt_hdl,
										 &ckpt_desc);

	if (ret_code != CL_OK)
	{
		printf("clTcActivateReplica: could not retrieve ckpt info: 0x%x\n",
			   ret_code);
		return ret_code;
	}

	/* If the check point type is async collocated
	 * then we need to set the active replica to this
	 * node
	 */
	if (ckpt_desc.checkpointCreationAttributes.creationFlags &
		CL_CKPT_CHECKPOINT_COLLOCATED)
	{
    	ret_code = clCkptActiveReplicaSet((ClCkptHdlT)ckpt_data->ckpt_hdl);
		if ( ret_code != CL_OK )
		{
			printf("clTcActivateReplica: Failed to activate replica :0x%x\n", 
				   ret_code);
		}
	}
	return ret_code;
}
SaAisErrorT saCkptCheckpointStatusGet(
        SaCkptCheckpointHandleT     checkpointHandle,
        SaCkptCheckpointDescriptorT *checkpointStatus)
{
    ClRcT                       rc         = CL_OK;
    SaAisErrorT                 safRc      = SA_AIS_OK;
    ClCkptCheckpointDescriptorT ckptStatus = {{0}};

    /*
     * Validate the input parameters.
     */
    if(checkpointStatus == NULL)
    {
        return SA_AIS_ERR_INVALID_PARAM;
    }
    
    memset(&ckptStatus,'\0',sizeof(ClCkptCheckpointDescriptorT));
    
    /*
     * Call the corresponding ckpt client library function.
     */
    rc = clCkptCheckpointStatusGet((ClCkptHdlT)checkpointHandle,
                                   &ckptStatus);
    
    /*
     * Copy the status info to the output buffer.
     */
    checkpointStatus->checkpointCreationAttributes.creationFlags     = 
                ckptStatus.checkpointCreationAttributes.creationFlags;
    checkpointStatus->checkpointCreationAttributes.checkpointSize    = 
                ckptStatus.checkpointCreationAttributes.checkpointSize;
    checkpointStatus->checkpointCreationAttributes.retentionDuration = 
                ckptStatus.checkpointCreationAttributes.retentionDuration;
    checkpointStatus->checkpointCreationAttributes.maxSectionSize    = 
                ckptStatus.checkpointCreationAttributes.maxSectionSize;
    checkpointStatus->checkpointCreationAttributes.maxSections       = 
                ckptStatus.checkpointCreationAttributes.maxSections;
    checkpointStatus->checkpointCreationAttributes.maxSectionIdSize  = 
                ckptStatus.checkpointCreationAttributes.maxSectionIdSize;
    checkpointStatus->numberOfSections = ckptStatus.numberOfSections;
    checkpointStatus->memoryUsed       = ckptStatus.memoryUsed;

    /*
     * Translate the clovis error type to SAF error type.
     */
    clErrorTxlate(rc, &safRc);
    
    return safRc;
}