Skip to content

Commit

Permalink
RBUS-modify log messages & log level (#248)
Browse files Browse the repository at this point in the history
* RBUS-modify log messages & log level

* Update log messages

* Updated method invoke error log message
  • Loading branch information
NetajiPanigrahi authored Feb 11, 2025
1 parent 39ad76c commit 51b8773
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 41 deletions.
6 changes: 5 additions & 1 deletion include/rbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ typedef enum _rbusError
RBUS_ERROR_NOSUBSCRIBERS, /**< No subscribers present */
RBUS_ERROR_SUBSCRIPTION_ALREADY_EXIST, /**< The subscription already exists*/
RBUS_ERROR_INVALID_NAMESPACE, /**< Invalid namespace as per standard */
RBUS_ERROR_DIRECT_CON_NOT_EXIST /**< Direct connection not exist */
RBUS_ERROR_DIRECT_CON_NOT_EXIST, /**< Direct connection not exist */
RBUS_ERROR_NOT_WRITABLE, /**< Set to the requested data element was not permitted by the provider component.*/
RBUS_ERROR_NOT_READABLE, /**< Get to the requested data element was not permitted by the provider component.*/
RBUS_ERROR_INVALID_PARAMETER_TYPE, /**< Invalid parameter type.*/
RBUS_ERROR_INVALID_PARAMETER_VALUE /**< Invalid parameter value.*/
} rbusError_t;


Expand Down
119 changes: 82 additions & 37 deletions src/rbus/rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ static rbusError_t CCSPError_to_rbusError(rtError e)
err = RBUS_ERROR_OUT_OF_RESOURCES;
break;
case RBUS_LEGACY_ERR_INVALID_PARAMETER_NAME:
err = RBUS_ERROR_INVALID_INPUT;
err = RBUS_ERROR_INVALID_NAMESPACE;
break;
case RBUS_LEGACY_ERR_INVALID_PARAMETER_TYPE:
err = RBUS_ERROR_INVALID_INPUT;
err = RBUS_ERROR_INVALID_PARAMETER_TYPE;
break;
case RBUS_LEGACY_ERR_INVALID_PARAMETER_VALUE:
err = RBUS_ERROR_INVALID_INPUT;
err = RBUS_ERROR_INVALID_PARAMETER_VALUE;
break;
case RBUS_LEGACY_ERR_NOT_WRITABLE:
err = RBUS_ERROR_INVALID_OPERATION;
err = RBUS_ERROR_NOT_WRITABLE;
break;
default:
err = RBUS_ERROR_BUS_ERROR;
Expand All @@ -240,6 +240,51 @@ static rbusError_t CCSPError_to_rbusError(rtError e)
return err;
}

const char* rbusCoreErrorToString(rbusCoreError_t error) {
switch (error) {
case RBUSCORE_SUCCESS:
return "Success";
case RBUSCORE_ERROR_GENERAL:
return "General error";
case RBUSCORE_ERROR_INVALID_PARAM:
return "Invalid parameter error";
case RBUSCORE_ERROR_INSUFFICIENT_MEMORY:
return "Insufficient memory error";
case RBUSCORE_ERROR_INVALID_STATE:
return "Invalid state error";
case RBUSCORE_ERROR_REMOTE_END_DECLINED_TO_RESPOND:
return "Remote end declined to respond";
case RBUSCORE_ERROR_REMOTE_END_FAILED_TO_RESPOND:
return "Remote end failed to respond";
case RBUSCORE_ERROR_REMOTE_TIMED_OUT:
return "Remote timed out error";
case RBUSCORE_ERROR_MALFORMED_RESPONSE:
return "Malformed response";
case RBUSCORE_ERROR_UNSUPPORTED_METHOD:
return "Unsupported method error";
case RBUSCORE_ERROR_UNSUPPORTED_EVENT:
return "Unsupported event error";
case RBUSCORE_ERROR_OUT_OF_RESOURCES:
return "Out of resources error";
case RBUSCORE_ERROR_DESTINATION_UNREACHABLE:
return "Destination unreachable error";
case RBUSCORE_SUCCESS_ASYNC:
return "Success (async)";
case RBUSCORE_ERROR_SUBSCRIBE_NOT_HANDLED:
return "Subscribe not handled error";
case RBUSCORE_ERROR_EVENT_NOT_HANDLED:
return "Event not handled error";
case RBUSCORE_ERROR_DUPLICATE_ENTRY:
return "Duplicate entry error";
case RBUSCORE_ERROR_ENTRY_NOT_FOUND:
return "Entry not found error";
case RBUSCORE_ERROR_UNSUPPORTED_ENTRY:
return "Unsupported entry error";
default:
return "Unknown error";
}
}

void rbusEventSubscription_free(void* p)
{
rbusEventSubscription_t* sub = (rbusEventSubscription_t*)p;
Expand Down Expand Up @@ -1058,20 +1103,20 @@ int subscribeHandlerImpl(

if(rawData && autoPublish)
{
RBUSLOG_DEBUG("%s raw data subscription doesn't allow autoPublish=%d", __FUNCTION__, err);
RBUSLOG_ERROR("%s raw data subscription doesn't allow autoPublish=%d", __FUNCTION__, err);
return RBUS_ERROR_INVALID_INPUT;
}

if(err != RBUS_ERROR_SUCCESS)
{
RBUSLOG_DEBUG("provider subHandler return err=%d", err);
RBUSLOG_ERROR("provider subHandler return err=%d", err);
return err;
}
}
else if (interval)
{
autoPublish = true;
RBUSLOG_DEBUG("rbus autoPublish is enabled for interval based subscription");
RBUSLOG_INFO("rbus autoPublish is enabled for interval based subscription");
}

if(added)
Expand Down Expand Up @@ -1104,7 +1149,7 @@ int subscribeHandlerImpl(

if(!subscription)
{
RBUSLOG_INFO("unsubscribing from event which isn't currectly subscribed to event=%s listener=%s", eventName, listener);
RBUSLOG_ERROR("unsubscribing from event which isn't currectly subscribed to event=%s listener=%s", eventName, listener);
return RBUS_ERROR_INVALID_INPUT; /*unsubscribing from event which isn't currectly subscribed to*/
}
}
Expand Down Expand Up @@ -1379,7 +1424,7 @@ static int _master_event_callback_handler(char const* sender, char const* eventN

if(!handleInfo)
{
RBUSLOG_INFO("Received master event callback with invalid componentId: sender=%s eventName=%s componentId=%d", sender, eventName, componentId);
RBUSLOG_ERROR("Received master event callback with invalid componentId: sender=%s eventName=%s componentId=%d", sender, eventName, componentId);
return RBUSCORE_ERROR_EVENT_NOT_HANDLED;
}

Expand Down Expand Up @@ -1502,7 +1547,7 @@ static void _set_callback_handler (rbusHandle_t handle, rbusMessage request, rbu
else
{
RBUSLOG_WARN("Set Failed for %s; No Handler found", paramName);
rc = RBUS_ERROR_INVALID_OPERATION;
rc = RBUS_ERROR_NOT_WRITABLE;
pFailedElement = paramName;
break;
}
Expand Down Expand Up @@ -2236,7 +2281,7 @@ static void _table_add_row_callback_handler (rbusHandle_t handle, rbusMessage re
{
if(tableRegElem->cbTable.tableAddRowHandler)
{
RBUSLOG_INFO("calling tableAddRowHandler table [%s] alias [%s]", tableName, aliasName);
RBUSLOG_DEBUG("calling tableAddRowHandler table [%s] alias [%s]", tableName, aliasName);

ELM_PRIVATE_LOCK(tableRegElem);
result = tableRegElem->cbTable.tableAddRowHandler(handle, tableName, aliasName, &instNum);
Expand Down Expand Up @@ -2294,7 +2339,7 @@ static void _table_remove_row_callback_handler (rbusHandle_t handle, rbusMessage
{
if(tableRegElem->cbTable.tableRemoveRowHandler)
{
RBUSLOG_INFO("calling tableRemoveRowHandler row [%s]", rowName);
RBUSLOG_DEBUG("calling tableRemoveRowHandler row [%s]", rowName);

ELM_PRIVATE_LOCK(tableRegElem);
result = tableRegElem->cbTable.tableRemoveRowHandler(handle, rowName);
Expand All @@ -2311,7 +2356,7 @@ static void _table_remove_row_callback_handler (rbusHandle_t handle, rbusMessage
}
else
{
RBUSLOG_INFO("tableRemoveRowHandler not registered row [%s]", rowName);
RBUSLOG_ERROR("tableRemoveRowHandler not registered row [%s]", rowName);
result = RBUS_ERROR_INVALID_OPERATION;
}
}
Expand Down Expand Up @@ -2368,7 +2413,7 @@ static int _method_callback_handler(rbusHandle_t handle, rbusMessage request, rb
{
if(methRegElem->cbTable.methodHandler)
{
RBUSLOG_INFO("calling methodHandler method [%s]", methodName);
RBUSLOG_DEBUG("calling methodHandler method [%s]", methodName);

rbusMethodAsyncHandle_t asyncHandle = rt_malloc(sizeof(struct _rbusMethodAsyncHandle));
asyncHandle->hdr = *hdr;
Expand All @@ -2380,7 +2425,7 @@ static int _method_callback_handler(rbusHandle_t handle, rbusMessage request, rb
if (result == RBUS_ERROR_ASYNC_RESPONSE)
{
/*outParams will be sent async*/
RBUSLOG_INFO("async method in progress [%s]", methodName);
RBUSLOG_DEBUG("async method in progress [%s]", methodName);
}
else
{
Expand All @@ -2401,7 +2446,7 @@ static int _method_callback_handler(rbusHandle_t handle, rbusMessage request, rb
}
else
{
RBUSLOG_INFO("methodHandler not registered method [%s]", methodName);
RBUSLOG_ERROR("methodHandler not registered method [%s]", methodName);
result = RBUS_ERROR_INVALID_OPERATION;
rbusValue_SetInt32(value1, RBUS_ERROR_INVALID_OPERATION);
rbusValue_SetString(value2, "RBUS_ERROR_INVALID_OPERATION");
Expand Down Expand Up @@ -3062,7 +3107,7 @@ rbusError_t rbus_close(rbusHandle_t handle)
int i;
HANDLE_EVENTSUBS_MUTEX_LOCK(handle);
int count = (int)rtVector_Size(handleInfo->eventSubs);
RBUSLOG_INFO("Cleaning up all (%d) subscriptions", count);
RBUSLOG_DEBUG("Cleaning up all (%d) subscriptions", count);
for(i = 0; i < count; ++i)
{
rbusEventSubscriptionInternal_t* subInternal = NULL;
Expand Down Expand Up @@ -3387,7 +3432,7 @@ rbusError_t rbus_get(rbusHandle_t handle, char const* name, rbusValue_t* value)

if(err != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("get by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, name);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, name, rbusCoreErrorToString(err));
errorcode = rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -3548,7 +3593,7 @@ rbusError_t rbus_getExt(rbusHandle_t handle, int paramCount, char const** pParam

if(err != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("get by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, destinations[i]);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, destinations[i], rbusCoreErrorToString(err));
errorcode = rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -3709,7 +3754,7 @@ rbusError_t rbus_getExt(rbusHandle_t handle, int paramCount, char const** pParam

if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_GETPARAMETERVALUES, request, rbusHandle_FetchGetTimeout(handle), &response)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("get by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, firstParamName);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, firstParamName, rbusCoreErrorToString(err));
errorcode = rbusCoreError_to_rbusError(err);
break;
}
Expand Down Expand Up @@ -3863,7 +3908,7 @@ rbusError_t rbus_set(rbusHandle_t handle, char const* name,rbusValue_t value, rb

if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_SETPARAMETERVALUES, setRequest, rbusHandle_FetchSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("set by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, name);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, name, rbusCoreErrorToString(err));
errorcode = rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -3931,7 +3976,7 @@ rbusError_t rbus_setCommit(rbusHandle_t handle, char const* name, rbusSetOptions
myConn = handleInfo->m_connection;
if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_COMMIT, setRequest, rbusHandle_FetchSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("set commit by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, name);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, name, rbusCoreErrorToString(err));
errorcode = rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -4102,7 +4147,7 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop

if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_SETPARAMETERVALUES, setRequest, rbusHandle_FetchSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("set by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, firstParamName);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, firstParamName, rbusCoreErrorToString(err));
errorcode = rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -4270,7 +4315,7 @@ rbusError_t rbusTable_addRow(
rbusHandle_FetchSetTimeout(handle),
&response)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("Add row by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, tableName);
RBUSLOG_ERROR("%s for %s failed with RBUS Daemon error: %s", __FUNCTION__, tableName, rbusCoreErrorToString(err));
return rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -4336,7 +4381,7 @@ rbusError_t rbusTable_removeRow(
rbusHandle_FetchSetTimeout(handle),
&response)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("Delete row by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, rowName);
RBUSLOG_ERROR(" %s for %s failed with RBUS Daemon error: %s", __FUNCTION__, rowName, rbusCoreErrorToString(err));
return rbusCoreError_to_rbusError(err);
}
else
Expand Down Expand Up @@ -4724,7 +4769,7 @@ static rbusError_t _rbus_event_unsubscribe(
char rawDataTopic[RBUS_MAX_NAME_LENGTH] = {0};
rbusEventSubscription_t* subscription = (rbusEventSubscription_t*)subInternal->sub;

RBUSLOG_INFO("unsubscribe for %s", subscription->eventName);
RBUSLOG_DEBUG("unsubscribe for %s", subscription->eventName);

rbusCoreError_t coreerr;
rbusMessage payload;
Expand Down Expand Up @@ -4767,7 +4812,7 @@ static rbusError_t _rbus_event_unsubscribe(
if(coreerr == RBUSCORE_ERROR_ENTRY_NOT_FOUND)
{
subInternal->dirty = true;
RBUSLOG_DEBUG ("n%s unsubscription failed because no provider could be found"
RBUSLOG_DEBUG ("%s unsubscription failed because no provider could be found"
"and subscriber marked as dirty", subscription->eventName);
errorcode = RBUS_ERROR_DESTINATION_NOT_FOUND;
}
Expand Down Expand Up @@ -5196,12 +5241,12 @@ rbusError_t rbusEvent_Unsubscribe(
if(coreerr == RBUSCORE_ERROR_ENTRY_NOT_FOUND)
{
subInternal->dirty = true;
RBUSLOG_INFO ("%s unsubscription failed because no provider could be found"
RBUSLOG_ERROR ("%s unsubscription failed because no provider could be found"
"and subscriber marked as dirty", subInternal->sub->eventName);
}
else
{
RBUSLOG_INFO("%s failed with core err=%d", eventName, coreerr);
RBUSLOG_ERROR("%s failed with core err=%d", eventName, coreerr);
rtVector_RemoveItem(handleInfo->eventSubs, subInternal, rbusEventSubscriptionInternal_free);
HANDLE_EVENTSUBS_MUTEX_UNLOCK(handle);
return RBUS_ERROR_BUS_ERROR;
Expand Down Expand Up @@ -5412,7 +5457,7 @@ rbusError_t rbusEvent_SubscribeExAsync(

for(i = 0; i < numSubscriptions; ++i)
{
RBUSLOG_INFO("Asynchronous subscription for %s", subscription[i].eventName);
RBUSLOG_DEBUG("Asynchronous subscription for %s", subscription[i].eventName);

errorcode = rbusEvent_SubscribeWithRetries(
handle, subscription[i].eventName, subscription[i].handler, subscription[i].userData,
Expand Down Expand Up @@ -5463,7 +5508,7 @@ rbusError_t rbusEvent_UnsubscribeExRawData(
{
rbusEventSubscriptionInternal_t* subInternal = NULL;

RBUSLOG_INFO("Unsubscribe RawData for %s", subscription[i].eventName);
RBUSLOG_DEBUG("Unsubscribe RawData for %s", subscription[i].eventName);

/*the use of rtVector is inefficient here. I have to loop through the vector to find the sub by name,
then call RemoveItem, which loops through again to find the item by address to destroy */
Expand Down Expand Up @@ -5505,7 +5550,7 @@ rbusError_t _rbus_AsyncSubscribe_remove_subscription(
sub_removed = rbusAsyncSubscribe_RemoveSubscription(&sub);
if(sub_removed)
{
RBUSLOG_INFO("%s removed pending async subscription", sub.eventName);
RBUSLOG_DEBUG("%s removed pending async subscription", sub.eventName);
}
else
{
Expand Down Expand Up @@ -5598,13 +5643,13 @@ bool rbusEvent_IsSubscriptionExist(
HANDLE_EVENTSUBS_MUTEX_LOCK(handle);
if (subscription)
{
RBUSLOG_INFO("Event name: %s", subscription->eventName);
RBUSLOG_DEBUG("Event name: %s", subscription->eventName);
subInternal = rbusEventSubscription_find(handleInfo->eventSubs, subscription[0].eventName,
subscription[0].filter, subscription[0].interval, subscription[0].duration, false);
}
else
{
RBUSLOG_INFO("Event name: %s", eventName);
RBUSLOG_DEBUG("Event name: %s", eventName);
subInternal = rbusEventSubscription_find(handleInfo->eventSubs, eventName, NULL, 0, 0, false);
}

Expand Down Expand Up @@ -5791,7 +5836,7 @@ rbusError_t rbusEvent_Publish(
{
if(errOut == RBUSCORE_SUCCESS)
errOut = err;
RBUSLOG_INFO("rbusEvent_Publish failed: rbus_publishSubscriberEvent return error %d", err);
RBUSLOG_ERROR("rbusEvent_Publish failed: rbus_publishSubscriberEvent return error %d", err);
}
}
rtListItem_GetNext(listItem, &listItem);
Expand Down Expand Up @@ -5848,7 +5893,7 @@ rbusError_t rbusMethod_InvokeInternal(
timeout,
&response)) != RBUSCORE_SUCCESS)
{
RBUSLOG_ERROR("%s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, methodName);
RBUSLOG_ERROR("rbusMethod Invoke for %s failed with RBUS Daemon error:%s", methodName, rbusCoreErrorToString(err));
/* Updating the outParmas as RBUS core is returning failure */
rbusObject_Init(outParams, NULL);
rbusValue_Init(&value1);
Expand All @@ -5874,7 +5919,7 @@ rbusError_t rbusMethod_InvokeInternal(

rbusMessage_Release(response);

RBUSLOG_INFO("Method_InvokeInternal success response with returnCode:%d", returnCode);
RBUSLOG_DEBUG("Method_InvokeInternal success response with returnCode:%d", returnCode);

return returnCode;
}
Expand Down
4 changes: 2 additions & 2 deletions unittests/rbusConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ int rbusConsumer(rbusGtest_t test, pid_t pid, int runtime)
{
const char *param = "Device.rbusProvider.PartialPath.1.Param2";
isElementPresent(handle, param);
rc = exec_rbus_set_test(handle, RBUS_ERROR_INVALID_OPERATION, param, "Gtest set value");
rc = exec_rbus_set_test(handle, RBUS_ERROR_NOT_WRITABLE, param, "Gtest set value");
}
break;
case RBUS_GTEST_SET3:
Expand Down Expand Up @@ -542,7 +542,7 @@ int rbusConsumer(rbusGtest_t test, pid_t pid, int runtime)
const char *param2 = "Device.rbusProvider.PartialPath.1.Param2";
isElementPresent(handle, param1);
isElementPresent(handle, param2);
rc = exec_rbus_multi_test(handle, RBUS_ERROR_INVALID_OPERATION, 2, param1, param2);
rc = exec_rbus_multi_test(handle, RBUS_ERROR_NOT_WRITABLE, 2, param1, param2);
}
break;
case RBUS_GTEST_GET1:
Expand Down
Loading

0 comments on commit 51b8773

Please sign in to comment.