Segregate utility methods
This commit segregates utility methods required commonly by both
openpower-read-vpd and ibm-read-vpd from methods only required by
ibm-read-vpd.
All dependency required by utility methods specific to ibm-read-vpd
is not applicable to utility methods required by openpower-read-vpd.
Hence to avoid un-necessary dependency inclusion, this change is
introduced.
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I95f2be27dc0c391a45beb1654a99506317aaa52b
diff --git a/common_utility.cpp b/common_utility.cpp
new file mode 100644
index 0000000..5a12b6c
--- /dev/null
+++ b/common_utility.cpp
@@ -0,0 +1,75 @@
+#include "common_utility.hpp"
+
+#include "const.hpp"
+
+#include <iostream>
+#include <phosphor-logging/log.hpp>
+
+namespace openpower
+{
+namespace vpd
+{
+namespace common
+{
+namespace utility
+{
+using namespace constants;
+using namespace inventory;
+using namespace phosphor::logging;
+
+std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
+ const std::string& interface)
+{
+ auto mapper = bus.new_method_call(mapperDestination, mapperObjectPath,
+ mapperInterface, "GetObject");
+ mapper.append(path, std::vector<std::string>({interface}));
+
+ std::map<std::string, std::vector<std::string>> response;
+ try
+ {
+ auto reply = bus.call(mapper);
+ reply.read(response);
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ log<level::ERR>("D-Bus call exception",
+ entry("OBJPATH=%s", mapperObjectPath),
+ entry("INTERFACE=%s", mapperInterface),
+ entry("EXCEPTION=%s", e.what()));
+
+ throw std::runtime_error("Service name is not found");
+ }
+
+ if (response.empty())
+ {
+ throw std::runtime_error("Service name response is empty");
+ }
+
+ return response.begin()->first;
+}
+
+void callPIM(ObjectMap&& objects)
+{
+ try
+ {
+ auto bus = sdbusplus::bus::new_default();
+ auto service = getService(bus, pimPath, pimIntf);
+ auto pimMsg =
+ bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify");
+ pimMsg.append(std::move(objects));
+ auto result = bus.call(pimMsg);
+ if (result.is_method_error())
+ {
+ std::cerr << "PIM Notify() failed\n";
+ }
+ }
+ catch (const std::runtime_error& e)
+ {
+ log<level::ERR>(e.what());
+ }
+}
+
+} // namespace utility
+} // namespace common
+} // namespace vpd
+} // namespace openpower
\ No newline at end of file
diff --git a/common_utility.hpp b/common_utility.hpp
new file mode 100644
index 0000000..15e2f2c
--- /dev/null
+++ b/common_utility.hpp
@@ -0,0 +1,31 @@
+#pragma once
+#include "types.hpp"
+
+namespace openpower
+{
+namespace vpd
+{
+namespace common
+{
+namespace utility
+{
+
+/** @brief Api to Get d-bus service for given interface
+ * @param[in] bus - Bus object
+ * @param[in] path - object path of the service
+ * @param[in] interface - interface under the object path
+ * @return service name
+ */
+std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
+ const std::string& interface);
+
+/** @brief Call inventory-manager to add objects
+ *
+ * @param [in] objects - Map of inventory object paths
+ */
+void callPIM(inventory::ObjectMap&& objects);
+
+} // namespace utility
+} // namespace common
+} // namespace vpd
+} // namespace openpower
\ No newline at end of file
diff --git a/const.hpp b/const.hpp
index 5c67968..8130334 100644
--- a/const.hpp
+++ b/const.hpp
@@ -125,6 +125,17 @@
FAILED = -1
};
} // namespace eccStatus
+
+/**
+ * @brief Types of VPD
+ */
+enum vpdType
+{
+ IPZ_VPD, /**< IPZ VPD type */
+ KEYWORD_VPD, /**< Keyword VPD type */
+ MEMORY_VPD, /**< Memory VPD type */
+ INVALID_VPD_FORMAT /**< Invalid VPD type */
+};
} // namespace constants
} // namespace vpd
} // namespace openpower
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index 7eddeba..c677ba2 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -1,11 +1,12 @@
#include "config.h"
+#include "common_utility.hpp"
#include "defines.hpp"
+#include "ibm_vpd_utils.hpp"
#include "ipz_parser.hpp"
#include "keyword_vpd_parser.hpp"
#include "memory_vpd_parser.hpp"
#include "parser_factory.hpp"
-#include "utils.hpp"
#include "vpd_exceptions.hpp"
#include <assert.h>
@@ -913,7 +914,7 @@
}
// Notify PIM
- inventory::callPIM(move(objects));
+ common::utility::callPIM(move(objects));
}
int main(int argc, char** argv)
diff --git a/utils.cpp b/ibm_vpd_utils.cpp
similarity index 84%
rename from utils.cpp
rename to ibm_vpd_utils.cpp
index 69fbe6e..d691c84 100644
--- a/utils.cpp
+++ b/ibm_vpd_utils.cpp
@@ -1,12 +1,14 @@
#include "config.h"
-#include "utils.hpp"
+#include "ibm_vpd_utils.hpp"
+#include "common_utility.hpp"
#include "defines.hpp"
#include "vpd_exceptions.hpp"
#include <fstream>
#include <iomanip>
+#include <nlohmann/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/server.hpp>
@@ -26,61 +28,10 @@
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace record;
using namespace openpower::vpd::exceptions;
+using namespace common::utility;
namespace inventory
{
-std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
- const std::string& interface)
-{
- auto mapper = bus.new_method_call(mapperDestination, mapperObjectPath,
- mapperInterface, "GetObject");
- mapper.append(path, std::vector<std::string>({interface}));
-
- std::map<std::string, std::vector<std::string>> response;
- try
- {
- auto reply = bus.call(mapper);
- reply.read(response);
- }
- catch (const sdbusplus::exception::SdBusError& e)
- {
- log<level::ERR>("D-Bus call exception",
- entry("OBJPATH=%s", mapperObjectPath),
- entry("INTERFACE=%s", mapperInterface),
- entry("EXCEPTION=%s", e.what()));
-
- throw std::runtime_error("Service name is not found");
- }
-
- if (response.empty())
- {
- throw std::runtime_error("Service name response is empty");
- }
-
- return response.begin()->first;
-}
-
-void callPIM(ObjectMap&& objects)
-{
- try
- {
- auto bus = sdbusplus::bus::new_default();
- auto service = getService(bus, pimPath, pimIntf);
- auto pimMsg =
- bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify");
- pimMsg.append(std::move(objects));
- auto result = bus.call(pimMsg);
- if (result.is_method_error())
- {
- std::cerr << "PIM Notify() failed\n";
- }
- }
- catch (const std::runtime_error& e)
- {
- log<level::ERR>(e.what());
- }
-}
-
MapperResponse
getObjectSubtreeForInterfaces(const std::string& root, const int32_t depth,
const std::vector<std::string>& interfaces)
@@ -111,35 +62,6 @@
} // namespace inventory
-vpdType vpdTypeCheck(const Binary& vpdVector)
-{
- // Read first 3 Bytes to check the 11S bar code format
- std::string is11SFormat = "";
- for (uint8_t i = 0; i < FORMAT_11S_LEN; i++)
- {
- is11SFormat += vpdVector[MEMORY_VPD_DATA_START + i];
- }
-
- if (vpdVector[IPZ_DATA_START] == KW_VAL_PAIR_START_TAG)
- {
- // IPZ VPD FORMAT
- return vpdType::IPZ_VPD;
- }
- else if (vpdVector[KW_VPD_DATA_START] == KW_VPD_START_TAG)
- {
- // KEYWORD VPD FORMAT
- return vpdType::KEYWORD_VPD;
- }
- else if (is11SFormat.compare(MEMORY_VPD_START_TAG) == 0)
- {
- // Memory VPD format
- return vpdType::MEMORY_VPD;
- }
-
- // INVALID VPD FORMAT
- return vpdType::INVALID_VPD_FORMAT;
-}
-
LE2ByteData readUInt16LE(Binary::const_iterator iterator)
{
LE2ByteData lowByte = *iterator;
@@ -346,5 +268,34 @@
return present;
}
+vpdType vpdTypeCheck(const Binary& vpdVector)
+{
+ // Read first 3 Bytes to check the 11S bar code format
+ std::string is11SFormat = "";
+ for (uint8_t i = 0; i < FORMAT_11S_LEN; i++)
+ {
+ is11SFormat += vpdVector[MEMORY_VPD_DATA_START + i];
+ }
+
+ if (vpdVector[IPZ_DATA_START] == KW_VAL_PAIR_START_TAG)
+ {
+ // IPZ VPD FORMAT
+ return vpdType::IPZ_VPD;
+ }
+ else if (vpdVector[KW_VPD_DATA_START] == KW_VPD_START_TAG)
+ {
+ // KEYWORD VPD FORMAT
+ return vpdType::KEYWORD_VPD;
+ }
+ else if (is11SFormat.compare(MEMORY_VPD_START_TAG) == 0)
+ {
+ // Memory VPD format
+ return vpdType::MEMORY_VPD;
+ }
+
+ // INVALID VPD FORMAT
+ return vpdType::INVALID_VPD_FORMAT;
+}
+
} // namespace vpd
} // namespace openpower
diff --git a/utils.hpp b/ibm_vpd_utils.hpp
similarity index 80%
rename from utils.hpp
rename to ibm_vpd_utils.hpp
index 94f4992..e21f13d 100644
--- a/utils.hpp
+++ b/ibm_vpd_utils.hpp
@@ -4,7 +4,6 @@
#include "types.hpp"
#include <iostream>
-#include <nlohmann/json.hpp>
using namespace std;
@@ -12,26 +11,6 @@
{
namespace vpd
{
-/**
- * @brief Types of VPD
- */
-enum vpdType
-{
- IPZ_VPD, /**< IPZ VPD type */
- KEYWORD_VPD, /**< Keyword VPD type */
- MEMORY_VPD, /**< Memory VPD type */
- INVALID_VPD_FORMAT /**< Invalid VPD type */
-};
-
-/**
- * @brief Check the type of VPD.
- *
- * Checks the type of vpd based on the start tag.
- * @param[in] vector - Vpd data in vector format
- *
- * @return enum of type vpdType
- */
-vpdType vpdTypeCheck(const Binary& vector);
/** @brief Return the hex representation of the incoming byte
*
@@ -46,22 +25,6 @@
namespace inventory
{
-
-/** @brief Api to Get d-bus service for given interface
- * @param[in] - Bus object
- * @param[in] - object path of the service
- * @param[in] - interface under the object path
- * @return service name
- */
-std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
- const std::string& interface);
-
-/** @brief Call inventory-manager to add objects
- *
- * @param [in] objects - Map of inventory object paths
- */
-void callPIM(ObjectMap&& objects);
-
/** @brief Api to obtain a dictionary of path -> services
* where path is in subtree and services is of the type
* returned by the GetObject method.
@@ -139,5 +102,15 @@
*/
bool isRecKwInDbusJson(const std::string& record, const std::string& keyword);
+/**
+ * @brief Check the type of VPD.
+ *
+ * Checks the type of vpd based on the start tag.
+ * @param[in] vector - Vpd data in vector format
+ *
+ * @return enum of type vpdType
+ */
+constants::vpdType vpdTypeCheck(const Binary& vector);
+
} // namespace vpd
} // namespace openpower
diff --git a/impl.cpp b/impl.cpp
index d8a6138..a0a45d9 100644
--- a/impl.cpp
+++ b/impl.cpp
@@ -2,7 +2,7 @@
#include "const.hpp"
#include "defines.hpp"
-#include "utils.hpp"
+#include "ibm_vpd_utils.hpp"
#include "vpd_exceptions.hpp"
#include <algorithm>
diff --git a/meson.build b/meson.build
index 1a44195..e05edc3 100644
--- a/meson.build
+++ b/meson.build
@@ -52,11 +52,11 @@
}
)
-common_SOURCES =[
+common_SOURCES =['common_utility.cpp',
'vpd-parser/parser_factory.cpp',
'vpd-parser/memory_vpd_parser.cpp',
'vpd-parser/keyword_vpd_parser.cpp',
- 'vpd-parser/ipz_parser.cpp', 'impl.cpp', 'utils.cpp',
+ 'vpd-parser/ipz_parser.cpp', 'impl.cpp', 'ibm_vpd_utils.cpp',
'vpdecc/vpdecc.c', 'vpdecc/vpdecc_support.c'
]
@@ -142,7 +142,7 @@
'impl.cpp',
'vpd-parser/ipz_parser.cpp',
'write.cpp',
- 'utils.cpp',
+ 'common_utility.cpp',
writefru_hpp,
extra_properties_gen_hpp
]
diff --git a/test/meson.build b/test/meson.build
index 97b5e1c..74bb079 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -22,13 +22,14 @@
'keyword_vpd_parser_test/kw_vpd_test.cpp',
'vpd-manager-test/reader_test.cpp',
'vpd-manager-test/editor_test.cpp'
- ]
+]
application_src =['../impl.cpp',
'../vpdecc/vpdecc.c',
'../vpdecc/vpdecc_support.c',
'../vpd-parser/ipz_parser.cpp',
- '../utils.cpp',
+ '../ibm_vpd_utils.cpp',
+ '../common_utility.cpp',
'../vpd-manager/reader_impl.cpp',
'../vpd-parser/keyword_vpd_parser.cpp',
'../vpd-manager/editor_impl.cpp',
diff --git a/utilInterface.hpp b/utilInterface.hpp
index 086f510..0d13b7d 100644
--- a/utilInterface.hpp
+++ b/utilInterface.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "utils.hpp"
+#include "ibm_vpd_utils.hpp"
#include <string>
diff --git a/vpd-manager/editor_impl.cpp b/vpd-manager/editor_impl.cpp
index 9ca68fc..23079f2 100644
--- a/vpd-manager/editor_impl.cpp
+++ b/vpd-manager/editor_impl.cpp
@@ -2,9 +2,9 @@
#include "editor_impl.hpp"
+#include "ibm_vpd_utils.hpp"
#include "ipz_parser.hpp"
#include "parser_factory.hpp"
-#include "utils.hpp"
#include "vpdecc/vpdecc.h"
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index 5344664..feb6115 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -3,9 +3,9 @@
#include "manager.hpp"
#include "editor_impl.hpp"
+#include "ibm_vpd_utils.hpp"
#include "ipz_parser.hpp"
#include "reader_impl.hpp"
-#include "utils.hpp"
using namespace openpower::vpd::constants;
using namespace openpower::vpd::inventory;
diff --git a/vpd-manager/meson.build b/vpd-manager/meson.build
index 56b139e..66e283f 100644
--- a/vpd-manager/meson.build
+++ b/vpd-manager/meson.build
@@ -11,7 +11,8 @@
'reader_impl.cpp',
'../impl.cpp',
'../vpd-parser/ipz_parser.cpp',
- '../utils.cpp',
+ '../ibm_vpd_utils.cpp',
+ '../common_utility.cpp',
'../vpdecc/vpdecc.c',
'../vpdecc/vpdecc_support.c',
'../vpd-parser//keyword_vpd_parser.cpp',
diff --git a/vpd-manager/reader_impl.cpp b/vpd-manager/reader_impl.cpp
index 4da02be..08eb32b 100644
--- a/vpd-manager/reader_impl.cpp
+++ b/vpd-manager/reader_impl.cpp
@@ -2,7 +2,7 @@
#include "reader_impl.hpp"
-#include "utils.hpp"
+#include "ibm_vpd_utils.hpp"
#include <algorithm>
#include <com/ibm/VPD/error.hpp>
diff --git a/vpd-parser/parser_factory.cpp b/vpd-parser/parser_factory.cpp
index 7953655..0489ef1 100644
--- a/vpd-parser/parser_factory.cpp
+++ b/vpd-parser/parser_factory.cpp
@@ -1,9 +1,10 @@
#include "parser_factory.hpp"
+#include "const.hpp"
+#include "ibm_vpd_utils.hpp"
#include "ipz_parser.hpp"
#include "keyword_vpd_parser.hpp"
#include "memory_vpd_parser.hpp"
-#include "utils.hpp"
#include "vpd_exceptions.hpp"
using namespace vpd::keyword::parser;
@@ -11,6 +12,7 @@
using namespace openpower::vpd::parser::interface;
using namespace openpower::vpd::ipz::parser;
using namespace openpower::vpd::exceptions;
+using namespace openpower::vpd::constants;
namespace openpower
{
diff --git a/vpd_tool.cpp b/vpd_tool.cpp
index 9e76331..a4891f6 100644
--- a/vpd_tool.cpp
+++ b/vpd_tool.cpp
@@ -1,4 +1,3 @@
-#include "utils.hpp"
#include "vpd_tool_impl.hpp"
#include <CLI/CLI.hpp>
diff --git a/vpd_tool_impl.hpp b/vpd_tool_impl.hpp
index 1ca50b5..4e320b2 100644
--- a/vpd_tool_impl.hpp
+++ b/vpd_tool_impl.hpp
@@ -1,8 +1,8 @@
#include "config.h"
#include "editor_impl.hpp"
+#include "ibm_vpd_utils.hpp"
#include "types.hpp"
-#include "utils.hpp"
#include <nlohmann/json.hpp>
#include <string>
diff --git a/writefru.mako.hpp b/writefru.mako.hpp
index 203d033..6e04649 100755
--- a/writefru.mako.hpp
+++ b/writefru.mako.hpp
@@ -10,7 +10,7 @@
#include "defines.hpp"
#include "store.hpp"
#include "types.hpp"
-#include "utils.hpp"
+#include "common_utility.hpp"
#include "extra-properties-gen.hpp"
namespace openpower
@@ -19,6 +19,7 @@
{
namespace inventory
{
+using namespace openpower::vpd::common::utility;
/** @brief API to write parsed VPD to inventory,
* for a specific FRU