diff options
author | John Wang <wangzqbj@inspur.com> | 2019-09-11 16:39:36 +0800 |
---|---|---|
committer | John Wang <wangzq.jn@gmail.com> | 2019-09-26 02:23:22 +0000 |
commit | 27d82814c3e79865221f599b98ce069c31c4d60a (patch) | |
tree | 42642fbe702e91b50ac6ad7c191ca5f92a4c3c2d | |
parent | 14dc04117c7dd88317d3b2ae851f6cb202221b69 (diff) | |
download | phosphor-logging-27d82814c3e79865221f599b98ce069c31c4d60a.tar.gz phosphor-logging-27d82814c3e79865221f599b98ce069c31c4d60a.zip |
Move to new association interface
A new association interface is defined in phosphor-dbus-interfaces
It would be nice to move the local version of the interface
to the new one.
The behavior of how association work is described here:
https://github.com/openbmc/docs/blob/master/object-mapper.md#associations
Partially resolves openbmc/openbmc#3584
Tested: Create a new log using the Create interface, see that
org.openbmc.Associations has been replaced by the xyz one and
2 association objects are created by the mapper.
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I9bcddd4765b12224967383bab2dbaa6d273e2790
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | elog_entry.hpp | 6 | ||||
-rw-r--r-- | org.openbmc.Associations.cpp | 160 | ||||
-rw-r--r-- | org/openbmc/Associations.interface.yaml | 13 | ||||
-rw-r--r-- | org/openbmc/Associations/server.hpp | 97 | ||||
-rw-r--r-- | test/Makefile.am | 2 |
7 files changed, 5 insertions, 278 deletions
diff --git a/Makefile.am b/Makefile.am index e731c30..961aecf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,7 +36,6 @@ phosphor_log_manager_SOURCES = \ log_manager_main.cpp \ elog-lookup.cpp \ elog_entry.cpp \ - org.openbmc.Associations.cpp \ elog-process-metadata.cpp \ elog_meta.cpp \ elog_serialize.cpp \ @@ -85,7 +85,7 @@ where X starts at 1 and is incremented for each new log. The interfaces are: * [xyz.openbmc_project.Logging.Entry] * The main event log interface. -* [org.openbmc.Associations] +* [xyz.openbmc_project.Association.Definitions] * Used for specifying inventory items as the cause of the event. * For more information on associations, see [here][associations-doc]. * [xyz.openbmc_project.Object.Delete] @@ -226,7 +226,7 @@ that uses them. To do that, one must: **TODO** [xyz.openbmc_project.Logging.Entry]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Logging/Entry.interface.yaml -[org.openbmc.Associations]: https://github.com/openbmc/phosphor-logging/blob/master/org/openbmc/Associations.interface.yaml +[xyz.openbmc_project.Association.Definitions]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Association/Definitions.interface.yaml [associations-doc]: https://github.com/openbmc/docs/blob/master/object-mapper.md#associations [callout-doc]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Common/Callout/README.md [xyz.openbmc_project.Object.Delete]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Object/Delete.interface.yaml diff --git a/elog_entry.hpp b/elog_entry.hpp index abcfe50..9c93afe 100644 --- a/elog_entry.hpp +++ b/elog_entry.hpp @@ -1,12 +1,12 @@ #pragma once -#include "org/openbmc/Associations/server.hpp" #include "xyz/openbmc_project/Logging/Entry/server.hpp" #include "xyz/openbmc_project/Object/Delete/server.hpp" #include "xyz/openbmc_project/Software/Version/server.hpp" #include <sdbusplus/bus.hpp> #include <sdbusplus/server/object.hpp> +#include <xyz/openbmc_project/Association/Definitions/server.hpp> namespace phosphor { @@ -16,7 +16,7 @@ namespace logging using EntryIfaces = sdbusplus::server::object::object< sdbusplus::xyz::openbmc_project::Logging::server::Entry, sdbusplus::xyz::openbmc_project::Object::server::Delete, - sdbusplus::org::openbmc::server::Associations, + sdbusplus::xyz::openbmc_project::Association::server::Definitions, sdbusplus::xyz::openbmc_project::Software::server::Version>; using AssociationList = @@ -31,7 +31,7 @@ class Manager; * @brief OpenBMC logging entry implementation. * @details A concrete implementation for the * xyz.openbmc_project.Logging.Entry and - * org.openbmc.Associations DBus APIs. + * xyz.openbmc_project.Associations.Definitions DBus APIs. */ class Entry : public EntryIfaces { diff --git a/org.openbmc.Associations.cpp b/org.openbmc.Associations.cpp deleted file mode 100644 index 25d79fd..0000000 --- a/org.openbmc.Associations.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include <algorithm> -#include <org/openbmc/Associations/server.hpp> -#include <sdbusplus/exception.hpp> -#include <sdbusplus/server.hpp> - -namespace sdbusplus -{ -namespace org -{ -namespace openbmc -{ -namespace server -{ - -Associations::Associations(bus::bus& bus, const char* path) : - _org_openbmc_Associations_interface(bus, path, _interface, _vtable, this) -{ -} - -Associations::Associations( - bus::bus& bus, const char* path, - const std::map<std::string, PropertiesVariant>& vals) : - Associations(bus, path) -{ - for (const auto& v : vals) - { - setPropertyByName(v.first, v.second); - } -} - -auto Associations::associations() const - -> std::vector<std::tuple<std::string, std::string, std::string>> -{ - return _associations; -} - -int Associations::_callback_get_associations(sd_bus* bus, const char* path, - const char* interface, - const char* property, - sd_bus_message* reply, - void* context, sd_bus_error* error) -{ - using sdbusplus::server::binding::details::convertForMessage; - - try - { - auto m = message::message(reply); -#ifndef DISABLE_TRANSACTION - { - auto tbus = m.get_bus(); - sdbusplus::server::transaction::Transaction t(tbus, m); - sdbusplus::server::transaction::set_id( - std::hash<sdbusplus::server::transaction::Transaction>{}(t)); - } -#endif - - auto o = static_cast<Associations*>(context); - m.append(convertForMessage(o->associations())); - } - catch (sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -auto Associations::associations( - std::vector<std::tuple<std::string, std::string, std::string>> value) - -> std::vector<std::tuple<std::string, std::string, std::string>> -{ - if (_associations != value) - { - _associations = value; - _org_openbmc_Associations_interface.property_changed("associations"); - } - - return _associations; -} - -int Associations::_callback_set_associations(sd_bus* bus, const char* path, - const char* interface, - const char* property, - sd_bus_message* value, - void* context, sd_bus_error* error) -{ - try - { - auto m = message::message(value); -#ifndef DISABLE_TRANSACTION - { - auto tbus = m.get_bus(); - sdbusplus::server::transaction::Transaction t(tbus, m); - sdbusplus::server::transaction::set_id( - std::hash<sdbusplus::server::transaction::Transaction>{}(t)); - } -#endif - - auto o = static_cast<Associations*>(context); - - std::vector<std::tuple<std::string, std::string, std::string>> v{}; - m.read(v); - o->associations(v); - } - catch (sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -namespace details -{ -namespace Associations -{ -static const auto _property_associations = utility::tuple_to_array( - message::types::type_id< - std::vector<std::tuple<std::string, std::string, std::string>>>()); -} -} // namespace details - -void Associations::setPropertyByName(const std::string& name, - const PropertiesVariant& val) -{ - if (name == "associations") - { - auto& v = message::variant_ns::get< - std::vector<std::tuple<std::string, std::string, std::string>>>( - val); - associations(v); - return; - } -} - -auto Associations::getPropertyByName(const std::string& name) - -> PropertiesVariant -{ - if (name == "associations") - { - return associations(); - } - - return PropertiesVariant(); -} - -const vtable::vtable_t Associations::_vtable[] = { - vtable::start(), - vtable::property("associations", - details::Associations::_property_associations.data(), - _callback_get_associations, _callback_set_associations, - vtable::property_::emits_change), - vtable::end()}; - -} // namespace server -} // namespace openbmc -} // namespace org -} // namespace sdbusplus diff --git a/org/openbmc/Associations.interface.yaml b/org/openbmc/Associations.interface.yaml deleted file mode 100644 index 9be60ce..0000000 --- a/org/openbmc/Associations.interface.yaml +++ /dev/null @@ -1,13 +0,0 @@ -description: > - Implement to delegate org.openbmc.Association interface management - responsibilities to another application. -properties: - - name: associations - type: array[struct[string,string,string]] - description: > - An array of forward, reverse, endpoint tuples where: - forward - The type of the association. - reverse - The type of the association to create for the endpoint. - endpoint - The association endpoint. - -# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/org/openbmc/Associations/server.hpp b/org/openbmc/Associations/server.hpp deleted file mode 100644 index fb3ff7e..0000000 --- a/org/openbmc/Associations/server.hpp +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once -#include <systemd/sd-bus.h> - -#include <sdbusplus/server.hpp> -#include <tuple> - -namespace sdbusplus -{ -namespace org -{ -namespace openbmc -{ -namespace server -{ - -class Associations -{ - 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. - */ - Associations() = delete; - Associations(const Associations&) = delete; - Associations& operator=(const Associations&) = delete; - Associations(Associations&&) = delete; - Associations& operator=(Associations&&) = delete; - virtual ~Associations() = 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. - */ - Associations(bus::bus& bus, const char* path); - - using PropertiesVariant = sdbusplus::message::variant< - std::vector<std::tuple<std::string, std::string, std::string>>>; - - /** @brief Constructor to initialize the object from a map of - * properties. - * - * @param[in] bus - Bus to attach to. - * @param[in] path - Path to attach at. - * @param[in] vals - Map of property name to value for initialization. - */ - Associations(bus::bus& bus, const char* path, - const std::map<std::string, PropertiesVariant>& vals); - - /** Get value of associations */ - virtual std::vector<std::tuple<std::string, std::string, std::string>> - associations() const; - /** Set value of associations */ - virtual std::vector<std::tuple<std::string, std::string, std::string>> - associations( - std::vector<std::tuple<std::string, std::string, std::string>> - value); - - /** @brief Sets a property by name. - * @param[in] name - A string representation of the property name. - * @param[in] val - A variant containing the value to set. - */ - void setPropertyByName(const std::string& name, - const PropertiesVariant& val); - - /** @brief Gets a property by name. - * @param[in] name - A string representation of the property name. - * @return - A variant containing the value of the property. - */ - PropertiesVariant getPropertyByName(const std::string& name); - - private: - /** @brief sd-bus callback for get-property 'associations' */ - static int _callback_get_associations(sd_bus*, const char*, const char*, - const char*, sd_bus_message*, void*, - sd_bus_error*); - /** @brief sd-bus callback for set-property 'associations' */ - static int _callback_set_associations(sd_bus*, const char*, const char*, - const char*, sd_bus_message*, void*, - sd_bus_error*); - - static constexpr auto _interface = "org.openbmc.Associations"; - static const vtable::vtable_t _vtable[]; - sdbusplus::server::interface::interface _org_openbmc_Associations_interface; - - std::vector<std::tuple<std::string, std::string, std::string>> - _associations{}; -}; - -} // namespace server -} // namespace openbmc -} // namespace org -} // namespace sdbusplus diff --git a/test/Makefile.am b/test/Makefile.am index 6499764..64aa6d8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -34,7 +34,6 @@ test_ldadd = \ $(top_builddir)/elog_serialize.o \ $(top_builddir)/elog_entry.o \ $(top_builddir)/log_manager.o \ - $(top_builddir)/org.openbmc.Associations.o \ $(top_builddir)/xyz/openbmc_project/Logging/Internal/Manager/server.o \ $(top_builddir)/elog_meta.o \ $(top_builddir)/elog-lookup.o \ @@ -104,7 +103,6 @@ extensions_test_LDADD = \ $(top_builddir)/elog-process-metadata.o \ $(top_builddir)/elog_serialize.o \ $(top_builddir)/log_manager.o \ - $(top_builddir)/org.openbmc.Associations.o \ $(top_builddir)/xyz/openbmc_project/Logging/Internal/Manager/server.o extensions_test_LDFLAGS = $(test_ldflags) |