fix crash when copy'ing latent plugins
[ardour.git] / libs / backends / jack / jack_api.cc
index 0136161181e0068ef5dbc79bad4f539ab531277f..b63b1c1f69f8d0580623b351c395374b71ad2f4c 100644 (file)
 
 #include "jack_connection.h"
 #include "jack_audiobackend.h"
-#include "jack_portengine.h"
 
 using namespace ARDOUR;
 
 static boost::shared_ptr<JACKAudioBackend> backend;
-static boost::shared_ptr<JACKPortEngine> port_engine;
 static boost::shared_ptr<JackConnection> jack_connection;
 
+static boost::shared_ptr<AudioBackend> backend_factory (AudioEngine& ae);
+static int  instantiate (const std::string& arg1, const std::string& arg2);
+static int  deinstantiate ();
+static bool already_configured ();
+static bool available ();
+
+static ARDOUR::AudioBackendInfo _descriptor = {
+       "JACK",
+       instantiate,
+       deinstantiate,
+       backend_factory,
+       already_configured,
+       available
+};
+
 static boost::shared_ptr<AudioBackend>
 backend_factory (AudioEngine& ae)
 {
@@ -35,26 +48,12 @@ backend_factory (AudioEngine& ae)
        }
 
        if (!backend) {
-               backend.reset (new JACKAudioBackend (ae, jack_connection));
+               backend.reset (new JACKAudioBackend (ae, _descriptor, jack_connection));
        }
 
        return backend;
 }
 
-static boost::shared_ptr<PortEngine>
-portengine_factory (PortManager& pm)
-{
-       if (!jack_connection) {
-               return boost::shared_ptr<PortEngine>();
-       }
-
-       if (!port_engine) {
-               port_engine.reset (new JACKPortEngine (pm, jack_connection));
-       }
-
-       return port_engine;
-}
-
 static int
 instantiate (const std::string& arg1, const std::string& arg2)
 {
@@ -67,10 +66,9 @@ instantiate (const std::string& arg1, const std::string& arg2)
        return 0;
 }
 
-static int 
+static int
 deinstantiate ()
 {
-       port_engine.reset ();
        backend.reset ();
        jack_connection.reset ();
 
@@ -80,23 +78,14 @@ deinstantiate ()
 static bool
 already_configured ()
 {
-       return JackConnection::server_running ();
+       return !JackConnection::in_control ();
 }
 
-extern "C" {
-       
-       
-       /* functions looked up using dlopen-and-cousins, and so naming scope
-        * must be non-mangled.
-        */
-
-       ARDOUR::AudioBackendInfo descriptor = {
-               "JACK",
-               instantiate,
-               deinstantiate,
-               backend_factory,
-               portengine_factory,
-               already_configured,
-       };
+static bool
+available ()
+{
+       return have_libjack() ? false : true;
 }
 
+extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor() { return &_descriptor; }
+