summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-02-16 23:48:18 -0600
committerPatrick Williams <patrick@stwcx.xyz>2017-02-20 14:20:20 +0000
commit76794495882082db189e2fc6d6c05dfe3756338a (patch)
tree1f8d437d6ee55d6a0ffa12d6ca0ab4db50a4806e
parentc6e551b97ad17f786f84efd3705d84e3f320ddc0 (diff)
downloadopenpower-vpd-parser-76794495882082db189e2fc6d6c05dfe3756338a.tar.gz
openpower-vpd-parser-76794495882082db189e2fc6d6c05dfe3756338a.zip
refactor: move types and utils in their own files
Change-Id: I477dd69f0c6c648b63171dc2db264d3e70dafaf4 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r--Makefile.am7
-rw-r--r--test/Makefile.am3
-rw-r--r--types.hpp23
-rw-r--r--utils.cpp73
-rw-r--r--utils.hpp26
-rwxr-xr-xwritefru.mako.hpp76
6 files changed, 131 insertions, 77 deletions
diff --git a/Makefile.am b/Makefile.am
index 89c3cc9..de3232a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,7 +6,9 @@ noinst_HEADERS = \
types.hpp \
write.hpp \
impl.hpp \
- args.hpp
+ args.hpp \
+ types.hpp \
+ utils.hpp
# Be sure to build writefru.hpp before compiling
BUILT_SOURCES = writefru.hpp
@@ -27,7 +29,8 @@ openpower_read_vpd_SOURCES = \
args.cpp \
impl.cpp \
parser.cpp \
- write.cpp
+ write.cpp \
+ utils.cpp
openpower_read_vpd_LDFLAGS = $(SDBUSPLUS_LIBS) $(PHOSPHOR_LOGGING_LIBS)
openpower_read_vpd_CXXFLAGS = $(SDBUSPLUS_CFLAGS) $(PHOSPHOR_LOGGING_CFLAGS)
diff --git a/test/Makefile.am b/test/Makefile.am
index 0eb18ac..4e69969 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -12,6 +12,7 @@ parser_test_SOURCES = \
parser/parser.cpp \
../impl.cpp \
../parser.cpp \
- ../write.cpp
+ ../write.cpp \
+ ../utils.cpp
parser_test_LDFLAGS = $(SDBUSPLUS_LIBS) $(PHOSPHOR_LOGGING_LIBS)
parser_test_CXXFLAGS = $(SDBUSPLUS_CFLAGS) $(PHOSPHOR_LOGGING_CFLAGS)
diff --git a/types.hpp b/types.hpp
index 7e56eb4..d65aa70 100644
--- a/types.hpp
+++ b/types.hpp
@@ -2,6 +2,9 @@
#include <climits>
#include <vector>
+#include <string>
+#include <map>
+#include <sdbusplus/server.hpp>
namespace openpower
{
@@ -14,5 +17,25 @@ static_assert((8 == CHAR_BIT), "A byte is not 8 bits!");
using Byte = uint8_t;
using Binary = std::vector<Byte>;
+namespace inventory
+{
+
+using Path = std::string;
+using Property = std::string;
+using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
+using PropertyMap = std::map<Property, Value>;
+
+using Interface = std::string;
+using InterfaceMap = std::map<Interface, PropertyMap>;
+
+using Object = sdbusplus::message::object_path;
+using ObjectMap = std::map<Object, InterfaceMap>;
+
+using namespace std::string_literals;
+static const auto pimPath = "/xyz/openbmc_project/Inventory"s;
+static const auto pimIntf = "xyz.openbmc_project.Inventory.Manager"s;
+
+} // namespace inventory
+
} // namespace vpd
} // namespace openpower
diff --git a/utils.cpp b/utils.cpp
new file mode 100644
index 0000000..4226d44
--- /dev/null
+++ b/utils.cpp
@@ -0,0 +1,73 @@
+#include "utils.hpp"
+#include <sdbusplus/server.hpp>
+#include <log.hpp>
+#include <iostream>
+
+namespace openpower
+{
+namespace vpd
+{
+
+namespace inventory
+{
+
+auto getPIMService()
+{
+ auto bus = sdbusplus::bus::new_default();
+ auto mapper =
+ bus.new_method_call(
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/ObjectMapper",
+ "xyz.openbmc_project.ObjectMapper",
+ "GetObject");
+
+ mapper.append(pimPath);
+ mapper.append(std::vector<std::string>({pimIntf}));
+
+ auto result = bus.call(mapper);
+ if(result.is_method_error())
+ {
+ throw std::runtime_error("ObjectMapper GetObject failed");
+ }
+
+ std::map<std::string, std::vector<std::string>> response;
+ result.read(response);
+ if(response.empty())
+ {
+ throw std::runtime_error("ObjectMapper GetObject bad response");
+ }
+
+ return response.begin()->first;
+}
+
+void callPIM(ObjectMap&& objects)
+{
+ std::string service;
+
+ try
+ {
+ service = getPIMService();
+ auto bus = sdbusplus::bus::new_default();
+ auto pimMsg = bus.new_method_call(
+ service.c_str(),
+ pimPath.c_str(),
+ pimIntf.c_str(),
+ "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)
+ {
+ using namespace phosphor::logging;
+ log<level::ERR>(e.what());
+ }
+}
+
+} // namespace inventory
+
+} //namespace vpd
+} //namespace openpower
diff --git a/utils.hpp b/utils.hpp
new file mode 100644
index 0000000..0aeeb32
--- /dev/null
+++ b/utils.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "types.hpp"
+
+namespace openpower
+{
+namespace vpd
+{
+
+namespace inventory
+{
+
+/** @brief Get inventory-manager's d-bus service
+ */
+auto getPIMService();
+
+/** @brief Call inventory-manager to add objects
+ *
+ * @param [in] objects - Map of inventory object paths
+ */
+void callPIM(ObjectMap&& objects);
+
+} // namespace inventory
+
+} //namespace vpd
+} //namespace openpower
diff --git a/writefru.mako.hpp b/writefru.mako.hpp
index 7066f9a..9275e9f 100755
--- a/writefru.mako.hpp
+++ b/writefru.mako.hpp
@@ -7,10 +7,10 @@
#include <map>
#include <iostream>
-#include <sdbusplus/server.hpp>
-#include <log.hpp>
#include "defines.hpp"
#include "store.hpp"
+#include "types.hpp"
+#include "utils.hpp"
namespace openpower
{
@@ -19,78 +19,6 @@ namespace vpd
namespace inventory
{
-using Property = std::string;
-using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
-using PropertyMap = std::map<Property, Value>;
-
-using Interface = std::string;
-using InterfaceMap = std::map<Interface, PropertyMap>;
-
-using Object = sdbusplus::message::object_path;
-using ObjectMap = std::map<Object, InterfaceMap>;
-
-using namespace std::string_literals;
-static const auto pimPath = "/xyz/openbmc_project/Inventory"s;
-static const auto pimIntf = "xyz.openbmc_project.Inventory.Manager"s;
-
-/** @brief Get inventory-manager's d-bus service
- */
-auto getPIMService()
-{
- auto bus = sdbusplus::bus::new_default();
- auto mapper =
- bus.new_method_call(
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/ObjectMapper",
- "xyz.openbmc_project.ObjectMapper",
- "GetObject");
-
- mapper.append(pimPath);
- mapper.append(std::vector<std::string>({pimIntf}));
-
- auto result = bus.call(mapper);
- if(result.is_method_error())
- {
- throw std::runtime_error("ObjectMapper GetObject failed");
- }
-
- std::map<std::string, std::vector<std::string>> response;
- result.read(response);
- if(response.empty())
- {
- throw std::runtime_error("ObjectMapper GetObject bad response");
- }
-
- return response.begin()->first;
-}
-
-auto callPIM(ObjectMap&& objects)
-{
- std::string service;
-
- try
- {
- service = getPIMService();
- auto bus = sdbusplus::bus::new_default();
- auto pimMsg = bus.new_method_call(
- service.c_str(),
- pimPath.c_str(),
- pimIntf.c_str(),
- "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)
- {
- using namespace phosphor::logging;
- log<level::ERR>(e.what());
- }
-}
-
/** @brief API to write parsed VPD to inventory,
* for a specifc FRU
*
OpenPOWER on IntegriCloud