]> sigrok.org Git - libsigrokflow.git/blobdiff - src/main.cpp
Srf::init(): Throw an exception upon multiple init() calls.
[libsigrokflow.git] / src / main.cpp
index db3de8fad347ba9cc16eb339c1ef8db19944579e..45d2308fe3a99387229095d4d1aaf84f7325aee1 100644 (file)
  */
 
 #include <config.h>
-#include <libsigrokflow/libsigrokflow.hpp>
-
-#include <libsigrokdecode/libsigrokdecode.h>
-
 #include <iostream>
+#include <libsigrokflow/libsigrokflow.hpp>
 
 namespace Srf
 {
@@ -33,6 +30,12 @@ using namespace std::placeholders;
 
 void init()
 {
+       static bool srf_initialized = false;
+
+       if (srf_initialized)
+               throw runtime_error("libsigrokflow is already initialized");
+
+#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",
@@ -48,11 +51,16 @@ void init()
                        "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;
 }
 
 Sink::Sink(GstBaseSink *gobj) :
@@ -70,6 +78,7 @@ CaptureDevice::CaptureDevice(GstElement *gobj) :
 {
 }
 
+#ifdef HAVE_LIBSIGROKCXX
 void LegacyCaptureDevice::class_init(Gst::ElementClass<LegacyCaptureDevice> *klass)
 {
        klass->set_metadata("sigrok legacy capture device",
@@ -345,7 +354,9 @@ bool LegacyOutput::stop_vfunc()
        cout << result;
        return true;
 }
+#endif
 
+#ifdef HAVE_LIBSIGROKDECODE
 void LegacyDecoder::class_init(Gst::ElementClass<LegacyDecoder> *klass)
 {
        klass->set_metadata("sigrok legacy decoder",
@@ -414,5 +425,6 @@ bool LegacyDecoder::stop_vfunc()
        srd_session_terminate_reset(_session);
        return true;
 }
+#endif
 
 }