]> sigrok.org Git - libsigrok.git/commitdiff
C++: Add bindings for session stop notification
authorDaniel Elstner <redacted>
Fri, 9 Oct 2015 17:24:51 +0000 (19:24 +0200)
committerDaniel Elstner <redacted>
Sat, 17 Oct 2015 15:40:42 +0000 (17:40 +0200)
bindings/cxx/classes.cpp
bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp

index a944faa21b879aaa191ddf7acf4e224e27c2a195..f40a6dc571d27aebf124427cf62cf6763096aea4 100644 (file)
@@ -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<SessionStoppedCallback*>(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)
 {
index efcd63a7f7de3bd6e759364a1f7d96d99ceb1bd8..2441c2c37b9933f3f602498bf422d79f0938645c 100644 (file)
@@ -589,6 +589,9 @@ protected:
        friend class TriggerStage;
 };
 
+/** Type of session stopped callback */
+typedef function<void()> SessionStoppedCallback;
+
 /** Type of datafeed callback */
 typedef function<void(shared_ptr<Device>, shared_ptr<Packet>)>
        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> trigger();
        /** Get the context. */
@@ -737,6 +744,7 @@ protected:
        map<const struct sr_dev_inst *, SessionDevice *> _owned_devices;
        map<const struct sr_dev_inst *, shared_ptr<Device> > _other_devices;
        vector<DatafeedCallbackData *> _datafeed_callbacks;
+       SessionStoppedCallback _stopped_callback;
        map<shared_ptr<EventSource>, SourceCallbackData *> _source_callbacks;
        string _filename;
        shared_ptr<Trigger> _trigger;