]> sigrok.org Git - libsigrokflow.git/commitdiff
Revised implementation without using constructor.
authorMartin Ling <redacted>
Sun, 30 Dec 2018 00:17:36 +0000 (01:17 +0100)
committerUwe Hermann <redacted>
Tue, 8 Jan 2019 15:04:19 +0000 (16:04 +0100)
include/libsigrokflow/libsigrokflow.hpp
src/main.cpp

index e800be0d45cc38248fc55fd8a0ae92d3195b096a..4f0fcdb78392b1432b43754ff6ea9d13827f2c03 100644 (file)
@@ -51,16 +51,15 @@ class CaptureDevice :
         public Device
 {
         /* Operations specific to capture (source) devices go here */
-protected :
-        CaptureDevice();
 };
 
 class LegacyCaptureDevice :
         public CaptureDevice
 {
 public:
-        /* Construct from libsigrok device object */
-        LegacyCaptureDevice(shared_ptr<sigrok::HardwareDevice>);
+        /* Create from libsigrok device object */
+        static Glib::RefPtr<LegacyCaptureDevice> create(
+                shared_ptr<sigrok::HardwareDevice> libsigrok_device);
 
         /* Retrieve libsigrok device object */
         shared_ptr<sigrok::HardwareDevice> libsigrok_device();
@@ -68,7 +67,7 @@ public:
         /* Override state change */
         Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
 private:
-        shared_ptr<sigrok::HardwareDevice> _device;
+        shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
         Glib::RefPtr<Gst::Pad> _src_pad;
         Glib::Threads::RecMutex _mutex;
         Glib::RefPtr<Gst::Task> _task;
index d6bfe50e71196f7a482184f8d3e80f19a9d4f6e6..19d1f35eb733bd27d49e78f424fbaf3639cbb8ab 100644 (file)
@@ -32,20 +32,25 @@ void init()
 {
 }
 
-auto src_template = Gst::PadTemplate::create("src",
-               Gst::PAD_SRC,
-               Gst::PAD_ALWAYS,
-               Gst::Caps::create_any());
-
-LegacyCaptureDevice::LegacyCaptureDevice(shared_ptr<sigrok::HardwareDevice> device) :
-       _device(device), _src_pad(Gst::Pad::create(src_template))
+Glib::RefPtr<LegacyCaptureDevice>LegacyCaptureDevice::create(
+       shared_ptr<sigrok::HardwareDevice> libsigrok_device)
 {
-       add_pad(_src_pad);
+       auto element = Gst::ElementFactory::create_element("sigrok_legacy_capture_device");
+       auto device = Glib::RefPtr<LegacyCaptureDevice>::cast_static(element);
+
+       auto src_template = Gst::PadTemplate::create("src",
+                       Gst::PAD_SRC,
+                       Gst::PAD_ALWAYS,
+                       Gst::Caps::create_any());
+       device->_src_pad = Gst::Pad::create(src_template);
+       device->add_pad(device->_src_pad);
+       device->_libsigrok_device = libsigrok_device;
+       return device;
 }
 
 shared_ptr<sigrok::HardwareDevice> LegacyCaptureDevice::libsigrok_device()
 {
-       return _device;
+       return _libsigrok_device;
 }
 
 Gst::StateChangeReturn LegacyCaptureDevice::change_state_vfunc(Gst::StateChange transition)
@@ -55,8 +60,8 @@ Gst::StateChangeReturn LegacyCaptureDevice::change_state_vfunc(Gst::StateChange
                case Gst::STATE_CHANGE_READY_TO_PAUSED:
                        return Gst::StateChangeReturn::STATE_CHANGE_NO_PREROLL;
                case Gst::STATE_CHANGE_PAUSED_TO_PLAYING:
-                       _device->open();
-                       _device->config_set(sigrok::ConfigKey::LIMIT_SAMPLES,
+                       _libsigrok_device->open();
+                       _libsigrok_device->config_set(sigrok::ConfigKey::LIMIT_SAMPLES,
                                        Glib::Variant<int>::create(10));
                        _task = Gst::Task::create(std::bind(&LegacyCaptureDevice::_run, this));
                        _task->set_lock(_mutex);
@@ -99,8 +104,8 @@ void LegacyCaptureDevice::_datafeed_callback(
 
 void LegacyCaptureDevice::_run()
 {
-       _session = _device->driver()->parent()->create_session();
-       _session->add_device(_device);
+       _session = _libsigrok_device->driver()->parent()->create_session();
+       _session->add_device(_libsigrok_device);
        _session->add_datafeed_callback(bind(&LegacyCaptureDevice::_datafeed_callback, this, _1, _2));
        _session->start();
        _session->run();