Move getPrintableValue api to utils
This commit moves getPrintableValue api from VpdTool
class to utility file, as this is a common api needs to
be used by other class members as well.
Signed-off-by: Priyanga Ramasamy <priyanga24@in.ibm.com>
Change-Id: Iac8a645156d48c9f44308f96bf1f951b663a6669
diff --git a/ibm_vpd_utils.cpp b/ibm_vpd_utils.cpp
index 0d49a3f..bf50bd8 100644
--- a/ibm_vpd_utils.cpp
+++ b/ibm_vpd_utils.cpp
@@ -570,5 +570,39 @@
return kwVal;
}
+string getPrintableValue(const vector<unsigned char>& vec)
+{
+ string str{};
+ bool printableChar = true;
+ for (auto i : vec)
+ {
+ if (!isprint(i))
+ {
+ printableChar = false;
+ break;
+ }
+ }
+
+ if (!printableChar)
+ {
+ stringstream ss;
+ string hexRep = "0x";
+ ss << hexRep;
+ str = ss.str();
+
+ // convert Decimal to Hex
+ for (auto& v : vec)
+ {
+ ss << setfill('0') << setw(2) << hex << (int)v;
+ str = ss.str();
+ }
+ }
+ else
+ {
+ str = string(vec.begin(), vec.end());
+ }
+ return str;
+}
+
} // namespace vpd
} // namespace openpower
\ No newline at end of file
diff --git a/ibm_vpd_utils.hpp b/ibm_vpd_utils.hpp
index f067b9b..209d070 100644
--- a/ibm_vpd_utils.hpp
+++ b/ibm_vpd_utils.hpp
@@ -241,5 +241,17 @@
driverType + "/" + bindOrUnbind);
}
+/**
+ * @brief Get Printable Value
+ *
+ * Checks if the vector value has non printable characters.
+ * Returns hex value if non printable char is found else
+ * returns ascii value.
+ *
+ * @param[in] vector - Reference of the Binary vector
+ * @return printable value - either in hex or in ascii.
+ */
+string getPrintableValue(const vector<unsigned char>& vec);
+
} // namespace vpd
} // namespace openpower
\ No newline at end of file
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index d01a28d..931bba1 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -56,40 +56,6 @@
}
}
-string VpdTool::getPrintableValue(const vector<unsigned char>& vec)
-{
- string str{};
- bool printableChar = true;
- for (auto i : vec)
- {
- if (!isprint(i))
- {
- printableChar = false;
- break;
- }
- }
-
- if (!printableChar)
- {
- stringstream ss;
- string hexRep = "0x";
- ss << hexRep;
- str = ss.str();
-
- // convert Decimal to Hex
- for (auto& v : vec)
- {
- ss << setfill('0') << setw(2) << hex << (int)v;
- str = ss.str();
- }
- }
- else
- {
- str = string(vec.begin(), vec.end());
- }
- return str;
-}
-
void VpdTool::eraseInventoryPath(string& fru)
{
// Power supply frupath comes with INVENTORY_PATH appended in prefix.
diff --git a/vpd_tool_impl.hpp b/vpd_tool_impl.hpp
index 0337617..ac0b2f5 100644
--- a/vpd_tool_impl.hpp
+++ b/vpd_tool_impl.hpp
@@ -165,18 +165,6 @@
void forceReset(const nlohmann::basic_json<>& jsObject);
/**
- * @brief Get Printable Value
- *
- * Checks if the vector value has non printable characters.
- * Returns hex value if non printable char is found else
- * returns ascii value.
- *
- * @param[in] vector - Reference of the Binary vector
- * @return printable value - either in hex or in ascii.
- */
- std::string getPrintableValue(const std::vector<unsigned char>& vector);
-
- /**
* @brief Update Hardware
* If the given record-keyword pair is present in dbus_properties.json,
* then will update the given data in both dbus and hardware.