summaryrefslogtreecommitdiffstats
path: root/src/JackDbusDriver.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-29 18:02:59 +0100
committerDavid Robillard <d@drobilla.net>2020-11-29 18:03:31 +0100
commitb848d9ccbd94f88e3b1b9f1884a05efcea377dfc (patch)
tree6a859e66e613061b1abcebb13fada336982efbac /src/JackDbusDriver.cpp
parent9964717f1c5bf56f24c81ff5597085a62e966a7b (diff)
downloadpatchage-b848d9ccbd94f88e3b1b9f1884a05efcea377dfc.tar.gz
patchage-b848d9ccbd94f88e3b1b9f1884a05efcea377dfc.tar.bz2
patchage-b848d9ccbd94f88e3b1b9f1884a05efcea377dfc.zip
Completely isolate drivers from the rest of the application
Diffstat (limited to 'src/JackDbusDriver.cpp')
-rw-r--r--src/JackDbusDriver.cpp83
1 files changed, 81 insertions, 2 deletions
diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp
index add838d..c656594 100644
--- a/src/JackDbusDriver.cpp
+++ b/src/JackDbusDriver.cpp
@@ -15,8 +15,6 @@
* along with Patchage. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "JackDbusDriver.hpp"
-
#include "ClientType.hpp"
#include "Driver.hpp"
#include "ILog.hpp"
@@ -24,6 +22,7 @@
#include "PortNames.hpp"
#include "PortType.hpp"
#include "SignalDirection.hpp"
+#include "make_jack_driver.hpp"
#include "warnings.hpp"
PATCHAGE_DISABLE_FMT_WARNINGS
@@ -37,6 +36,7 @@ PATCHAGE_RESTORE_WARNINGS
#include <glib.h>
#include <cassert>
+#include <cstdint>
#include <cstring>
#include <set>
#include <string>
@@ -54,6 +54,78 @@ PATCHAGE_RESTORE_WARNINGS
#define JACKDBUS_PORT_TYPE_AUDIO 0
#define JACKDBUS_PORT_TYPE_MIDI 1
+/// Driver for JACK audio and midi ports that uses D-Bus
+class JackDriver : public AudioDriver
+{
+public:
+ explicit JackDriver(ILog& log, EventSink emit_event);
+
+ JackDriver(const JackDriver&) = delete;
+ JackDriver& operator=(const JackDriver&) = delete;
+
+ JackDriver(JackDriver&&) = delete;
+ JackDriver& operator=(JackDriver&&) = delete;
+
+ ~JackDriver() override;
+
+ // Driver interface
+ void attach(bool launch_daemon) override;
+ void detach() override;
+ bool is_attached() const override;
+ void refresh(const EventSink& sink) override;
+ bool connect(const PortID& tail_id, const PortID& head_id) override;
+ bool disconnect(const PortID& tail_id, const PortID& head_id) override;
+
+ // AudioDriver interface
+ uint32_t xruns() override;
+ void reset_xruns() override;
+ uint32_t buffer_size() override;
+ bool set_buffer_size(uint32_t frames) override;
+ uint32_t sample_rate() override;
+
+private:
+ PortType patchage_port_type(dbus_uint32_t dbus_port_type) const;
+
+ PortInfo port_info(const std::string& port_name,
+ dbus_uint32_t port_type,
+ dbus_uint32_t port_flags) const;
+
+ void error_msg(const std::string& msg) const;
+ void info_msg(const std::string& msg) const;
+
+ bool call(bool response_expected,
+ const char* iface,
+ const char* method,
+ DBusMessage** reply_ptr_ptr,
+ int in_type,
+ ...);
+
+ void update_attached();
+
+ bool is_started();
+
+ void start_server();
+
+ void stop_server();
+
+ static DBusHandlerResult dbus_message_hook(DBusConnection* connection,
+ DBusMessage* message,
+ void* jack_driver);
+
+ void on_jack_appeared();
+
+ void on_jack_disappeared();
+
+ ILog& _log;
+ DBusError _dbus_error;
+ DBusConnection* _dbus_connection;
+
+ mutable bool _server_responding;
+ bool _server_started;
+
+ dbus_uint64_t _graph_version;
+};
+
JackDriver::JackDriver(ILog& log, EventSink emit_event)
: AudioDriver{std::move(emit_event)}
, _log(log)
@@ -900,3 +972,10 @@ JackDriver::info_msg(const std::string& msg) const
{
_log.info(std::string{"[JACK] "} + msg);
}
+
+std::unique_ptr<AudioDriver>
+make_jack_driver(ILog& log, Driver::EventSink emit_event)
+{
+ return std::unique_ptr<AudioDriver>{
+ new JackDriver{log, std::move(emit_event)}};
+}