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 be218ac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 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
35 changes: 11 additions & 24 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 @@ -188,7 +181,7 @@ namespace WPEFramework
string interface;
if(m_primaryInterfaceCache.isSet())
{
NMLOG_TRACE("reading interface cached values");
NMLOG_INFO("reading interface cached values");
interface = m_primaryInterfaceCache.getValue();
rc = Core::ERROR_NONE;
}
Expand Down Expand Up @@ -289,8 +282,8 @@ namespace WPEFramework
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
string interface;
string ipversion;
string interface = "";
string ipversion = "";
bool isCacheLoaded = false;
Exchange::INetworkManager::IPAddressInfo result{};

Expand All @@ -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 @@ -342,10 +329,10 @@ namespace WPEFramework
/* The value will be cached only for the primary interface IP address. */
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"))
NMLOG_DEBUG("caching the ip address values");
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
7 changes: 3 additions & 4 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 @@ -629,7 +629,7 @@ namespace WPEFramework
std::vector<InterfaceDetails> interfaceList;
for (int i = 0; i < list.size; i++)
{
NMLOG_TRACE("Interface Name = %s", list.interfaces[i].name);
NMLOG_DEBUG("Interface Name = %s", list.interfaces[i].name);
string interfaceName(list.interfaces[i].name);
if (("eth0" == interfaceName) || ("wlan0" == interfaceName))
{
Expand Down Expand Up @@ -833,12 +833,11 @@ 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");
rc = Core::ERROR_NONE;
}
else
{
NMLOG_ERROR("%s - Calling IARM Failed", IARM_BUS_NETSRVMGR_API_getIPSettings);
NMLOG_ERROR("NetworkManagerImplementation::GetIPSettings - Calling IARM Failed");
}

return rc;
Expand Down

0 comments on commit be218ac

Please sign in to comment.