From e57c38e9dd64e0a5bc12bac5b6d3199c7baa9595 Mon Sep 17 00:00:00 2001 From: Lei YU Date: Fri, 20 Sep 2019 17:38:17 +0800 Subject: Emit adding/removing interfaces for object server The object server currently either creats the objects and interfaces, or defer the signal by not adding objects. In practice, we have situations that the code would like to add interfaces to an existing object, and it's not supported, or needs tricky code to workaround. Exmaples: https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-bmc-code-mgmt/+/5820 https://gerrit.openbmc-project.xyz/c/openbmc/openpower-pnor-code-mgmt/+/5346 This commit adds the support by: 1. Adding emit_added() in interface.hpp and the generated server.hpp 2. Adding a enum class in object's constructor to indicate which action to do, to create the object, or adding the interface, or defer signal as before. So the user of object<> could pass `action::emit_interface_added` to the constructor to tell the object server *only* emit interface added to DBus, without emitting object added. The previous code stays the same behavior: * If `true` is passed in object's constructor, it defers emitting object added signal; * If no extra parameter is passed in object's constructor, it emits object added signal as before. Tested: 1. Make sure the openbmc builds fine with https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-logging/+/25089 because phosphor-logging uses its own server.hpp for interface, the above patch removes that. 2. Manually write a small service to verify the interfaces are added and removed by using the `emit_interface_added` action. 3. Added the unit test cases for object.hpp to check the ctor/dtor with different actions. Signed-off-by: Lei YU Change-Id: I178c5bed3c9ff39ee2ac8d143fbe9131b0753dfa --- tools/sdbusplus/templates/interface.mako.server.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tools') diff --git a/tools/sdbusplus/templates/interface.mako.server.hpp b/tools/sdbusplus/templates/interface.mako.server.hpp index 99ba769..1825d6b 100644 --- a/tools/sdbusplus/templates/interface.mako.server.hpp +++ b/tools/sdbusplus/templates/interface.mako.server.hpp @@ -121,6 +121,18 @@ ${p.camelCase}(${p.cppTypeParam(interface.name)} value); static ${e.name} convert${e.name}FromString(const std::string& s); % endfor + /** @brief Emit interface added */ + void emit_added() + { + _${"_".join(interface.name.split('.'))}_interface.emit_added(); + } + + /** @brief Emit interface removed */ + void emit_removed() + { + _${"_".join(interface.name.split('.'))}_interface.emit_removed(); + } + static constexpr auto interface = "${interface.name}"; private: -- cgit v1.2.3