From: Daniel Elstner Date: Fri, 9 Oct 2015 17:24:51 +0000 (+0200) Subject: C++: Add bindings for session stop notification X-Git-Tag: libsigrok-0.4.0~216 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f91cf612dfde284c8a146417644fbfba05cca1a2;p=libsigrok.git C++: Add bindings for session stop notification --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index a944faa2..f40a6dc5 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -1025,6 +1025,31 @@ void Session::stop() check(sr_session_stop(_structure)); } +bool Session::is_running() const +{ + const int ret = sr_session_is_running(_structure); + if (ret < 0) + throw Error{ret}; + return (ret != 0); +} + +static void session_stopped_callback(void *data) +{ + auto *const callback = static_cast(data); + (*callback)(); +} + +void Session::set_stopped_callback(SessionStoppedCallback callback) +{ + _stopped_callback = move(callback); + if (_stopped_callback) + check(sr_session_stopped_callback_set(_structure, + &session_stopped_callback, &_stopped_callback)); + else + check(sr_session_stopped_callback_set(_structure, + nullptr, nullptr)); +} + static void datafeed_callback(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *pkt, void *cb_data) { diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index efcd63a7..2441c2c3 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -589,6 +589,9 @@ protected: friend class TriggerStage; }; +/** Type of session stopped callback */ +typedef function SessionStoppedCallback; + /** Type of datafeed callback */ typedef function, shared_ptr)> DatafeedCallbackFunction; @@ -719,6 +722,10 @@ public: void run(); /** Stop the session. */ void stop(); + /** Return whether the session is running. */ + bool is_running() const; + /** Set callback to be invoked on session stop. */ + void set_stopped_callback(SessionStoppedCallback callback); /** Get current trigger setting. */ shared_ptr trigger(); /** Get the context. */ @@ -737,6 +744,7 @@ protected: map _owned_devices; map > _other_devices; vector _datafeed_callbacks; + SessionStoppedCallback _stopped_callback; map, SourceCallbackData *> _source_callbacks; string _filename; shared_ptr _trigger;