]> sigrok.org Git - libsigrokflow.git/commitdiff
WIP on plugin registration.
authorMartin Ling <redacted>
Sun, 30 Dec 2018 01:01:43 +0000 (02:01 +0100)
committerUwe Hermann <redacted>
Tue, 8 Jan 2019 18:41:58 +0000 (19:41 +0100)
include/libsigrokflow/libsigrokflow.hpp
src/main.cpp

index 4f0fcdb78392b1432b43754ff6ea9d13827f2c03..2c13cb4be875b77e6d1ef78624c258143589d3c2 100644 (file)
@@ -39,18 +39,24 @@ class GstBlock :
         public Gst::Element
 {
         /* Operations specific to sigrok GStreamer blocks go here. */
+protected:
+        explicit GstBlock(GstElement *gobj);
 };
 
 class Device :
         public GstBlock
 {
         /* Operations specific to hardware devices go here */
+protected:
+        explicit Device(GstElement *gobj);
 };
 
 class CaptureDevice :
         public Device
 {
         /* Operations specific to capture (source) devices go here */
+protected:
+        explicit CaptureDevice(GstElement *gobj);
 };
 
 class LegacyCaptureDevice :
@@ -66,6 +72,15 @@ public:
 
         /* Override state change */
         Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
+
+        /* Gst class init */
+        static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
+
+        /* Register class with plugin */
+        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+        /* Construcor used by element factory */
+        explicit LegacyCaptureDevice(GstElement *gobj);
 private:
         shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
         Glib::RefPtr<Gst::Pad> _src_pad;
index ead3446fc8cc9a49353131bfd97f5216f26e8206..c611157a46cfbbb97fa4943ca29b1761cd70dc88 100644 (file)
@@ -30,6 +30,39 @@ using namespace std::placeholders;
 
 void init()
 {
+       Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
+                       "sigrok_legacy_capture_device",
+                       "Wrapper for capture devices using legacy libsigrok APIs",
+                       sigc::ptr_fun(&LegacyCaptureDevice::register_element),
+                       "0.01", "GPLv3+", "sigrok", "libsigrokflow", "http://sigrok.org");
+}
+
+void LegacyCaptureDevice::class_init(Gst::ElementClass<LegacyCaptureDevice> *klass)
+{
+       klass->set_metadata("sigrok legacy capture device",
+                       "Source", "Wrapper for capture devices using legacy libsigrok APIs",
+                       "Martin Ling");
+
+       klass->add_pad_template(Gst::PadTemplate::create(
+                       "src",
+                       Gst::PAD_SRC,
+                       Gst::PAD_ALWAYS,
+                       Gst::Caps::create_any()));
+}
+
+bool LegacyCaptureDevice::register_element(Glib::RefPtr<Gst::Plugin> plugin)
+{
+       Gst::ElementFactory::register_element(plugin, "sigrok_legacy_capture_device",
+                       0, Gst::register_mm_type<LegacyCaptureDevice>(
+                               "sigrok_legacy_capture_device"));
+       return true;
+}
+
+LegacyCaptureDevice::LegacyCaptureDevice(GstElement *gobj) :
+       Glib::ObjectBase(typeid(LegacyCaptureDevice)),
+       CaptureDevice(gobj)
+{
+       add_pad(_src_pad = Gst::Pad::create(get_pad_template("src"), "src"));
 }
 
 Glib::RefPtr<LegacyCaptureDevice>LegacyCaptureDevice::create(
@@ -39,13 +72,6 @@ Glib::RefPtr<LegacyCaptureDevice>LegacyCaptureDevice::create(
        if (!element)
                throw runtime_error("Failed to create element - plugin not registered?");
        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;
 }