From c8f7434b35f7c309b549893ba5923875f58385bc Mon Sep 17 00:00:00 2001 From: Matt Derksen Date: Thu, 11 Feb 2016 14:22:15 -0600 Subject: 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 Reviewed-by: Daniel M. Crowell --- src/include/usr/fapi2/target.H | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/include/usr/fapi2') 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::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 -/// @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& i_target, char* i_buffer, size_t i_bsize) +inline void toString(const Target& 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(i_target.get()); + + if(!l_platTarget->tryGetAttr(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 -/// @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* i_target, char* i_buffer, size_t i_bsize) +inline void toString(const Target *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); } /// -- cgit v1.2.3