diff options
Diffstat (limited to 'user_channel')
-rw-r--r-- | user_channel/channel_mgmt.cpp | 101 | ||||
-rw-r--r-- | user_channel/channel_mgmt.hpp | 6 |
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); |