Skip to content

Commit

Permalink
Implementation of RBUS Publish API to support the setCommit functiona…
Browse files Browse the repository at this point in the history
…lity (#220)

* Updated provider side for METHOD_COMMIT
* Implemented setcommit in rbuscli

---------

Co-authored-by: Karunakaran A <[email protected]>
  • Loading branch information
NetajiPanigrahi and karuna2git authored Oct 15, 2024
1 parent 2b82a4d commit fc55df9
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/rbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,11 @@ rbusError_t rbus_set(
rbusValue_t value,
rbusSetOptions_t* opts);

rbusError_t rbus_setCommit(
rbusHandle_t handle,
char const* name,
rbusSetOptions_t* opts);

/** @fn rbusError_t rbus_setMulti(
* rbusHandle_t handle,
* int numProps,
Expand Down
70 changes: 70 additions & 0 deletions src/rbus/rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2698,6 +2698,12 @@ static int _callback_handler(char const* destination, char const* method, rbusMe
{
_set_callback_handler (handle, request, response);
}
else if (!strcmp(method, METHOD_COMMIT))
{
/*return success for commit*/
rbusMessage_Init(response);
rbusMessage_SetInt32(*response, RBUS_ERROR_SUCCESS);
}
else if(!strcmp(method, METHOD_GETPARAMETERNAMES))
{
_get_parameter_names_handler (handle, request, response);
Expand Down Expand Up @@ -3847,6 +3853,70 @@ rbusError_t rbus_set(rbusHandle_t handle, char const* name,rbusValue_t value, rb
return errorcode;
}

rbusError_t rbus_setCommit(rbusHandle_t handle, char const* name, rbusSetOptions_t* opts)
{
VERIFY_NULL(handle);
VERIFY_NULL(name);
VERIFY_HANDLE(handle);
rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT;
rbusCoreError_t err = RBUSCORE_SUCCESS;
rbusMessage setRequest, setResponse;
struct _rbusHandle* handleInfo = (struct _rbusHandle*) handle;
if (handleInfo->m_handleType != RBUS_HWDL_TYPE_REGULAR)
return RBUS_ERROR_INVALID_HANDLE;
rbusMessage_Init(&setRequest);
/* Set the Session ID first */
if ((opts) && (opts->sessionId != 0))
rbusMessage_SetInt32(setRequest, opts->sessionId);
else
rbusMessage_SetInt32(setRequest, 0);

/* Set the Component name that invokes the set */
rbusMessage_SetString(setRequest, handleInfo->componentName);
/* Set the Size of params */
rbusMessage_SetInt32(setRequest, 1);

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

/* Find direct connection status */
rtConnection myConn = rbuscore_FindClientPrivateConnection(name);
if (NULL == myConn)
myConn = handleInfo->m_connection;
if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_COMMIT, setRequest, rbusConfig_ReadSetTimeout(), &setResponse)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("set commit by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, name);
errorcode = rbusCoreError_to_rbusError(err);
}
else
{
rbusLegacyReturn_t legacyRetCode = RBUS_LEGACY_ERR_FAILURE;
int ret = -1;
char const* pErrorReason = NULL;
rbusMessage_GetInt32(setResponse, &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");
}
else
{
rbusMessage_GetString(setResponse, &pErrorReason);
RBUSLOG_WARN("Failed to Set the Value for %s", pErrorReason);
if(legacyRetCode > RBUS_LEGACY_ERR_SUCCESS)
{
errorcode = CCSPError_to_rbusError(legacyRetCode);
}
}
/* Release the reponse message */
rbusMessage_Release(setResponse);
}
return errorcode;
}

rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t properties, rbusSetOptions_t* opts)
{
rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT;
Expand Down
58 changes: 57 additions & 1 deletion utils/rbuscli/rbuscli.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ void show_menu(const char* command)
printf ("\tset Example.Prop1 string \"Hello World\" Example.Prop2 int 10\n\r");
printf ("\n\r");
}
else if(matchCmd(command, 4, "setcommit"))
{
printf ("\e[1msetc\e[0mommit \e[4mcomponent\e[0m [sessionid]\n\r");
printf ("Sets the value(s) of one or more parameters.\n\r");
printf ("Args:\n\r");
printf ("\t%-20sThe name of a component\n\r", "component");
printf ("\t%-20sOptional sessionid (default 0)\n\r", "sessionid");
printf ("Examples:\n\r");
printf ("\tsetc rbusSampleProvider \n\r");
printf ("\tsetc rbusSampleProvider 1\n\r");
printf ("\n\r");
}

else if(matchCmd(command, 3, "addrow"))
{
printf ("\e[1madd\e[0mrow \e[4mtable\e[0m [alias]\n\r");
Expand Down Expand Up @@ -511,6 +524,7 @@ void show_menu(const char* command)
printf ("\t\e[1mclose\e[0mdirect \e[4mpath\e[0m\n\r");
printf ("\t\e[1mget\e[0mvalues \e[4mpath\e[0m [\e[4mpath\e[0m \e[4m...\e[0m]\n\r");
printf ("\t\e[1mset\e[0mvalues \e[4mparameter\e[0m \e[4mtype\e[0m \e[4mvalue\e[0m [[\e[4mparameter\e[0m \e[4mtype\e[0m \e[4mvalue\e[0m] \e[4m...\e[0m] [commit]\n\r");
printf ("\t\e[1msetc\e[0mommit \e[4mcomponents\e[0m [sessionid]\n\r");
printf ("\t\e[1madd\e[0mrow \e[4mtable\e[0m [alias]\n\r");
printf ("\t\e[1mdel\e[0mrow \e[4mrow\e[0m\n\r");
printf ("\t\e[1mgetr\e[0mows \e[4mpath\e[0m\n\r");
Expand Down Expand Up @@ -1518,6 +1532,40 @@ void validate_and_execute_set_cmd (int argc, char *argv[])
}
}

void validate_and_execute_setcommit_cmd (int argc, char *argv[])
{
rbusError_t rc = RBUS_ERROR_SUCCESS;
int i = argc - 2;
bool isCommit = true;
unsigned int sessionId = 0;

if (!verify_rbus_open())
return;

if ((i >= 1) && (i <= 2))
{
if (argv[3])
{
sessionId = atoi(argv[3]);
}

rbusSetOptions_t opts = {isCommit,sessionId};
rc = rbus_setCommit(g_busHandle, argv[2], &opts);
if(RBUS_ERROR_SUCCESS == rc)
{
RBUSCLI_LOG ("setcommit succeeded..\n\r");
}
else
{
RBUSCLI_LOG ("setcommit failed with return value: %d\n\r", rc);
}
}
else
{
printf ("Invalid arguments. Please see the help\n\r");
}
}

void validate_and_execute_getnames_cmd (int argc, char *argv[])
{
bool nextLevel = true;
Expand Down Expand Up @@ -2339,6 +2387,10 @@ int handle_cmds (int argc, char *argv[])
{
validate_and_execute_set_cmd (argc, argv);
}
else if(matchCmd(command, 4, "setcommit"))
{
validate_and_execute_setcommit_cmd (argc, argv);
}
else if(matchCmd(command, 4, "getnames"))
{
validate_and_execute_getnames_cmd (argc, argv);
Expand Down Expand Up @@ -2623,7 +2675,7 @@ void completion(const char *buf, linenoiseCompletions *lc) {
if(num == 1)
{
runSteps = __LINE__;
completion = find_completion(tokens[0], 14, "get", "set", "add", "del", "getr", "getn", "disca", "discc", "disce",
completion = find_completion(tokens[0], 14, "get", "set", "setc", "add", "del", "getr", "getn", "disca", "discc", "disce",
"discw", "sub", "subint", "rawdatasub", "rawdataunsub", "unsub", "unsubint", "asub", "method_no", "method_na", "method_va", "reg", "unreg", "pub", "rawdatapub", "log", "quit", "opend", "closed", "help");
}
else if(num == 2)
Expand Down Expand Up @@ -2706,6 +2758,10 @@ char *hints(const char *buf, int *color, int *bold) {
{
hint = " parameter type value";
}
else if(strcmp(tokens[0], "setc") == 0)
{
hint = " component [sessionid]";
}
else if(strcmp(tokens[0], "add") == 0)
{
hint = " table";
Expand Down

0 comments on commit fc55df9

Please sign in to comment.