Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDKB-57891: Rollback support of DM parameters handled in RBUS #238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rbus_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void rbusProperty_Append(rbusProperty_t property, rbusProperty_t back);
uint32_t rbusProperty_Count(rbusProperty_t property);

void rbusProperty_fwrite(rbusProperty_t prop, int depth, FILE* fout);

void rbusProperty_Copy(rbusProperty_t destination, rbusProperty_t source);
#ifdef __cplusplus
}
#endif
Expand Down
81 changes: 69 additions & 12 deletions src/rbus/rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ static int _master_event_callback_handler(char const* sender, char const* eventN
static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbusMessage *response)
{
rbusError_t rc = 0;
rbusError_t err = 0;
int sessionId = 0;
int numVals = 0;
int loopCnt = 0;
Expand All @@ -1429,9 +1430,9 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu
rbusProperty_t* pProperties = NULL;
struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle;
rbusSetHandlerOptions_t opts;

rbusProperty_t tmpProperties = NULL;
memset(&opts, 0, sizeof(opts));

rbusGetHandlerOptions_t options;
rbusMessage_GetInt32(request, &sessionId);
rbusMessage_GetString(request, (char const**) &pCompName);
rbusMessage_GetInt32(request, &numVals);
Expand Down Expand Up @@ -1470,6 +1471,14 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu
el = retrieveInstanceElementEx(handle, handleInfo->elementRoot, paramName, true);
if(el != NULL)
{
rbusProperty_t prop = NULL;
if(el->cbTable.getHandler)
{
rbusProperty_Init(&prop, paramName, NULL);
ELM_PRIVATE_LOCK(el);
rc = el->cbTable.getHandler(handle, prop, &options);
ELM_PRIVATE_UNLOCK(el);
}
if(el->cbTable.setHandler)
{
if(isCommit && loopCnt == numVals -1)
Expand All @@ -1482,11 +1491,37 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu
{
RBUSLOG_WARN("Set Failed for %s; Component Owner returned Error", paramName);
pFailedElement = paramName;
RBUSLOG_DEBUG("Reverting because set failed for this param:%s",pFailedElement);
/*===========< Rollback old values >============*/
rbusProperty_t prevProp = tmpProperties;
while(prevProp)
{
char const* prevParamName = rbusProperty_GetName(prevProp);
el = retrieveInstanceElement(handleInfo->elementRoot, prevParamName);
ELM_PRIVATE_LOCK(el);
err = el->cbTable.setHandler(handle, prevProp, &opts);
ELM_PRIVATE_UNLOCK(el);
prevProp = rbusProperty_GetNext(prevProp);
}
if(err != RBUS_ERROR_SUCCESS)
RBUSLOG_WARN("Reverting paramValues to initial values failed");
break;
}
else
{
setPropertyChangeComponent(el, pCompName);
/* ======== < Old values backup >============= */
if (prop)
{
if (tmpProperties == NULL)
tmpProperties = prop;
else
{
rbusProperty_Append(tmpProperties, prop);
rbusProperty_Release(prop);
}
}

}
}
else
Expand All @@ -1505,6 +1540,7 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu
break;
}
}

}
else
{
Expand All @@ -1523,6 +1559,12 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu
exit:
rbusMessage_Init(response);
rbusMessage_SetInt32(*response, (int) rc);

if (rc == RBUS_ERROR_SUCCESS)
{
rbusPropertyList_appendToMessage(tmpProperties, *response);
rbusProperty_Release(tmpProperties);
}
if (pFailedElement)
rbusMessage_SetString(*response, pFailedElement);

Expand All @@ -1537,7 +1579,6 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu

return;
}

/*
convert a registration element name to a instance name based on the instance numbers in the original
partial path query
Expand Down Expand Up @@ -3954,16 +3995,19 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop
{
rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT;
rbusCoreError_t err = RBUSCORE_SUCCESS;
VERIFY_HANDLE(handle);
VERIFY_HANDLE(handle);
rbusMessage setRequest, setResponse;
struct _rbusHandle* handleInfo = (struct _rbusHandle*) handle;
rbusValueType_t type = RBUS_NONE;
rbusProperty_t current;

int numPrevProps = 0;
rbusProperty_t prevProperties = NULL;
VERIFY_NULL(handle);

if (handleInfo->m_handleType != RBUS_HWDL_TYPE_REGULAR)
{
return RBUS_ERROR_INVALID_HANDLE;
}

if (numProps > 0 && properties != NULL)
{
Expand Down Expand Up @@ -4032,7 +4076,6 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop
char* componentName = NULL;
char const* firstParamName = NULL;
int batchCount = 0;

for(i = 0; i < numProps; ++i)
{
if(componentNames[i])
Expand All @@ -4053,7 +4096,6 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop

if(componentName)
{

rbusMessage_Init(&setRequest);

/* Set the Session ID first */
Expand Down Expand Up @@ -4082,11 +4124,10 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop
free(componentNames[i]);
componentNames[i] = NULL;
}
}
}

/* Set the Commit value; FIXME: Should we use string? */
rbusMessage_SetString(setRequest, (!opts || opts->commit) ? "TRUE" : "FALSE");

if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_SETPARAMETERVALUES, setRequest, rbusConfig_ReadSetTimeout(), &setResponse)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("set by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, firstParamName);
Expand All @@ -4098,20 +4139,35 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop
rbusLegacyReturn_t legacyRetCode = RBUS_LEGACY_ERR_FAILURE;
int ret = -1;
rbusMessage_GetInt32(setResponse, &ret);

RBUSLOG_DEBUG("Response from the remote method is [%d]!", ret);
RBUSLOG_DEBUG("Response from the remote method is [%d]!", ret);
errorcode = (rbusError_t) ret;
legacyRetCode = (rbusLegacyReturn_t) ret;

if((errorcode == RBUS_ERROR_SUCCESS) || (legacyRetCode == RBUS_LEGACY_ERR_SUCCESS))
{
errorcode = RBUS_ERROR_SUCCESS;
RBUSLOG_DEBUG("Successfully Set the Value");
rbusPropertyList_initFromMessage(&prevProperties, setResponse);
}
else
{
rbusMessage_GetString(setResponse, &pErrorReason);
RBUSLOG_WARN("Failed to Set the Value for %s", pErrorReason);
rbusSetOptions_t revertOpts = {true,0};
rbusProperty_t first;
first = prevProperties;
numPrevProps = 0;
while(prevProperties)
{
numPrevProps++;
prevProperties = rbusProperty_GetNext(prevProperties);
}
prevProperties = first;
rbusError_t result;
result = rbus_setMulti(handle, numPrevProps, prevProperties, &revertOpts);
if(result == RBUS_ERROR_SUCCESS)
RBUSLOG_DEBUG("Successfully reverted back the values");
else
RBUSLOG_WARN("Failed to revert back the initial values");
if(legacyRetCode > RBUS_LEGACY_ERR_SUCCESS)
{
errorcode = CCSPError_to_rbusError(legacyRetCode);
Expand Down Expand Up @@ -4147,6 +4203,7 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop
if(componentNames)
free(componentNames);
}
free(prevProperties);
return errorcode;
}

Expand Down
17 changes: 17 additions & 0 deletions src/rbus/rbus_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ rbusProperty_t rbusProperty_AppendBytes(rbusProperty_t property, char const* nam
return p;
}


void rbusProperty_Copy(rbusProperty_t destination, rbusProperty_t source)
{
if(destination->name)
{
free(destination->name);
destination->name = NULL;
}
if(source->name)
destination->name = strdup(source->name);
rbusValue_Copy(destination->value, source->value);
if(source->next)
{
rbusProperty_SetNext(destination, source->next);
}
}

#define DEFINE_PROPERTY_TYPE_FUNCS(T1, T2, T3, T4)\
rbusProperty_t rbusProperty_Init##T1(char const* name, T2 data)\
{\
Expand Down