From: Uwe Hermann Date: Wed, 9 Jan 2019 01:15:47 +0000 (+0100) Subject: Factor out src/init.cpp. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fc5450cb62d7dc06f7928e5dfb587ccc908547d4;p=libsigrokflow.git Factor out src/init.cpp. --- diff --git a/Makefile.am b/Makefile.am index 533813a..a0f34fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,7 +28,8 @@ AM_CXXFLAGS = $(SRF_WXXFLAGS) $(LIBSIGROKFLOW_CFLAGS) lib_LTLIBRARIES = libsigrokflow.la libsigrokflow_la_SOURCES = \ - src/main.cpp + src/main.cpp \ + src/init.cpp libsigrokflow_la_LIBADD = $(LIBSIGROKFLOW_LIBS) libsigrokflow_la_LDFLAGS = -version-info $(SRF_LIB_VERSION) -no-undefined diff --git a/src/init.cpp b/src/init.cpp new file mode 100644 index 0000000..344ba6a --- /dev/null +++ b/src/init.cpp @@ -0,0 +1,73 @@ +/* + * This file is part of the libsigrokflow project. + * + * Copyright (C) 2018 Martin Ling + * Copyright (C) 2018 Uwe Hermann + * + * 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 . + */ + +#include +#include + +namespace Srf +{ + +static bool srf_initialized_ = false; + +void init() +{ + if (srf_initialized_) + throw runtime_error("libsigrokflow is already initialized"); + + if (!Gst::is_initialized()) + throw runtime_error("Gst::init() has not run yet"); + +#ifdef HAVE_LIBSIGROKCXX + 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", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); + Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, + "sigrok_legacy_input", + "Wrapper for inputs using legacy libsigrok APIs", + sigc::ptr_fun(&LegacyInput::register_element), + "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); + Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, + "sigrok_legacy_output", + "Wrapper for outputs using legacy libsigrok APIs", + sigc::ptr_fun(&LegacyOutput::register_element), + "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); +#endif +#ifdef HAVE_LIBSIGROKDECODE + Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, + "sigrok_legacy_decoder", + "Wrapper for protocol decoders using legacy libsigrokdecode APIs", + sigc::ptr_fun(&LegacyDecoder::register_element), + "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); +#endif + + srf_initialized_ = true; +} + +void deinit() +{ + if (!srf_initialized_) + throw runtime_error("libsigrokflow is not initialized"); + + srf_initialized_ = false; +} + +} diff --git a/src/main.cpp b/src/main.cpp index b79e935..1b1193f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,52 +28,6 @@ namespace Srf using namespace std; using namespace std::placeholders; -static bool srf_initialized_ = false; - -void init() -{ - if (srf_initialized_) - throw runtime_error("libsigrokflow is already initialized"); - - if (!Gst::is_initialized()) - throw runtime_error("Gst::init() has not run yet"); - -#ifdef HAVE_LIBSIGROKCXX - 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", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); - Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, - "sigrok_legacy_input", - "Wrapper for inputs using legacy libsigrok APIs", - sigc::ptr_fun(&LegacyInput::register_element), - "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); - Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, - "sigrok_legacy_output", - "Wrapper for outputs using legacy libsigrok APIs", - sigc::ptr_fun(&LegacyOutput::register_element), - "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); -#endif -#ifdef HAVE_LIBSIGROKDECODE - Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, - "sigrok_legacy_decoder", - "Wrapper for protocol decoders using legacy libsigrokdecode APIs", - sigc::ptr_fun(&LegacyDecoder::register_element), - "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); -#endif - - srf_initialized_ = true; -} - -void deinit() -{ - if (!srf_initialized_) - throw runtime_error("libsigrokflow is not initialized"); - - srf_initialized_ = false; -} - Sink::Sink(GstBaseSink *gobj) : Gst::BaseSink(gobj) {