From 8b014689e3a9408c84c9f7f4ed318faeae14e1fe Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 22 Nov 2023 17:57:10 +0000 Subject: [PATCH] code coverage --- .../TelematicBridgePlugin/src/TelematicUnit.cpp | 17 +++++++++-------- .../TelematicBridgePlugin/src/TelematicUnit.h | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp index 355fe8fe3..fc73a24b0 100644 --- a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp +++ b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp @@ -19,9 +19,9 @@ namespace TelematicBridge void TelematicUnit::registerUnitRequestor() { // Reset registration status - _isRegistered = false; + bool isRegistered = false; - while (!_isRegistered) + while (!isRegistered) { PLOG(logDEBUG2) << "Inside register unit requestor"; natsMsg *reply = nullptr; @@ -31,7 +31,9 @@ namespace TelematicBridge { auto replyStr = natsMsg_GetData(reply); PLOG(logINFO) << "Received registered reply: " << replyStr; - updateRegisterStatus(replyStr); + + // Unit is registered when server responds with event information (location, testing_type, event_name) + isRegistered = updateRegisterStatus(replyStr); natsMsg_Destroy(reply); } else @@ -41,7 +43,7 @@ namespace TelematicBridge sleep(1); } - if (_isRegistered) + if (isRegistered) { // Provide below services when the unit is registered availableTopicsReplier(); @@ -50,7 +52,7 @@ namespace TelematicBridge } } - void TelematicUnit::updateRegisterStatus(const string ®isterReply) + bool TelematicUnit::updateRegisterStatus(const string ®isterReply) { auto root = parseJson(registerReply); if (root.isMember(LOCATION) && root.isMember(TESTING_TYPE) && root.isMember(EVENT_NAME)) @@ -58,10 +60,9 @@ namespace TelematicBridge _eventLocation = root[LOCATION].asString(); _testingType = root[TESTING_TYPE].asString(); _eventName = root[EVENT_NAME].asString(); - - // Unit is registered when server responds with event information (location, testing_type, event_name) - _isRegistered = true; + return true; } + return false; } void TelematicUnit::availableTopicsReplier() diff --git a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h index 031439f44..fc15939bd 100644 --- a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h +++ b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h @@ -29,7 +29,6 @@ namespace TelematicBridge mutex _unitMutex; mutex _availableTopicsMutex; mutex _excludedTopicsMutex; - atomic _isRegistered{false}; // Global variable to indicate whether the unit is registered with the NATS server unit_st _unit; // Global variable to store the unit information vector _availableTopics; // Global variable to store available topics string _excludedTopics; // Global variable to store topics that are excluded by the users @@ -123,8 +122,9 @@ namespace TelematicBridge /** * @brief Update telematic unit registration status with the registration reply from NATS server * @param string Register reply in Json format + * @return True when status are updated, otherwise false. */ - void updateRegisterStatus(const string& registerReply); + bool updateRegisterStatus(const string& registerReply); /** * @brief construct Json data string that will be streamed into the cloud by a publisher