]> sigrok.org Git - libsigrokflow.git/commitdiff
Factor out src/legacy_decoder.cpp.
authorUwe Hermann <redacted>
Wed, 9 Jan 2019 01:32:53 +0000 (02:32 +0100)
committerUwe Hermann <redacted>
Wed, 9 Jan 2019 01:39:16 +0000 (02:39 +0100)
Makefile.am
src/legacy_decoder.cpp [new file with mode: 0644]
src/main.cpp

index 7fe4fc4fb7ebfb771bd71ee4d6bb5b0435e97f0c..c39366dbe08b7b86b1233c8ad4d8057a3b266cb6 100644 (file)
@@ -32,7 +32,8 @@ libsigrokflow_la_SOURCES = \
        src/init.cpp \
        src/legacy_capture_device.cpp \
        src/legacy_input.cpp \
-       src/legacy_output.cpp
+       src/legacy_output.cpp \
+       src/legacy_decoder.cpp
 
 libsigrokflow_la_LIBADD = $(LIBSIGROKFLOW_LIBS)
 libsigrokflow_la_LDFLAGS = -version-info $(SRF_LIB_VERSION) -no-undefined
diff --git a/src/legacy_decoder.cpp b/src/legacy_decoder.cpp
new file mode 100644 (file)
index 0000000..82d6f8b
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * This file is part of the libsigrokflow project.
+ *
+ * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
+ * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <libsigrokflow/libsigrokflow.hpp>
+
+namespace Srf
+{
+
+using namespace std;
+
+#ifdef HAVE_LIBSIGROKDECODE
+void LegacyDecoder::class_init(Gst::ElementClass<LegacyDecoder> *klass)
+{
+       klass->set_metadata("sigrok legacy decoder",
+                       "Sink", "Wrapper for protocol decoders using legacy libsigrokdecode APIs",
+                       "Uwe Hermann");
+
+       klass->add_pad_template(Gst::PadTemplate::create(
+                       "sink",
+                       Gst::PAD_SINK,
+                       Gst::PAD_ALWAYS,
+                       Gst::Caps::create_any()));
+}
+
+bool LegacyDecoder::register_element(Glib::RefPtr<Gst::Plugin> plugin)
+{
+       Gst::ElementFactory::register_element(plugin, "sigrok_legacy_decoder",
+                       0, Gst::register_mm_type<LegacyDecoder>(
+                               "sigrok_legacy_decoder"));
+
+       return true;
+}
+
+LegacyDecoder::LegacyDecoder(GstBaseSink *gobj) :
+       Glib::ObjectBase(typeid(LegacyDecoder)),
+       Sink(gobj)
+{
+}
+
+Glib::RefPtr<LegacyDecoder>LegacyDecoder::create(
+       struct srd_session *libsigrokdecode_session, uint64_t unitsize)
+{
+       auto element = Gst::ElementFactory::create_element("sigrok_legacy_decoder");
+       if (!element)
+               throw runtime_error("Failed to create element - plugin not registered?");
+       auto decoder = Glib::RefPtr<LegacyDecoder>::cast_static(element);
+       decoder->session_ = libsigrokdecode_session;
+       decoder->unitsite_ = unitsize;
+
+       return decoder;
+}
+
+struct srd_session *LegacyDecoder::libsigrokdecode_session()
+{
+       return session_;
+}
+
+Gst::FlowReturn LegacyDecoder::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer)
+{
+       Gst::MapInfo info;
+       buffer->map(info, Gst::MAP_READ);
+       uint64_t num_samples = info.get_size() / unitsite_;
+       srd_session_send(session_, abs_ss_, abs_ss_ + num_samples,
+               info.get_data(), info.get_size(), unitsite_);
+       abs_ss_ += num_samples;
+       buffer->unmap(info);
+
+       return Gst::FLOW_OK;
+}
+
+bool LegacyDecoder::start_vfunc()
+{
+       abs_ss_ = 0;
+       srd_session_start(session_);
+
+       return true;
+}
+
+bool LegacyDecoder::stop_vfunc()
+{
+       srd_session_terminate_reset(session_);
+
+       return true;
+}
+#endif
+
+}
index 208af495baec09ba4ea1548821b7be5e7211d286..6ade4978fa3f7d1e636d4170477190be6e46df5b 100644 (file)
@@ -24,8 +24,6 @@
 namespace Srf
 {
 
-using namespace std;
-
 Sink::Sink(GstBaseSink *gobj) :
        Gst::BaseSink(gobj)
 {
@@ -41,80 +39,4 @@ CaptureDevice::CaptureDevice(GstElement *gobj) :
 {
 }
 
-#ifdef HAVE_LIBSIGROKDECODE
-void LegacyDecoder::class_init(Gst::ElementClass<LegacyDecoder> *klass)
-{
-       klass->set_metadata("sigrok legacy decoder",
-                       "Sink", "Wrapper for protocol decoders using legacy libsigrokdecode APIs",
-                       "Uwe Hermann");
-
-       klass->add_pad_template(Gst::PadTemplate::create(
-                       "sink",
-                       Gst::PAD_SINK,
-                       Gst::PAD_ALWAYS,
-                       Gst::Caps::create_any()));
-}
-
-bool LegacyDecoder::register_element(Glib::RefPtr<Gst::Plugin> plugin)
-{
-       Gst::ElementFactory::register_element(plugin, "sigrok_legacy_decoder",
-                       0, Gst::register_mm_type<LegacyDecoder>(
-                               "sigrok_legacy_decoder"));
-
-       return true;
-}
-
-LegacyDecoder::LegacyDecoder(GstBaseSink *gobj) :
-       Glib::ObjectBase(typeid(LegacyDecoder)),
-       Sink(gobj)
-{
-}
-
-Glib::RefPtr<LegacyDecoder>LegacyDecoder::create(
-       struct srd_session *libsigrokdecode_session, uint64_t unitsize)
-{
-       auto element = Gst::ElementFactory::create_element("sigrok_legacy_decoder");
-       if (!element)
-               throw runtime_error("Failed to create element - plugin not registered?");
-       auto decoder = Glib::RefPtr<LegacyDecoder>::cast_static(element);
-       decoder->session_ = libsigrokdecode_session;
-       decoder->unitsite_ = unitsize;
-
-       return decoder;
-}
-
-struct srd_session *LegacyDecoder::libsigrokdecode_session()
-{
-       return session_;
-}
-
-Gst::FlowReturn LegacyDecoder::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer)
-{
-       Gst::MapInfo info;
-       buffer->map(info, Gst::MAP_READ);
-       uint64_t num_samples = info.get_size() / unitsite_;
-       srd_session_send(session_, abs_ss_, abs_ss_ + num_samples,
-               info.get_data(), info.get_size(), unitsite_);
-       abs_ss_ += num_samples;
-       buffer->unmap(info);
-
-       return Gst::FLOW_OK;
-}
-
-bool LegacyDecoder::start_vfunc()
-{
-       abs_ss_ = 0;
-       srd_session_start(session_);
-
-       return true;
-}
-
-bool LegacyDecoder::stop_vfunc()
-{
-       srd_session_terminate_reset(session_);
-
-       return true;
-}
-#endif
-
 }