diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2016-10-18 15:33:25 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2016-10-20 16:40:18 -0500 |
commit | 5354c82a648c5937b8306284dad49be1b67ae75d (patch) | |
tree | 00592455506c13add73b1776705e10b421c77bb3 | |
parent | 0e9ad0d6dcbcd89e099672935d524c345362f7ce (diff) | |
download | sdbusplus-5354c82a648c5937b8306284dad49be1b67ae75d.tar.gz sdbusplus-5354c82a648c5937b8306284dad49be1b67ae75d.zip |
object: allow deferred creation signal
Change-Id: I4da3e502c667fbcd3c46749f8e0d61744beee055
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
-rw-r--r-- | sdbusplus/server/object.hpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/sdbusplus/server/object.hpp b/sdbusplus/server/object.hpp index 421dc53..7da6f35 100644 --- a/sdbusplus/server/object.hpp +++ b/sdbusplus/server/object.hpp @@ -80,15 +80,23 @@ struct object : details::compose<Args...> * * @param[in] bus - The bus to place the object on. * @param[in] path - The path the object resides at. + * @param[in] deferSignal - Set to true if emit_object_added should be + * deferred. This would likely be true if the + * object needs custom property init before the + * signal can be sent. */ object(bus::bus& bus, - const char* path) + const char* path, + bool deferSignal = false) : details::compose<Args...>(bus, path), __sdbusplus_server_object_bus(sd_bus_ref(bus.get())), - __sdbusplus_server_object_path(path) + __sdbusplus_server_object_path(path), + __sdbusplus_server_object_emitremoved(false) { - sd_bus_emit_object_added(__sdbusplus_server_object_bus.get(), - __sdbusplus_server_object_path.c_str()); + if (!deferSignal) + { + emit_object_added(); + } } ~object() @@ -97,6 +105,17 @@ struct object : details::compose<Args...> __sdbusplus_server_object_path.c_str()); } + /** Emit the 'object-added' signal, if not already sent. */ + void emit_object_added() + { + if (!__sdbusplus_server_object_emitremoved) + { + sd_bus_emit_object_added(__sdbusplus_server_object_bus.get(), + __sdbusplus_server_object_path.c_str()); + __sdbusplus_server_object_emitremoved = true; + } + } + private: // These member names are purposefully chosen as long and, hopefully, // unique. Since an object is 'composed' via multiple-inheritence, @@ -104,6 +123,7 @@ struct object : details::compose<Args...> // ambiguity. bus::bus __sdbusplus_server_object_bus; std::string __sdbusplus_server_object_path; + bool __sdbusplus_server_object_emitremoved; }; |