diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2016-10-17 14:07:51 -0500 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2016-10-20 16:17:34 -0500 |
| commit | 0f9ed695a7a1f6d84b0ec542178f63cd5f3a1e98 (patch) | |
| tree | a7ece4b184c6185af0b7964ec4a92c3314abc6ff | |
| parent | affeafada185ed1a1498d0d08d9a2baa4c69141c (diff) | |
| download | sdbusplus-0f9ed695a7a1f6d84b0ec542178f63cd5f3a1e98.tar.gz sdbusplus-0f9ed695a7a1f6d84b0ec542178f63cd5f3a1e98.zip | |
slot: add binding class for sd_bus_slot
Change-Id: Ib092ec3fd22be1d2a9755457235aba81acb606a1
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
| -rw-r--r-- | sdbusplus/slot.hpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/sdbusplus/slot.hpp b/sdbusplus/slot.hpp new file mode 100644 index 0000000..039f520 --- /dev/null +++ b/sdbusplus/slot.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include <memory> +#include <systemd/sd-bus.h> + +namespace sdbusplus +{ + +namespace slot +{ + +using slotp_t = sd_bus_slot*; +class slot; + +namespace details +{ + +/** @brief unique_ptr functor to release a slot reference. */ +struct SlotDeleter +{ + void operator()(slotp_t ptr) const + { + sd_bus_slot_unref(ptr); + } +}; + +using slot = std::unique_ptr<sd_bus_slot, SlotDeleter>; + +} // namespace details + +/** @class slot + * @brief Provides C++ holder for sd_bus_slot instances. + */ +struct slot +{ + /* Define all of the basic class operations: + * Not allowed: + * - Default constructor to avoid nullptrs. + * - Copy operations due to internal unique_ptr. + * Allowed: + * - Move operations. + * - Destructor. + */ + slot() = delete; + slot(const slot&) = delete; + slot& operator=(const slot&) = delete; + slot(slot&&) = default; + slot& operator=(slot&&) = default; + ~slot() = default; + + /** @brief Conversion constructor for 'slotp_t'. + * + * Takes ownership of the slot-pointer and releases it when done. + */ + explicit slot(slotp_t s) : _slot(s) {} + + /** @brief Release ownership of the stored slot-pointer. */ + slotp_t release() { return _slot.release(); } + + /** @brief Check if slot contains a real pointer. (non-nullptr). */ + explicit operator bool() const { return bool(_slot); } + + private: + details::slot _slot; + +}; + +} // namespace slot +} // namespace sdbusplus |

