Skip to content

Commit

Permalink
address code smel
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Apr 16, 2024
1 parent 8e1afef commit f671c8d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once
#include <iostream>
#include <tmx/TmxException.hpp>

namespace RSUHealthMonitor
{
class RSUConfigurationException : public std::runtime_error
class RSUConfigurationException : public tmx::TmxException
{
public:
explicit RSUConfigurationException(const char *msg) : runtime_error(msg){};
using TmxException::TmxException;
};
}
14 changes: 7 additions & 7 deletions src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RSUHealthMonitor
{
Json::Value RSUConfigurationList::parseJson(std::string &rsuConfigsStr) const
Json::Value RSUConfigurationList::parseJson(const std::string &rsuConfigsStr) const
{
JSONCPP_STRING err;
Json::Value root;
Expand All @@ -19,12 +19,12 @@ namespace RSUHealthMonitor
return root;
}

void RSUConfigurationList::parseRSUs(std::string &rsuConfigsStr)
void RSUConfigurationList::parseRSUs(const std::string &rsuConfigsStr)
{
auto json = parseJson(rsuConfigsStr);
std::vector<RSUConfiguration> tempConfigs;
RSUConfiguration config;
auto rsuArray = json["RSUS"];
auto rsuArray = json[RSUSKey];
if (!rsuArray.isArray())
{
throw RSUConfigurationException("RSUS is not an array.");
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace RSUHealthMonitor
configs.assign(tempConfigs.begin(), tempConfigs.end());
}

RSUMibVersion RSUConfigurationList::strToMibVersion(std::string &mibVersionStr) const
RSUMibVersion RSUConfigurationList::strToMibVersion(const std::string &mibVersionStr) const
{
boost::trim_left(mibVersionStr);
boost::trim_right(mibVersionStr);
Expand All @@ -101,16 +101,16 @@ namespace RSUHealthMonitor
}
}

std::vector<RSUConfiguration> RSUConfigurationList::getConfigs()
std::vector<RSUConfiguration> RSUConfigurationList::getConfigs() const
{
return configs;
}

std::ostream &operator<<(std::ostream &os, const RSUMibVersion &mib)
{
const std::vector<std::string> nameMibs = {"UNKOWN MIB",
"RSU 4.1",
"NTCIP 1218"};
"RSU4.1",
"NTCIP1218"};
return os << nameMibs[static_cast<int>(mib)];
}

Expand Down
9 changes: 5 additions & 4 deletions src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace RSUHealthMonitor
{
static constexpr const char *RSUSKey = "RSUS";
static constexpr const char *RSUIpKey = "RSUIp";
static constexpr const char *SNMPPortKey = "SNMPPort";
static constexpr const char *UserKey = "User";
Expand Down Expand Up @@ -44,8 +45,8 @@ namespace RSUHealthMonitor
* @param rsuConfigsStr A JSON string includes all RSUs related configrations.
* @return JSON::Value A JSON object that includes RSUS information.
*/
Json::Value parseJson(std::string &rsuConfigsStr) const;
RSUMibVersion strToMibVersion(std::string &mibVersionStr) const;
Json::Value parseJson(const std::string &rsuConfigsStr) const;
RSUMibVersion strToMibVersion(const std::string &mibVersionStr) const;

public:
RSUConfigurationList() = default;
Expand All @@ -54,11 +55,11 @@ namespace RSUHealthMonitor
* @brief Parse RSUs configrations in JSON string representation, and update the memeber of list of RSUConfiguration struct.
* @param rsuConfigsStr A JSON string includes all RSUs related configrations.
*/
void parseRSUs(std::string &rsuConfigsStr);
void parseRSUs(const std::string &rsuConfigsStr);
/**
* @brief Get a list of RSUConfiguration struct.
*/
std::vector<RSUConfiguration> getConfigs();
std::vector<RSUConfiguration> getConfigs() const;
};

} // namespace RSUHealthMonitor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace RSUHealthMonitor
ASSERT_EQ(2, rsuConfigList->getConfigs().size());
std::stringstream ss;
ss << rsuConfigList->getConfigs()[0];
std::string expected = "RSUIp: 192.168.XX.XX, SNMPPort: 161, User: authOnlyUser, AuthPassPhrase: dummy, SecurityLevel: authPriv, RSUMIBVersion: RSU 4.1";
std::string expected = "RSUIp: 192.168.XX.XX, SNMPPort: 161, User: authOnlyUser, AuthPassPhrase: dummy, SecurityLevel: authPriv, RSUMIBVersion: RSU4.1";
ASSERT_EQ(expected, ss.str());
}
TEST_F(test_RSUConfigurationList, parseAndGetConfigs_MalformatJSON)
Expand Down

0 comments on commit f671c8d

Please sign in to comment.