diff options
author | Matt Derksen <v2cibmd@us.ibm.com> | 2016-02-11 14:22:15 -0600 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2016-03-30 13:50:25 -0400 |
commit | c8f7434b35f7c309b549893ba5923875f58385bc (patch) | |
tree | 50dae4f15e89e7d5797b4b5aaaee3c347876a904 /src/include | |
parent | 45166b51b84c1411ab58dae694b0f4062b525879 (diff) | |
download | talos-hostboot-c8f7434b35f7c309b549893ba5923875f58385bc.tar.gz talos-hostboot-c8f7434b35f7c309b549893ba5923875f58385bc.zip |
Added fapi2::toString support
Added new FAPI_NAME attribute.
Change-Id: Ib467aa5ac203e9900f3cb6d65f13d7988c363348
RTC: 144504
Depends-on: I9faa3bea86d1b43bca0a7eaca3869b45cc0b0d54
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/20747
Tested-by: Jenkins Server
Tested-by: FSP CI Jenkins
Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/usr/fapi2/target.H | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/include/usr/fapi2/target.H b/src/include/usr/fapi2/target.H index 5eb375336..5f21eb3b3 100644 --- a/src/include/usr/fapi2/target.H +++ b/src/include/usr/fapi2/target.H @@ -740,32 +740,61 @@ Target<K, V>::getOtherEnd(const TargetState i_state) const /// @brief Return the string interpretation of this target /// @tparam T The type of the target /// @param[in] i_target Target<T> -/// @param[in] i_buffer buffer to write in to +/// @param[in/out] io_buffer buffer to write in to /// @param[in] i_bsize size of the buffer /// @return void /// @post The contents of the buffer is replaced with the string /// representation of the target /// template< TargetType T > -inline void toString(const Target<T>& i_target, char* i_buffer, size_t i_bsize) +inline void toString(const Target<T>& i_target, char* io_buffer, size_t i_bsize) { - snprintf(i_buffer, i_bsize, "Target 0x%lx/0x%x", i_target.get(), T); + TARGETING::ATTR_FAPI_NAME_type l_nameString = {0}; + const TARGETING::Target * l_platTarget = + static_cast<const TARGETING::Target*>(i_target.get()); + + if(!l_platTarget->tryGetAttr<TARGETING::ATTR_FAPI_NAME>(l_nameString)) + { + FAPI_ERR("ERROR: Can not read FAPI_NAME attribute"); + snprintf(io_buffer, i_bsize, "Target 0x%lx/0x%x", l_platTarget, T); + } + else + { + size_t needed_buffer_size = strlen((const char*)l_nameString) + 1; + + // Is i_buffer large enough for the entire string + null + if (i_bsize < needed_buffer_size) + { + FAPI_INF("Should use a larger buffer size (%d instead of %d) for %s", + needed_buffer_size, i_bsize, l_nameString); + memcpy(io_buffer, l_nameString, i_bsize); + if (i_bsize > 0) + { + io_buffer[i_bsize-1] = '\0'; + } + } + else + { + // copy full attribute string + null character + memcpy(io_buffer, l_nameString, needed_buffer_size); + } + } } /// /// @brief Return the string interpretation of this target /// @tparam T The type of the target /// @param[in] A pointer to the Target<T> -/// @param[in] i_buffer buffer to write in to +/// @param[in/out] io_buffer buffer to write in to /// @param[in] i_bsize size of the buffer /// @return void /// @post The contents of the buffer is replaced with the string /// representation of the target /// template< TargetType T > -inline void toString(const Target<T>* i_target, char* i_buffer, size_t i_bsize) +inline void toString(const Target<T> *i_target, char* io_buffer, size_t i_bsize) { - snprintf(i_buffer, i_bsize, "Target 0x%lx/0x%x", i_target->get(), T); + toString(*i_target, io_buffer, i_bsize); } /// |