summaryrefslogtreecommitdiffstats
path: root/user_channel
diff options
context:
space:
mode:
authorJohnathan Mantey <johnathanx.mantey@intel.com>2018-12-11 13:17:55 -0800
committerJohnathan Mantey <johnathanx.mantey@intel.com>2019-02-04 12:34:52 -0800
commit4c0435a22df32b71236a2f59fd8e02cce7f5fa31 (patch)
treebb6ac06c901a930c6f8100a51b90c5a142cc265e /user_channel
parente5c4f1d7a751a6ded6bb099d1949c3871d9c487a (diff)
downloadphosphor-host-ipmid-4c0435a22df32b71236a2f59fd8e02cce7f5fa31.tar.gz
phosphor-host-ipmid-4c0435a22df32b71236a2f59fd8e02cce7f5fa31.zip
Refactor the initialization of the channel data from the JSON
Copy the data retrieved from the JSON data files only after the contents of the two JSON configuration files have been read successfully. The code has also been changed to eliminate excess indentation in order to improve its readability and maintainability. Change-Id: I2def95b854bef39a9e7b196ef340c3a06965653a Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
Diffstat (limited to 'user_channel')
-rw-r--r--user_channel/channel_mgmt.cpp101
-rw-r--r--user_channel/channel_mgmt.hpp6
2 files changed, 47 insertions, 60 deletions
diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp
index 859045a..45a703a 100644
--- a/user_channel/channel_mgmt.cpp
+++ b/user_channel/channel_mgmt.cpp
@@ -381,7 +381,7 @@ std::string ChannelConfig::getChannelName(const uint8_t chNum)
int ChannelConfig::getChannelActiveSessions(const uint8_t chNum)
{
// TODO: TEMPORARY FIX
- // Channels active session count is managed separatly
+ // Channels active session count is managed separately
// by monitoring channel session which includes LAN and
// RAKP layer changes. This will be updated, once the
// authentication part is implemented.
@@ -876,15 +876,12 @@ int ChannelConfig::loadChannelConfig()
return -EIO;
}
- try
+ channelData.fill(ChannelProperties{});
+
+ for (int chNum = 0; chNum < maxIpmiChannels; chNum++)
{
- // Fill in global structure
- for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++)
+ try
{
- std::fill(reinterpret_cast<uint8_t*>(&channelData[chNum]),
- reinterpret_cast<uint8_t*>(&channelData[chNum]) +
- sizeof(ChannelData),
- 0);
std::string chKey = std::to_string(chNum);
Json jsonChData = data[chKey].get<Json>();
if (jsonChData.is_null())
@@ -894,59 +891,49 @@ int ChannelConfig::loadChannelConfig()
entry("CHANNEL_NUM:%d", chNum));
// If user didn't want to configure specific channel (say
// reserved channel), then load that index with default values.
- std::string chName(defaultChannelName);
- setDefaultChannelConfig(chNum, chName);
+ setDefaultChannelConfig(chNum, defaultChannelName);
+ continue;
}
- else
+ Json jsonChInfo = jsonChData[channelInfoString].get<Json>();
+ if (jsonChInfo.is_null())
{
- std::string chName = jsonChData[nameString].get<std::string>();
- channelData[chNum].chName = chName;
- channelData[chNum].chID = chNum;
- channelData[chNum].isChValid =
- jsonChData[isValidString].get<bool>();
- channelData[chNum].activeSessCount =
- jsonChData.value(activeSessionsString, 0);
- channelData[chNum].maxTransferSize =
- jsonChData.value(maxTransferSizeString, smallChannelSize);
- Json jsonChInfo = jsonChData[channelInfoString].get<Json>();
- if (jsonChInfo.is_null())
- {
- log<level::ERR>("Invalid/corrupted channel config file");
- return -EBADMSG;
- }
- else
- {
- std::string medTypeStr =
- jsonChInfo[mediumTypeString].get<std::string>();
- channelData[chNum].chInfo.mediumType = static_cast<uint8_t>(
- convertToMediumTypeIndex(medTypeStr));
- std::string protoTypeStr =
- jsonChInfo[protocolTypeString].get<std::string>();
- channelData[chNum].chInfo.protocolType =
- static_cast<uint8_t>(
- convertToProtocolTypeIndex(protoTypeStr));
- std::string sessStr =
- jsonChInfo[sessionSupportedString].get<std::string>();
- channelData[chNum].chInfo.sessionSupported =
- static_cast<uint8_t>(
- convertToSessionSupportIndex(sessStr));
- channelData[chNum].chInfo.isIpmi =
- jsonChInfo[isIpmiString].get<bool>();
- channelData[chNum].chInfo.authTypeSupported =
- defaultAuthType;
- }
+ log<level::ERR>("Invalid/corrupted channel config file");
+ return -EBADMSG;
}
+
+ ChannelProperties& chData = channelData[chNum];
+ chData.chName = jsonChData[nameString].get<std::string>();
+ chData.chID = chNum;
+ chData.isChValid = jsonChData[isValidString].get<bool>();
+ chData.activeSessCount = jsonChData.value(activeSessionsString, 0);
+ chData.maxTransferSize =
+ jsonChData.value(maxTransferSizeString, smallChannelSize);
+ std::string medTypeStr =
+ jsonChInfo[mediumTypeString].get<std::string>();
+ chData.chInfo.mediumType =
+ static_cast<uint8_t>(convertToMediumTypeIndex(medTypeStr));
+ std::string protoTypeStr =
+ jsonChInfo[protocolTypeString].get<std::string>();
+ chData.chInfo.protocolType =
+ static_cast<uint8_t>(convertToProtocolTypeIndex(protoTypeStr));
+ std::string sessStr =
+ jsonChInfo[sessionSupportedString].get<std::string>();
+ chData.chInfo.sessionSupported =
+ static_cast<uint8_t>(convertToSessionSupportIndex(sessStr));
+ chData.chInfo.isIpmi = jsonChInfo[isIpmiString].get<bool>();
+ chData.chInfo.authTypeSupported = defaultAuthType;
+ }
+ catch (const Json::exception& e)
+ {
+ log<level::DEBUG>("Json Exception caught.",
+ entry("MSG:%s", e.what()));
+ return -EBADMSG;
+ }
+ catch (const std::invalid_argument& e)
+ {
+ log<level::ERR>("Corrupted config.", entry("MSG:%s", e.what()));
+ return -EBADMSG;
}
- }
- catch (const Json::exception& e)
- {
- log<level::DEBUG>("Json Exception caught.", entry("MSG:%s", e.what()));
- return -EBADMSG;
- }
- catch (const std::invalid_argument& e)
- {
- log<level::ERR>("Corrupted config.", entry("MSG:%s", e.what()));
- return -EBADMSG;
}
return 0;
diff --git a/user_channel/channel_mgmt.hpp b/user_channel/channel_mgmt.hpp
index 993b3d1..44aaed6 100644
--- a/user_channel/channel_mgmt.hpp
+++ b/user_channel/channel_mgmt.hpp
@@ -49,12 +49,12 @@ struct ChannelAccessData
ChannelAccess chVolatileData;
};
-/** @struct ChannelData
+/** @struct ChannelProperties
*
* Structure for channel information - base structure to get all information
* about the channel.(refer spec sec 22.22 to 22.24)
*/
-struct ChannelData
+struct ChannelProperties
{
std::string chName;
uint8_t chID;
@@ -238,7 +238,7 @@ class ChannelConfig
nullptr};
private:
- std::array<ChannelData, maxIpmiChannels> channelData;
+ std::array<ChannelProperties, maxIpmiChannels> channelData;
std::time_t nvFileLastUpdatedTime;
std::time_t voltFileLastUpdatedTime;
std::time_t getUpdatedFileTime(const std::string& fileName);
OpenPOWER on IntegriCloud