Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Nov 22, 2023
1 parent 2d6364a commit 8b01468
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -41,7 +43,7 @@ namespace TelematicBridge
sleep(1);
}

if (_isRegistered)
if (isRegistered)
{
// Provide below services when the unit is registered
availableTopicsReplier();
Expand All @@ -50,18 +52,17 @@ namespace TelematicBridge
}
}

void TelematicUnit::updateRegisterStatus(const string &registerReply)
bool TelematicUnit::updateRegisterStatus(const string &registerReply)
{
auto root = parseJson(registerReply);
if (root.isMember(LOCATION) && root.isMember(TESTING_TYPE) && root.isMember(EVENT_NAME))
{
_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()
Expand Down
4 changes: 2 additions & 2 deletions src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace TelematicBridge
mutex _unitMutex;
mutex _availableTopicsMutex;
mutex _excludedTopicsMutex;
atomic<bool> _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<string> _availableTopics; // Global variable to store available topics
string _excludedTopics; // Global variable to store topics that are excluded by the users
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b01468

Please sign in to comment.