OpenClovis Logo

API Usage Examples

Code Examples.

Code Examples.

The provision attributes for a hardware/software resource is specified during the modeling of the system. These resources are mere types and needs to be instantiated before using them. These resources needs to be associated with a component/application which creates the instances on coming up. The following example shows how to create/delete Prov MSO instances.

ClRcT rc = CL_OK;
ClUint32T attrData = 10;
ClNameT moIdName;
ClCorAttributeValueT attrValue[] = {
{ NULL, // Attribute path is NULL
0x10, // Specify attribute ID of WRITE-INITIALIZED
// attribute. Attribute ID can be found in
// $ASP_CONFIG/clCorMetaStruct.h file.
-1, // As this is a simple attribute give -1 for index
(ClPtrT)&attrData, // Value of WRITE-INITIALIZED attribute
sizeof(ClUint32T) } // Size of the given attribute
}
ClCorAttributeValueListT attrValueList = {
sizeof(attrValue)/sizeof(ClCorAttributeValueT),
&attrValue }
// SM_CFG_TBL_SIM1_TABLE_MO has one WRITE-INITALIZED attibute and
// one WRITE attribute. WRITE-INITALIZED attribute should be initialized
// at the time object creation.
#define SM_CFG_TBL_SIM1_TABLE_MO "\\Chassis:0\\smCfgTblSim1Table:0"
// Get MOID from MO Name
strcpy(moIdName.value, SM_CFG_TBL_SIM1_TABLE_MO);
moIdName.length = strlen(SM_CFG_TBL_SIM1_TABLE_MO);
rc = clCorMoIdNameToMoIdGet(&moIdName, &moId);
if(CL_OK != rc) {
return rc;
}
// Create Prov MSO
rc = clProvObjectCreate(&moId, &attrValue, &handle);
if(CL_OK != rc) {
return rc;
}
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
ClPtrT ClCorObjectHandleT
The structure ClCorObjectHandle is the handle to MO.
Definition: clCorMetaData.h:608
ClRcT clCorMoIdNameToMoIdGet(CL_IN ClNameT *moIdName, CL_OUT ClCorMOIdT *moId)
Retrieves moId in ClCorMOIdT format, when moId is provided in ClNameT format.
ClRcT clProvObjectCreate(CL_IN ClCorMOIdPtrT pMoId, CL_IN ClCorAttributeValueListPtrT attrList, CL_OUT ClCorObjectHandleT *pHandle)
Create Prov MSO object.
A name.
Definition: clCommon.h:197
ClUint16T length
Length of the name in bytes excluding '\0'.
Definition: clCommon.h:199
ClCharT value[CL_MAX_NAME_LENGTH]
Actual name represented as a null terminated ASCII string.
Definition: clCommon.h:201
The structure ClCorMOId contains MoId of the object, which is the address of the COR object.
Definition: clCorMetaData.h:918
Type to provide value for the initialized attributes.
Definition: clCorMetaData.h:1309
Type to provide the list of attribute values for initialized attributes.
Definition: clCorMetaData.h:1350
ClRcT rc = CL_OK;
// Delete Prov MSO at run time
rc = clProvObjectDelete(handle);
if(CL_OK != rc) {
//Error occurred. Take appropriate action.
return rc;
}
ClRcT clProvObjectDelete(CL_IN ClCorObjectHandleT handle)
Delete Prov MSO object.

After the creation of Prov MSO, the Object Implementor (OI) can receive all change notifications like set, delete, create for the resource. Provisioning library on initialization registers its callbacks with Transaction Agent and also registers the OI with Clovis Object Repository(COR) on the creation of Prov objects. Subsequent requests like create, set, delete on this object will invoke the callbacks registered by Prov. Following code segment explains how to handle provisioning attribute change notifications.

// This function prints attribute information
ClRcT clProvTxnInfoPrint(ClProvTxnDataT* pProvTxnData)
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS,
"Attr ID[0x%x] AttrType[0x%x] AttrDataType [0x%x] Operation[0x%x]",\
pProvTxnData->attrId, pProvTxnData->attrType,
pProvTxnData->attrDataType, pProvTxnData->provCmd);
switch(pProvTxnData->attrType)
{
{
switch(pProvTxnData->attrDataType)
{
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data8[%c]",
*(ClCharT*)pProvTxnData->pProvData);
break;
}
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data16[%x]",
*(ClUint16T*)pProvTxnData->pProvData);
break;
}
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data32[%x]",
*(ClUint32T*)pProvTxnData->pProvData);
break;
}
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data64[%llx]",
*(ClUint64T*)pProvTxnData->pProvData);
break;
}
}
}
}
// Callback function to validate attribute change
ClRcT cl<OIName><MSOName>ProvValidate(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
ClRcT rc = CL_OK;
// Perform some logic here to do validation of the attribute.
// For ex: range checking, checking for valid type etc
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Validate");
return rc;
}
// Callback function to update attribute change
ClRcT cl<OIName><MSOName>ProvUpdate(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
ClRcT rc = CL_OK;
// If any attribute of Prov MSO is changed
if(pProvTxnData->provCmd == CL_COR_OP_SET)
{
// Perform logic here to do set on the attribute
}
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Update");
clProvTxnInfoPrint(pProvTxnData);
return rc;
}
// Callback function to rollback in case cl<OIName><MSOName>Validate
// function returns error value
ClRcT cl<OIName><MSOName>ProvRollback(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
ClRcT rc = CL_OK;
// Perform logic here to rollback the changes done at validation phase
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Rollback");
return rc;
}
@ CL_COR_INT8
Character data type.
Definition: clCorMetaData.h:245
@ CL_COR_UINT16
Unsigned short.
Definition: clCorMetaData.h:260
@ CL_COR_UINT64
Unsigned long long data type.
Definition: clCorMetaData.h:280
@ CL_COR_UINT8
Unsigned character.
Definition: clCorMetaData.h:250
@ CL_COR_INT32
Integer data type.
Definition: clCorMetaData.h:265
@ CL_COR_UINT32
Unsigned integer data type.
Definition: clCorMetaData.h:270
@ CL_COR_INT64
Long long data type.
Definition: clCorMetaData.h:275
@ CL_COR_INT16
Short data type.
Definition: clCorMetaData.h:255
@ CL_COR_SIMPLE_ATTR
Simple data type.
Definition: clCorMetaData.h:329
@ CL_COR_OP_SET
Operation type is set.
Definition: clCorMetaData.h:664
#define clLog(severity, area, context,...)
This macro provides the support to log messages by specifying the severity of log message and server ...
Definition: clLogUtilApi.h:87
The structure is used to pass the job information while calling the object implementer's callback fun...
Definition: clProvApi.h:75
ClCorTypeT attrDataType
This is the actual data type of the attribute.
Definition: clProvApi.h:113
void * pProvData
It is a pointer to the address containing value of the attribute.
Definition: clProvApi.h:130
ClCorOpsT provCmd
The argument provides the operation type of the job.
Definition: clProvApi.h:83
ClCorAttrTypeT attrType
It is the type of the attribute that is for an array attribute it is CL_COR_ARRAY_ATTR otherwise it i...
Definition: clProvApi.h:106
ClCorAttrIdT attrId
The identifier for the attribute.
Definition: clProvApi.h:120

Provisioning library registers Read callback with Transaction Agent on initialization. This is being invoked when there is a request to read the attribute value of a resource. This is assuming the fact that the OI has done clCorPrimaryOISet() during its initialization. Following function will be called when get request comes to run-time attribute of given Prov MSO

ClRcT cl<OIName><MSOName>ProvRead(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
// Need to have a logic to get the proper value for given attribute ID
ClUint32T tempData = 10;
// Find out proper size of given attribute
ClUint32T dataLen = sizeof(tempData);
memcpy((pProvTxnData->pProvData), &tempData, dataLen);
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Read callback");
}

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