From 03f4cd957800210c1763605d755904c95f6079f9 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Fri, 3 Feb 2017 15:17:21 -0500 Subject: Link with libphosphor_dbus Link with libphosphor_dbus. Update the manager implementation to match the new server binding in libphosphor_dbus (bool types for notify and notify signature change). Change-Id: I033d224965caf737591e363b3e2fd666605bff13 Signed-off-by: Brad Bishop --- Makefile.am | 4 +- configure.ac | 2 + manager.cpp | 4 +- manager.hpp | 5 +- test/test.cpp | 26 +++---- types.hpp | 3 +- xyz.openbmc_project.Inventory.Manager.cpp | 88 ------------------------ xyz/openbmc_project/Inventory/Manager/server.hpp | 79 --------------------- 8 files changed, 22 insertions(+), 189 deletions(-) delete mode 100644 xyz.openbmc_project.Inventory.Manager.cpp delete mode 100644 xyz/openbmc_project/Inventory/Manager/server.hpp diff --git a/Makefile.am b/Makefile.am index 1673362..b684c4a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,10 +13,10 @@ phosphor_inventory_LDFLAGS = $(SDBUSPLUS_LIBS) phosphor_inventory_CFLAGS = $(SDBUSPLUS_CFLAGS) libmanagercommon_la_SOURCES = \ - xyz.openbmc_project.Inventory.Manager.cpp \ events.cpp \ manager.cpp -libmanagercommon_la_LIBADD = $(SDBUSPLUS_LIBS) +libmanagercommon_la_LIBADD = $(SDBUSPLUS_LIBS) $(PHOSPHOR_DBUS_INTERFACES_LIBS) +libmanagercommon_la_CFLAGS = $(SDBUSPLUS_CFLAGS) $(PHOSPHOR_DBUS_INTERACES_CFLAGS) libmanager_la_SOURCES = \ extra_ifaces.cpp \ diff --git a/configure.ac b/configure.ac index e9b30fe..526770c 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,8 @@ AM_PATH_PYTHON([2.7], PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221]) PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, AC_MSG_ERROR(["Requires sdbusplus package."])) +PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],, + AC_MSG_ERROR(["Requires phosphor-dbus-interfaces package."])) # Checks for typedefs, structures, and compiler characteristics. AX_CXX_COMPILE_STDCXX_14([noext]) diff --git a/manager.cpp b/manager.cpp index 8026bf0..bb94c21 100644 --- a/manager.cpp +++ b/manager.cpp @@ -144,11 +144,11 @@ void Manager::run() noexcept } } -void Manager::notify(sdbusplus::message::object_path path, Object object) +void Manager::notify(std::map objs) { try { - createObjects({std::make_pair(path, object)}); + createObjects(objs); } catch (const std::exception& e) { diff --git a/manager.hpp b/manager.hpp index e6c08bf..8b59c1b 100644 --- a/manager.hpp +++ b/manager.hpp @@ -5,7 +5,7 @@ #include #include #include -#include "xyz/openbmc_project/Inventory/Manager/server.hpp" +#include #include "events.hpp" #include "actions.hpp" #include "types.hpp" @@ -92,7 +92,8 @@ class Manager final : void shutdown() noexcept; /** @brief sd_bus Notify method implementation callback. */ - void notify(sdbusplus::message::object_path, Object) override; + void notify( + std::map objs) override; /** @brief Event processing entry point. */ void handleEvent(sdbusplus::message::message&, diff --git a/test/test.cpp b/test/test.cpp index 6ffad51..0a941f7 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -26,6 +26,9 @@ using namespace std::literals::chrono_literals; using namespace std::literals::string_literals; +using Object = phosphor::inventory::manager::Object; +using ObjectMap = std::map; + constexpr auto MGR_SERVICE = "phosphor.inventory.test.mgr"; constexpr auto MGR_INTERFACE = IFACE; constexpr auto MGR_ROOT = "/testing/inventory"; @@ -94,7 +97,6 @@ struct ExampleService sdbusplus::server::manager::manager objmgr; }; -using Object = phosphor::inventory::manager::Object; /** @class SignalQueue * @brief Store DBus signals in a queue. @@ -201,11 +203,11 @@ void runTests() { { "xyz.openbmc_project.Example.Iface1", - {{"ExampleProperty1", "test1"}} + {{"ExampleProperty1", "test1"s}} }, { "xyz.openbmc_project.Example.Iface2", - {{"ExampleProperty2", "test2"}} + {{"ExampleProperty2", "test2"s}} }, }; @@ -236,8 +238,7 @@ void runTests() "path='" + root + "',member='InterfacesAdded'"); auto m = notify(); - m.append(relPath); - m.append(obj); + m.append(ObjectMap({{relPath, obj}})); b.call(m); auto sig{queue.pop()}; @@ -257,8 +258,7 @@ void runTests() // Create an object to be deleted. { auto m = notify(); - m.append(relDeleteMeThree); - m.append(obj); + m.append(ObjectMap({{relDeleteMeThree, obj}})); b.call(m); } @@ -330,20 +330,17 @@ void runTests() // Create some objects to be deleted by an action. { auto m = notify(); - m.append(relDeleteMeOne); - m.append(obj); + m.append(ObjectMap({{relDeleteMeOne, obj}})); b.call(m); } { auto m = notify(); - m.append(relDeleteMeTwo); - m.append(obj); + m.append(ObjectMap({{relDeleteMeTwo, obj}})); b.call(m); } { auto m = notify(); - m.append(relDeleteMeThree); - m.append(obj); + m.append(ObjectMap({{relDeleteMeThree, obj}})); b.call(m); } @@ -448,8 +445,7 @@ void runTests() // Create an object to be updated by the set property action. { auto m = notify(); - m.append(relChangeMe); - m.append(obj); + m.append(ObjectMap({{relChangeMe, obj}})); b.call(m); } diff --git a/types.hpp b/types.hpp index 3643bb1..ce43d11 100644 --- a/types.hpp +++ b/types.hpp @@ -12,7 +12,8 @@ namespace manager { /** @brief Inventory manager supported property types. */ -using InterfaceVariantType = sdbusplus::message::variant; +using InterfaceVariantType = + sdbusplus::message::variant; template using InterfaceType = std::map; diff --git a/xyz.openbmc_project.Inventory.Manager.cpp b/xyz.openbmc_project.Inventory.Manager.cpp deleted file mode 100644 index 787b65f..0000000 --- a/xyz.openbmc_project.Inventory.Manager.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include - - -namespace sdbusplus -{ -namespace xyz -{ -namespace openbmc_project -{ -namespace Inventory -{ -namespace server -{ - -Manager::Manager(bus::bus& bus, const char* path) - : _xyz_openbmc_project_Inventory_Manager_interface( - bus, path, _interface, _vtable, this) -{ -} - - -int Manager::_callback_Notify( - sd_bus_message* msg, void* context, sd_bus_error* error) -{ - using sdbusplus::server::binding::details::convertForMessage; - - try - { - auto m = message::message(msg); - - sdbusplus::message::object_path path{}; - std::map>> object{}; - - m.read(path, object); - - auto o = static_cast(context); - o->notify(path, object); - - auto reply = m.new_method_return(); - // No data to append on reply. - - reply.method_return(); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -namespace details -{ -namespace Manager -{ -static const auto _param_Notify = - utility::tuple_to_array(message::types::type_id< - sdbusplus::message::object_path, std::map>>>()); -static const auto _return_Notify = - utility::tuple_to_array(std::make_tuple('\0')); -} -} - - - - -const vtable::vtable_t Manager::_vtable[] = { - vtable::start(), - - vtable::method("Notify", - details::Manager::_param_Notify - .data(), - details::Manager::_return_Notify - .data(), - _callback_Notify), - vtable::end() -}; - -} // namespace server -} // namespace Inventory -} // namespace openbmc_project -} // namespace xyz -} // namespace sdbusplus - diff --git a/xyz/openbmc_project/Inventory/Manager/server.hpp b/xyz/openbmc_project/Inventory/Manager/server.hpp deleted file mode 100644 index 302bee5..0000000 --- a/xyz/openbmc_project/Inventory/Manager/server.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once -#include -#include -#include - -namespace sdbusplus -{ -namespace xyz -{ -namespace openbmc_project -{ -namespace Inventory -{ -namespace server -{ - -class Manager -{ - public: - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * - Move operations due to 'this' being registered as the - * 'context' with sdbus. - * Allowed: - * - Destructor. - */ - Manager() = delete; - Manager(const Manager&) = delete; - Manager& operator=(const Manager&) = delete; - Manager(Manager&&) = delete; - Manager& operator=(Manager&&) = delete; - virtual ~Manager() = default; - - /** @brief Constructor to put object onto bus at a dbus path. - * @param[in] bus - Bus to attach to. - * @param[in] path - Path to attach at. - */ - Manager(bus::bus& bus, const char* path); - - - - /** @brief Implementation for Notify - * Signal the implementing service that an item is ready to have its state managed. - * - * @param[in] path - The path of the item to be managed, relative to the inventory namespace root. - * @param[in] object - The fully enumerated item to be managed. - */ - virtual void notify( - sdbusplus::message::object_path path, - std::map>> object) = 0; - - - - - private: - - /** @brief sd-bus callback for Notify - */ - static int _callback_Notify( - sd_bus_message*, void*, sd_bus_error*); - - - static constexpr auto _interface = "xyz.openbmc_project.Inventory.Manager"; - static const vtable::vtable_t _vtable[]; - sdbusplus::server::interface::interface - _xyz_openbmc_project_Inventory_Manager_interface; - - -}; - - -} // namespace server -} // namespace Inventory -} // namespace openbmc_project -} // namespace xyz -} // namespace sdbusplus - -- cgit v1.2.1