From: Martin Ling Date: Sun, 30 Dec 2018 01:01:43 +0000 (+0100) Subject: WIP on plugin registration. X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=6d71d36a6150cc76ac2408a7a41dcd473328e4fa;hp=d75c9a6aab73eec3921cb951c3253afc4269ccb3;p=libsigrokflow.git WIP on plugin registration. --- diff --git a/include/libsigrokflow/libsigrokflow.hpp b/include/libsigrokflow/libsigrokflow.hpp index 4f0fcdb..2c13cb4 100644 --- a/include/libsigrokflow/libsigrokflow.hpp +++ b/include/libsigrokflow/libsigrokflow.hpp @@ -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 *klass); + + /* Register class with plugin */ + static bool register_element(Glib::RefPtr plugin); + + /* Construcor used by element factory */ + explicit LegacyCaptureDevice(GstElement *gobj); private: shared_ptr _libsigrok_device; Glib::RefPtr _src_pad; diff --git a/src/main.cpp b/src/main.cpp index ead3446..c611157 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 *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 plugin) +{ + Gst::ElementFactory::register_element(plugin, "sigrok_legacy_capture_device", + 0, Gst::register_mm_type( + "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::RefPtrLegacyCaptureDevice::create( @@ -39,13 +72,6 @@ Glib::RefPtrLegacyCaptureDevice::create( if (!element) throw runtime_error("Failed to create element - plugin not registered?"); auto device = Glib::RefPtr::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; }