diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-02-16 23:48:18 -0600 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-02-20 14:20:20 +0000 |
commit | 76794495882082db189e2fc6d6c05dfe3756338a (patch) | |
tree | 1f8d437d6ee55d6a0ffa12d6ca0ab4db50a4806e /utils.cpp | |
parent | c6e551b97ad17f786f84efd3705d84e3f320ddc0 (diff) | |
download | openpower-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>
Diffstat (limited to 'utils.cpp')
-rw-r--r-- | utils.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
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 |