Skip to content

Commit

Permalink
update the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Oct 6, 2024
1 parent 96d5708 commit 3a12bb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace WPEFramework
_notification(this)
{
// Don't do any work in the constructor - all set up should be done in Initialize
m_wifiStateCache = Exchange::INetworkManager::WIFI_STATE_DISCONNECTED;
m_primaryInterfaceCache = "wlan0";
}

NetworkManager::~NetworkManager()
Expand Down
12 changes: 6 additions & 6 deletions NetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,19 @@ namespace WPEFramework
}
void PublishToThunderAboutInternet();
/* Class to store and manage cached data */
template<typename DataType>
template<typename CacheValue>
class Cache {
public:
Cache() : is_set(false) {}

Cache& operator=(const DataType& value) {
Cache& operator=(const CacheValue& value) {
std::lock_guard<std::mutex> lock(mutex);
this->value = value;
is_set.store(true);
return *this;
}

Cache& operator=(DataType&& value) {
Cache& operator=(CacheValue&& value) {
std::lock_guard<std::mutex> lock(mutex);
this->value = std::move(value);
is_set.store(true);
Expand All @@ -303,18 +303,18 @@ namespace WPEFramework
is_set.store(false);
}

const DataType& getValue() const {
const CacheValue& getValue() const {
std::lock_guard<std::mutex> lock(mutex);
return value;
}

DataType& getValue() {
CacheValue& getValue() {
std::lock_guard<std::mutex> lock(mutex);
return value;
}

private:
DataType value;
CacheValue value;
std::atomic<bool> is_set;
mutable std::mutex mutex;
};
Expand Down
27 changes: 7 additions & 20 deletions NetworkManagerJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ namespace WPEFramework
Unregister("GetSupportedSecurityModes");
}

static bool caseInsensitiveCompare(const std::string& str1, const char* str2)
{
std::string upperStr1 = str1;
std::transform(upperStr1.begin(), upperStr1.end(), upperStr1.begin(), ::toupper);
return upperStr1 == str2;
}

uint32_t NetworkManager::SetLogLevel (const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
Expand Down Expand Up @@ -299,33 +292,27 @@ namespace WPEFramework
if (parameters.HasLabel("ipversion"))
ipversion = parameters["ipversion"].String();

if (!interface.empty() && ("wlan0" != interface) && ("eth0" != interface))
if (interface.empty() || ("wlan0" != interface && "eth0" != interface))
{
if(!interface.empty()) {
NMLOG_WARNING("interface is neither wlan0 nor eth0: %s", interface.c_str());
return Core::ERROR_RPC_CALL_FAILED;
return Core::ERROR_BAD_REQUEST;
}

NMLOG_TRACE("mandatory parameter 'interface' is missing");
interface = m_primaryInterfaceCache.getValue();
}

if ("wlan0" == interface && m_wifiStateCache.isSet() && m_wifiStateCache.getValue() != Exchange::INetworkManager::WIFI_STATE_CONNECTED)
{
NMLOG_WARNING("WiFi not connected; no IP address available");
rc = Core::ERROR_NONE;
}
else if(m_primaryInterfaceCache.isSet() && (interface == m_primaryInterfaceCache.getValue()))
if(m_primaryInterfaceCache.isSet() && (interface == m_primaryInterfaceCache.getValue()))
{
/* If ipversion is empty, IPv4 will be taken as the default version */
if(m_ipv4AddressCache.isSet() && (ipversion.empty() || caseInsensitiveCompare(ipversion,"IPV4")))
if(m_ipv4AddressCache.isSet() && (ipversion.empty() || strcasecmp(ipversion.c_str(), "IPv4") == 0))
{
NMLOG_INFO("reading ipv4 settings cached values");
result = m_ipv4AddressCache.getValue();
rc = Core::ERROR_NONE;
isCacheLoaded = true;
}
else if(m_ipv6AddressCache.isSet() && (ipversion.empty() || caseInsensitiveCompare(ipversion,"IPV6")))
else if(m_ipv6AddressCache.isSet() && (ipversion.empty() || strcasecmp(ipversion.c_str(), "IPv6") == 0))
{
NMLOG_INFO("reading ipv6 settings cached values");
result = m_ipv6AddressCache.getValue();
Expand All @@ -343,9 +330,9 @@ namespace WPEFramework
if(Core::ERROR_NONE == rc && m_primaryInterfaceCache.isSet() && (interface == m_primaryInterfaceCache.getValue()))
{
NMLOG_TRACE("caching the ip address values");
if(caseInsensitiveCompare(result.m_ipAddrType,"IPV4"))
if (strcasecmp(result.m_ipAddrType.c_str(), "IPv4") == 0)
m_ipv4AddressCache = result;
else if(caseInsensitiveCompare(result.m_ipAddrType,"IPV6"))
else if (strcasecmp(result.m_ipAddrType.c_str(), "IPv6") == 0)
m_ipv6AddressCache = result;
}
}
Expand Down
5 changes: 2 additions & 3 deletions NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ namespace WPEFramework
}
default:
{
NMLOG_TRACE("Event %d received; Unhandled", eventId);
NMLOG_INFO("Event %d received; Unhandled", eventId);
break;
}
}
Expand Down Expand Up @@ -818,7 +818,6 @@ namespace WPEFramework

strncpy(iarmData.ipversion, ipversion.c_str(), 16);
iarmData.isSupported = true;

if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getIPSettings, (void *)&iarmData, sizeof(iarmData)))
{
result.m_ipAddrType = string(iarmData.ipversion);
Expand All @@ -833,7 +832,7 @@ namespace WPEFramework
result.m_gateway = string(iarmData.gateway,MAX_IP_ADDRESS_LEN - 1);
result.m_primaryDns = string(iarmData.primarydns,MAX_IP_ADDRESS_LEN - 1);
result.m_secondaryDns = string(iarmData.secondarydns,MAX_IP_ADDRESS_LEN - 1);
NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - IARM Success.. Filled the data");
NMLOG_INFO("%s - IARM Success", IARM_BUS_NETSRVMGR_API_getIPSettings);
rc = Core::ERROR_NONE;
}
else
Expand Down

0 comments on commit 3a12bb0

Please sign in to comment.