diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/usr/targeting/common/attributeTank.H | 8 | ||||
-rw-r--r-- | src/include/usr/targeting/common/target.H | 22 | ||||
-rw-r--r-- | src/include/usr/targeting/common/targetUtil.H | 154 |
3 files changed, 168 insertions, 16 deletions
diff --git a/src/include/usr/targeting/common/attributeTank.H b/src/include/usr/targeting/common/attributeTank.H index 9561b9b83..4e67e72db 100644 --- a/src/include/usr/targeting/common/attributeTank.H +++ b/src/include/usr/targeting/common/attributeTank.H @@ -34,13 +34,12 @@ #include <stdint.h> #include <list> #include <vector> +#include <attributeenums.H> // TARGETING::ATTRIBUTE_ID #ifndef STANDALONE_COMPILE #include <targeting/adapters/mutexadapter.H> #include <targeting/common/error.H> namespace TARGETING { - - /** * @class AttributeTank * @@ -293,7 +292,7 @@ namespace AttributeTank * * return A constant pointer to the Attribute Value */ - const void* const getValue() const + const void* getValue() const { return iv_pVal; } @@ -729,7 +728,8 @@ private: // Lock for thread safety (class provided by platform) mutable TARG_MUTEX_TYPE iv_mutex; -}; + +}; // end AttributeTank #endif //STANDALONE_COMPILE diff --git a/src/include/usr/targeting/common/target.H b/src/include/usr/targeting/common/target.H index bfb5e70c7..3e7eb82e7 100644 --- a/src/include/usr/targeting/common/target.H +++ b/src/include/usr/targeting/common/target.H @@ -584,7 +584,16 @@ class Target return _trySetAttr(i_attr, i_size, i_pAttrData); } - + /** + * @brief Returns the target's type as used in a Targeting attribute + * tank. + * + * This target type is associated with an attribute in an attribute + * tank and helps identify which target(s) the attribute belongs to + * + * @return uint32_t The target type + */ + uint32_t getAttrTankTargetType() const; private: // Private helper interfaces @@ -809,17 +818,6 @@ class Target mutex_t*& o_pMutex) const; /** - * @brief Returns the target's type as used in a Targeting attribute - * tank. - * - * This target type is associated with an attribute in an attribute - * tank and helps identify which target(s) the attribute belongs to - * - * @return uint32_t The target type - */ - uint32_t getAttrTankTargetType() const; - - /** * @brief enumeration of assert reasons */ enum TargAssertReason diff --git a/src/include/usr/targeting/common/targetUtil.H b/src/include/usr/targeting/common/targetUtil.H new file mode 100644 index 000000000..86a49c8b0 --- /dev/null +++ b/src/include/usr/targeting/common/targetUtil.H @@ -0,0 +1,154 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/include/usr/targeting/common/targetUtil.H $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2013,2019 */ +/* [+] International Business Machines Corp. */ +/* */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); */ +/* you may not use this file except in compliance with the License. */ +/* You may obtain a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ +/* implied. See the License for the specific language governing */ +/* permissions and limitations under the License. */ +/* */ +/* IBM_PROLOG_END_TAG */ + +/** + * @file + * + * @brief Defines templates methods that require the use of the + * class Target and struct Attribute. Having the methods + * in this file helps with circular dependencies issue. + */ + +#ifndef __TARGETING_COMMON_TARGET_UTIL_H +#define __TARGETING_COMMON_TARGET_UTIL_H + +#include <stdint.h> // int16_t, uint8_t +#include <attributeenums.H> // TARGETING::ATTRIBUTE_ID +#include <targeting/common/target.H> // Target +#include <targeting/common/attributeTank.H> // AttributeTank::Attribute + +#ifndef STANDALONE_COMPILE + +namespace TARGETING +{ +/** + * @brief Returns the target handle's attribute associated with the given + * simple type attribute ID. + * + * @param[in] i_target The target to retrieve the attribute data from + * @param[out] o_attribute The attribute data, for the given attribute ID, + * if found + * + * @pre i_target must be a valid target + * + * @return Attribute data for given attribute ID, if found, else + * outgoing attribute will not touched + * + * @retval true is successful in locating the attribute ID, false otherwise + */ +template<const ATTRIBUTE_ID A> +bool makeAttribute(TargetHandle_t i_target, + AttributeTank::Attribute& o_attribute) +{ + // Set up the return value to true ... hoping for the best + bool retVal(true); + + do + { + // Some needed variables and their defaults + uint16_t l_positon(TARGETING::AttributeTank::ATTR_POS_NA); + uint8_t l_unitPositon(AttributeTank::ATTR_UNIT_POS_NA), + l_node(AttributeTank::ATTR_NODE_NA); + + // Get the target's position data + i_target->getAttrTankTargetPosData(l_positon, l_unitPositon, l_node); + + // Get the target's type and the target's attribute data + auto l_targetType = i_target->getAttrTankTargetType(); + auto l_attributeData = i_target->getAttr<A>(); + + // Populate the outgoing Attribute with the data retrieved above + o_attribute.setId(A); + o_attribute.setTargetType(l_targetType); + o_attribute.setPosition(l_positon); + o_attribute.setUnitPosition(l_unitPositon); + o_attribute.setNode(l_node); + o_attribute.setValue(&l_attributeData, sizeof(l_attributeData)); + } while (0); + + return retVal; +}; // end makeAttribute + +/** + * @brief Returns the target handle's attribute associated with the given + * complex type attribute ID. + * + * @param[in] i_target The target to retrieve the attribute data from + * @param[out] o_attribute The attribute data, for the given attribute ID, + * if found + * + * @pre i_target must be a valid target + * + * @return Attribute data for given attribute ID, if found, else + * outgoing attribute will not touched + * + * @retval true is successful in locating the attribute ID, false otherwise + */ +template<const ATTRIBUTE_ID A> +bool makeAttributeStdArr(TargetHandle_t i_target, + AttributeTank::Attribute& o_attribute) +{ + // Set up the return value to true ... hoping for the best + bool retVal(true); + + // Variable to hold the complex type, when found + typename AttributeTraits<A>::TypeStdArr l_attributeValue; + + do + { + // Some needed variables and their defaults + uint16_t l_positon(TARGETING::AttributeTank::ATTR_POS_NA); + uint8_t l_unitPositon(AttributeTank::ATTR_UNIT_POS_NA), + l_node(AttributeTank::ATTR_NODE_NA); + + // Get the target's position data + i_target->getAttrTankTargetPosData(l_positon, l_unitPositon, l_node); + + // Get the target's type and the target's attribute data + auto l_targetType = i_target->getAttrTankTargetType(); + bool l_found = i_target->tryGetAttr<A>(l_attributeValue); + if (!l_found) + { + retVal = false; + break; + } + + // Populate the outgoing Attribute with the data retrieved above + o_attribute.setId(A); + o_attribute.setTargetType(l_targetType); + o_attribute.setPosition(l_positon); + o_attribute.setUnitPosition(l_unitPositon); + o_attribute.setNode(l_node); + o_attribute.setValue(&l_attributeValue, sizeof(l_attributeValue)); + } while (0); + + return retVal; +}; // end makeAttributeStdArr + +}; // end namespace TARGETING + +#endif // end STANDALONE_COMPILE + +#endif // end __TARGETING_COMMON_TARGET_UTIL_H |