Adding a new parameter to the existing component
This method can be utilized if the sample application has functionality similar to an existing component or if there are no detailed configurations required to be done from head-end using different protocols (which are abstracted by RDK-B and converter to TR-181 format). In this options, a new TR-181 data model can be added to an existing component. To achieve this, the changes required are
- Add the data model details in the corresponding xml file
- Add the data model parameter to the corresponding DML file
- Add the underlying functionality to the corresponding API file
Refer files in folder sampleDatamodel_Existing_Component for more details.
Adding the data model details in XML file
A data model is known to exist, along with its characteristics, based on its configuration in xml file. In order to add the details in XML, the first thing to check is whether the type of the data model (Boolean, int , string etc. ) is already supported in the targeted object family. If it is already present, skip to next section where adding data model parameter is explained. If it is not present, need to add the set and get function details to xml file
<object>
<name>X_CISCO_COM_DeviceControl</name>
<objectType>object</objectType>
<functions>
<func_GetParamTypeValue>GetFunctionName_For_Type</func_GetParamTypeValue>
<func_SetParamTypeValue> SetFunctionName_For_Type </func_SetParamTypeValue>
In the above code, replace the highlighted text within <> with proper data type. Also, replace the function name with proper get and set function names for the type as defined in DML file in next section
In order to add the details of data model, add the below code block within the <parameters> </parameters> block. Syntax should be
<parameter>
<name>DataModel_Name</name>
<type>DataModel_Type</type>
<syntax>DataModel_Type_Syntax</syntax>
<writable>True_If_DataModel_Is_Writable_False_If_ReadOnly</writable>
</parameter>
In the above snippet, replace highlighted code with respective values (use existing data models for a reference, if required)
In the example case, the data model will be added under Device.X_CISCO_COM_DeviceControl. The data model is of type bool. The set and get functions are X_CISCO_COM_DeviceControl_GetParamBoolValue and X_CISCO_COM_DeviceControl_SetParamBoolValue. So the code will look like
<object>
<name>X_CISCO_COM_DeviceControl</name>
<objectType>object</objectType>
<functions>
<func_GetParamBoolValue>X_CISCO_COM_DeviceControl_GetParamBoolValue</func_GetParamBoolValue>
<func_SetParamBoolValue>X_CISCO_COM_DeviceControl_SetParamBoolValue</func_SetParamBoolValue>
..
..
..
<parameters>
<parameter>
<name>SampleAppEnable</name>
<type>boolean</type>
<syntax>bool</syntax>
<writable>true</writable>
</parameter>
Add the data model parameter to the corresponding DML file (cosa_x_cisco_com_devicecontrol_dml.*)
Any invocation of the data model results in the call being redirected to the functions defined in DML file. These are the same functions that are being mentioned in the XML file. Changes include (refer attached code files for details)
- Declare the set and get functions (mentioned in the XML) in header file and define them in c file (Skip this if data model is of an existing type)
- In the definition of both functions, add an ‘if’ case to check if the invocation is for the defined data model
if (AnscEqualString(ParamName, “DataModelName“, TRUE))
{
…
}
Replace the highlighted part in above snippet with the data model name mentioned in XML
- In the get function, either invoke the corresponding get function in API file or directly get it from syscfg APIs. In either case, update the output variable passed into the function (refer attached code files for details)
- In the set function, invoke the corresponding set function in API file. Return status based on API function return value (refer attached code files for details)
In the example, the below code will be added to the get function X_CISCO_COM_DeviceControl_GetParamBoolValue , which will read the value from syscfg db and returns the value
if (AnscEqualString(ParamName, “SampleAppEnable”, TRUE))
{
char buf[8] = {0};
syscfg_get( NULL, “sampleapp_enabled”, buf, sizeof(buf));
if( buf != NULL )
{
pMyObject->Enable=(BOOL)atoi(buf);
*pBool=pMyObject->Enable;
CcspTraceInfo((“syscfg get done for SampleApp\n”));
return TRUE;
}
else
{
CcspTraceInfo((“syscfg get failed for SampleApp \n”));
*pBool=pMyObject->Enable;
return TRUE;
}
}
For the set function X_CISCO_COM_DeviceControl_SetParamBoolValue, the below code snippet is used (where CosaDmlDcSetSampleApp is the API function for set) which will set the value in syscfg db, invokes the API function and then returns the status
if (AnscEqualString(ParamName, “SampleAppEnable”, TRUE))
{
char buf[8] = {0};
pMyObject->Enable = bValue;
snprintf(buf,sizeof(buf),”%d”,bValue);
if ( syscfg_set(NULL,”sampleapp_enabled”, buf) != 0 )
{
AnscTraceWarning((“syscfg_set failed\n”));
}
else
{
if(syscfg_commit() != 0)
{
AnscTraceWarning((“syscfg_commit failed \n”));
}
}
retStatus = CosaDmlDcSetSampleApp(NULL, pMyObject->Enable);
if ( retStatus != ANSC_STATUS_SUCCESS )
return FALSE;
return TRUE;
}
Add the API in corresponding API file (cosa_x_cisco_com_devicecontrol_apis.*)
The API file contains the actual API (invoked by the function in DML file) that performs the action intended to be performed by the SET operation (and in most cases the data fetch for the GET operation). Changes include (refer attached code files for details)
- Add the declaration of the API in header file
- Add the definition in the corresponding C file
- In the definition body, run the corresponding commands to start the service (either using system () or exec () or choice of other functions)
In the example, the below code snippet is added to start (restart is used in case service is stuck and Data Model is invoked to recover) and stop the service
ANSC_STATUS
CosaDmlDcSetSampleApp
(
ANSC_HANDLE hContext,
BOOLEAN pFlag
)
{
if (pFlag == 0)
{
system(“systemctl stop sample”);
CcspTraceInfo((“Inside stop\n”));
return ANSC_STATUS_SUCCESS;
}
else
{
system(“systemctl restart sample”);
CcspTraceInfo((“Inside restart\n”));
return ANSC_STATUS_SUCCESS;
}
// return ANSC_STATUS_SUCCESS;
}

