diff options
author | 2019-01-04 16:05:10 +0100 | |
---|---|---|
committer | 2019-01-04 16:54:53 +0100 | |
commit | 4b0cfc57651134044d11c0803f7140616dc25dfe (patch) | |
tree | fc70fe3bb56c8c6105443384c6b3e8ff0ea8b631 /include | |
parent | 8506a0dc4974703982732da57f06d96e335195d2 (diff) |
Reworked the event class
Added move semantic and remove invalidation method as it's not used anymore
since we drop the support of APIv2.
Change-Id: I291155cef3e55ca14c706aa2315ab8dbfd09dffb
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'include')
-rw-r--r-- | include/afb/c++/binding-wrap.hpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/include/afb/c++/binding-wrap.hpp b/include/afb/c++/binding-wrap.hpp index c65c4c7f..403eeec2 100644 --- a/include/afb/c++/binding-wrap.hpp +++ b/include/afb/c++/binding-wrap.hpp @@ -91,10 +91,13 @@ class event { afb_event_t event_; public: - event() { invalidate(); } + event(); event(afb_event_t e); event(const event &other); + event(event &&other); + ~event(); event &operator=(const event &other); + event &operator=(event &&other); operator afb_event_t() const; afb_event_t operator->() const; @@ -102,8 +105,6 @@ public: operator bool() const; bool is_valid() const; - void invalidate(); - int broadcast(json_object *object) const; int push(json_object *object) const; @@ -234,9 +235,13 @@ public: /*************************************************************************/ /* events */ -inline event::event(afb_event_t e) : event_(e) { } -inline event::event(const event &other) : event_(other.event_) { } +inline event::event() : event_{nullptr} { } +inline event::event(afb_event_t e) : event_{e} { } +inline event::event(event &&other) : event_{other.event_} { other.event_ = nullptr; } +inline event::event(const event &other) : event_{other.event_} { addref(); } +inline event::~event() { unref(); } inline event &event::operator=(const event &other) { event_ = other.event_; return *this; } +inline event &event::operator=(event &&other) { event_ = other.event_; other.event_ = nullptr; return *this;} inline event::operator afb_event_t() const { return event_; } inline afb_event_t event::operator->() const { return event_; } @@ -244,12 +249,10 @@ inline afb_event_t event::operator->() const { return event_; } inline event::operator bool() const { return is_valid(); } inline bool event::is_valid() const { return afb_event_is_valid(event_); } -inline void event::invalidate() { event_ = nullptr; } - inline int event::broadcast(json_object *object) const { return afb_event_broadcast(event_, object); } inline int event::push(json_object *object) const { return afb_event_push(event_, object); } -inline void event::unref() { afb_event_unref(event_); invalidate(); } +inline void event::unref() { afb_event_unref(event_); event_ = nullptr; } inline void event::addref() { afb_event_addref(event_); } inline const char *event::name() const { return afb_event_name(event_); } |