Skip to content

Commit

Permalink
RDKB-56078:Move session manager to use rbus APIs (#211)
Browse files Browse the repository at this point in the history
* RDKB-56078:Move session manager to use rbus APIs
Signed-off-by: Netaji Panigrahi [email protected]

* Updated session manager gtest code

* Updated unit test code
  • Loading branch information
NetajiPanigrahi authored Jul 17, 2024
1 parent 1f2ff53 commit 9a0c79f
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 430 deletions.
92 changes: 55 additions & 37 deletions src/rbus/rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -5869,70 +5869,83 @@ rbusError_t rbus_createSession(rbusHandle_t handle, uint32_t *pSessionId)
{
(void)handle;
rbusError_t rc = RBUS_ERROR_SUCCESS;
rbusCoreError_t err = RBUSCORE_SUCCESS;
rbusMessage response = NULL;
rbusObject_t outParams = NULL;
if (pSessionId && handle)
{
*pSessionId = 0;
if((err = rbus_invokeRemoteMethod(RBUS_SMGR_DESTINATION_NAME, RBUS_SMGR_METHOD_REQUEST_SESSION_ID, NULL, rbusConfig_ReadSetTimeout(), &response)) == RBUSCORE_SUCCESS)
if ((rc = rbusMethod_Invoke(handle, RBUS_SMGR_METHOD_REQUEST_SESSION_ID, NULL, &outParams)) == RBUS_ERROR_SUCCESS)
{
rbusMessage_GetInt32(response, /*MESSAGE_FIELD_RESULT,*/ (int*) &err);
if(RBUSCORE_SUCCESS != err)
rbusProperty_t prop = NULL;
prop = rbusObject_GetProperties(outParams);
int result = rbusValue_GetInt32(rbusProperty_GetValue(prop));
if (RBUS_ERROR_SUCCESS != result)
{
RBUSLOG_ERROR("Session manager reports internal error %d for the object %s", err, RBUS_SMGR_DESTINATION_NAME);
RBUSLOG_ERROR("Session manager reports internal error %d from %s for the object %s", rc, handle->componentName, RBUS_SMGR_DESTINATION_NAME);
rc = RBUS_ERROR_SESSION_ALREADY_EXIST;
}
else
{
rbusMessage_GetInt32(response, /*MESSAGE_FIELD_PAYLOAD,*/ (int*) pSessionId);
RBUSLOG_INFO("Received new session id %u", *pSessionId);
prop = rbusProperty_GetNext(prop);
/* Get current session id*/
if (prop)
{
*pSessionId = rbusValue_GetInt32(rbusProperty_GetValue(prop));
RBUSLOG_INFO("Received new session id %u", *pSessionId);
}
else
RBUSLOG_ERROR("Malformed response from session manager.\n");
}
}
else
{
RBUSLOG_ERROR("Failed to communicated with session manager.");
rc = rbusCoreError_to_rbusError(err);
}
rbusMessage_Release(response);
}
else
{
RBUSLOG_WARN("Invalid Input passed..");
rc = RBUS_ERROR_INVALID_INPUT;
}
return rc;
}
return rc;
}

rbusError_t rbus_getCurrentSession(rbusHandle_t handle, uint32_t *pSessionId)
{
(void)handle;
rbusError_t rc = RBUS_ERROR_SUCCESS;
rbusCoreError_t err = RBUSCORE_SUCCESS;
rbusMessage response = NULL;
rbusObject_t outParams = NULL;

if (pSessionId && handle)
{
*pSessionId = 0;
if((err = rbus_invokeRemoteMethod(RBUS_SMGR_DESTINATION_NAME, RBUS_SMGR_METHOD_GET_CURRENT_SESSION_ID, NULL, rbusConfig_ReadGetTimeout(), &response)) == RBUSCORE_SUCCESS)
if ((rc = rbusMethod_Invoke(handle, RBUS_SMGR_METHOD_GET_CURRENT_SESSION_ID, NULL, &outParams)) == RBUS_ERROR_SUCCESS)
{
rbusMessage_GetInt32(response, /*MESSAGE_FIELD_RESULT,*/ (int*) &err);
if(RBUSCORE_SUCCESS != err)
rbusProperty_t prop = NULL;
prop = rbusObject_GetProperties(outParams);
int result = rbusValue_GetInt32(rbusProperty_GetValue(prop));
if (RBUS_ERROR_SUCCESS != result)
{
RBUSLOG_ERROR("Session manager reports internal error %d from %s for the object %s", err, handle->componentName, RBUS_SMGR_DESTINATION_NAME);
RBUSLOG_ERROR("Session manager reports internal error %d from %s for the object %s", rc, handle->componentName, RBUS_SMGR_DESTINATION_NAME);
rc = RBUS_ERROR_SESSION_ALREADY_EXIST;
}
else
{
rbusMessage_GetInt32(response, /*MESSAGE_FIELD_PAYLOAD,*/ (int*) pSessionId);
RBUSLOG_INFO("Received new session id %u", *pSessionId);
prop = rbusProperty_GetNext(prop);
/* Get current session id*/
if (prop)
{
*pSessionId = rbusValue_GetInt32(rbusProperty_GetValue(prop));
RBUSLOG_INFO("Received new session id %u", *pSessionId);
}
else
RBUSLOG_ERROR("Malformed response from session manager.\n");
}
}
else
{
RBUSLOG_ERROR("Failed to communicated with session manager.");
rc = rbusCoreError_to_rbusError(err);
return rc;
}
rbusMessage_Release(response);
}
else
{
Expand All @@ -5946,44 +5959,49 @@ rbusError_t rbus_closeSession(rbusHandle_t handle, uint32_t sessionId)
{
(void)handle;
rbusError_t rc = RBUS_ERROR_SUCCESS;
rbusCoreError_t err = RBUSCORE_SUCCESS;

if (handle)
{
rbusMessage inputSession;
rbusMessage response = NULL;

if (sessionId == 0)
{
RBUSLOG_WARN("Passing default session ID which is 0");
return RBUS_ERROR_SUCCESS;
}
rbusMessage_Init(&inputSession);
rbusMessage_SetInt32(inputSession, /*MESSAGE_FIELD_PAYLOAD,*/ sessionId);
if((err = rbus_invokeRemoteMethod(RBUS_SMGR_DESTINATION_NAME, RBUS_SMGR_METHOD_END_SESSION, inputSession, rbusConfig_ReadSetTimeout(), &response)) == RBUSCORE_SUCCESS)

rbusObject_t inParams = NULL, outParams = NULL;
rbusObject_Init(&inParams, NULL);
rbusValue_t inputSession;
rbusValue_Init(&inputSession);
rbusValue_SetInt32(inputSession, sessionId);
rbusObject_SetValue(inParams, "session", inputSession);

if ((rc = rbusMethod_Invoke(handle, RBUS_SMGR_METHOD_END_SESSION, inParams, &outParams)) == RBUS_ERROR_SUCCESS)
{
rbusMessage_GetInt32(response, /*MESSAGE_FIELD_RESULT,*/ (int*) &err);
if(RBUSCORE_SUCCESS != err)
VERIFY_NULL(outParams);
rbusProperty_t prop = NULL;
prop = rbusObject_GetProperties(outParams);
int result = rbusValue_GetInt32(rbusProperty_GetValue(prop));

if (RBUS_ERROR_SUCCESS == result)
{
RBUSLOG_ERROR("Session manager reports internal error %d from %s for the object %s", err, handle->componentName, RBUS_SMGR_DESTINATION_NAME);
rc = RBUS_ERROR_SESSION_ALREADY_EXIST;
RBUSLOG_INFO("Successfully ended session %u.", sessionId);
}
else
RBUSLOG_INFO("Successfully ended session %u.", sessionId);
{
RBUSLOG_ERROR("Session manager reports internal error %d from %s for the object %s", result, handle->componentName, RBUS_SMGR_DESTINATION_NAME);
rc = RBUS_ERROR_SESSION_ALREADY_EXIST;
}
}
else
{
RBUSLOG_ERROR("Failed to communicated with session manager.");
rc = rbusCoreError_to_rbusError(err);
}
rbusMessage_Release(response);
}
else
{
RBUSLOG_WARN("Invalid Input passed..");
rc = RBUS_ERROR_INVALID_INPUT;
}

return rc;
}

Expand Down
15 changes: 8 additions & 7 deletions src/session_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
# limitations under the License.
##########################################################################
include_directories(.
../core
../rtmessage)
../../include
../core
../rtmessage)

add_executable(rbus_session_mgr session_manager.c)
add_dependencies(rbus_session_mgr rbuscore)
target_link_libraries(rbus_session_mgr rbuscore)
add_dependencies(rbus_session_mgr rbus rbuscore)
target_link_libraries(rbus_session_mgr rbus rbuscore)

if (BUILD_SESSIONMGR_SAMPLE_APPS)
add_executable(rbus_session_mgr_client test/sample_client.c)
add_dependencies(rbus_session_mgr_client rbuscore)
target_link_libraries(rbus_session_mgr_client rbuscore)
add_dependencies(rbus_session_mgr_client rbus rbuscore)
target_link_libraries(rbus_session_mgr_client rbus rbuscore)
endif (BUILD_SESSIONMGR_SAMPLE_APPS)

install (TARGETS rbus_session_mgr
install (TARGETS rbus_session_mgr
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

install(FILES rbus_session_mgr.h DESTINATION "include/rbus")
Loading

0 comments on commit 9a0c79f

Please sign in to comment.