remove use of implicit namespaces
[ladish.git] / gui / jack_proxy.cpp
blobe63fb6e536a9f773dd210d99b0a92b999717abf3
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains code that interface with JACK through D-Bus
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "common.h"
29 #include <cassert>
30 #include <cstring>
31 #include <set>
32 #include <iostream>
34 #include <glib.h>
35 #include <dbus/dbus.h>
36 #include <dbus/dbus-glib.h>
37 #include <dbus/dbus-glib-lowlevel.h>
39 #include "Patchage.hpp"
40 #include "jack_proxy.hpp"
41 #include "dbus_helpers.h"
43 #define JACKDBUS_SERVICE "org.jackaudio.service"
44 #define JACKDBUS_OBJECT "/org/jackaudio/Controller"
45 #define JACKDBUS_IFACE_CONTROL "org.jackaudio.JackControl"
46 #define JACKDBUS_IFACE_PATCHBAY "org.jackaudio.JackPatchbay"
48 #define JACKDBUS_PORT_FLAG_INPUT 0x00000001
49 #define JACKDBUS_PORT_FLAG_OUTPUT 0x00000002
50 #define JACKDBUS_PORT_FLAG_PHYSICAL 0x00000004
51 #define JACKDBUS_PORT_FLAG_CAN_MONITOR 0x00000008
52 #define JACKDBUS_PORT_FLAG_TERMINAL 0x00000010
54 #define JACKDBUS_PORT_TYPE_AUDIO 0
55 #define JACKDBUS_PORT_TYPE_MIDI 1
57 //#define USE_FULL_REFRESH
60 jack_proxy::jack_proxy(Patchage* app)
61 : _app(app)
62 , _server_responding(false)
63 , _server_started(false)
64 , _graph_version(0)
65 , _max_dsp_load(0.0)
67 patchage_dbus_add_match("type='signal',interface='" DBUS_INTERFACE_DBUS "',member=NameOwnerChanged,arg0='" JACKDBUS_SERVICE "'");
68 #if defined(USE_FULL_REFRESH)
69 patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=GraphChanged");
70 #else
71 // patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=ClientAppeared");
72 // patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=ClientDisappeared");
73 patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=PortAppeared");
74 patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=PortDisappeared");
75 patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=PortsConnected");
76 patchage_dbus_add_match("type='signal',interface='" JACKDBUS_IFACE_PATCHBAY "',member=PortsDisconnected");
77 #endif
78 patchage_dbus_add_filter(dbus_message_hook, this);
80 update_attached();
82 if (!_server_responding) {
83 return;
86 refresh(); // the initial refresh
90 jack_proxy::~jack_proxy()
94 void
95 jack_proxy::update_attached()
97 bool was_started = _server_started;
98 _server_started = is_started();
100 if (!_server_responding) {
101 if (was_started) {
102 signal_stopped.emit();
104 return;
107 if (_server_started && !was_started) {
108 signal_started.emit();
109 return;
112 if (!_server_started && was_started) {
113 signal_stopped.emit();
114 return;
119 void
120 jack_proxy::on_jack_appeared()
122 info_msg("JACK appeared.");
123 update_attached();
127 void
128 jack_proxy::on_jack_disappeared()
130 info_msg("JACK disappeared.");
132 // we are not calling update_attached() here, because it will activate jackdbus
134 _server_responding = false;
136 if (_server_started) {
137 signal_stopped.emit();
140 _server_started = false;
144 DBusHandlerResult
145 jack_proxy::dbus_message_hook(
146 DBusConnection* connection,
147 DBusMessage* message,
148 void* jack_driver)
150 dbus_uint64_t new_graph_version;
151 dbus_uint64_t client_id;
152 const char *client_name;
153 dbus_uint64_t port_id;
154 const char *port_name;
155 dbus_uint32_t port_flags;
156 dbus_uint32_t port_type;
157 dbus_uint64_t client2_id;
158 const char *client2_name;
159 dbus_uint64_t port2_id;
160 const char *port2_name;
161 dbus_uint64_t connection_id;
162 const char *object_name;
163 const char *old_owner;
164 const char *new_owner;
166 assert(jack_driver);
167 jack_proxy* me = reinterpret_cast<jack_proxy*>(jack_driver);
169 //me->info_msg("dbus_message_hook() called.");
171 // Handle signals we have subscribed for in attach()
173 if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
174 if (!dbus_message_get_args( message, &g_dbus_error,
175 DBUS_TYPE_STRING, &object_name,
176 DBUS_TYPE_STRING, &old_owner,
177 DBUS_TYPE_STRING, &new_owner,
178 DBUS_TYPE_INVALID)) {
179 me->error_msg(str(boost::format("dbus_message_get_args() failed to extract "
180 "NameOwnerChanged signal arguments (%s)") % g_dbus_error.message));
181 dbus_error_free(&g_dbus_error);
182 return DBUS_HANDLER_RESULT_HANDLED;
185 if ((std::string)object_name != JACKDBUS_SERVICE)
187 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
190 if (old_owner[0] == '\0') {
191 me->on_jack_appeared();
192 } else if (new_owner[0] == '\0') {
193 me->on_jack_disappeared();
196 return DBUS_HANDLER_RESULT_HANDLED;
199 #if defined(USE_FULL_REFRESH)
200 if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "GraphChanged")) {
201 if (!dbus_message_get_args(message, &g_dbus_error,
202 DBUS_TYPE_UINT64, &new_graph_version,
203 DBUS_TYPE_INVALID)) {
204 me->error_msg(str(boost::format("dbus_message_get_args() failed to extract "
205 "GraphChanged signal arguments (%s)") % g_dbus_error.message));
206 dbus_error_free(&g_dbus_error);
207 return DBUS_HANDLER_RESULT_HANDLED;
210 if (!me->_server_started) {
211 me->_server_started = true;
212 me->signal_attached.emit();
215 if (new_graph_version > me->_graph_version) {
216 me->refresh_internal(false);
219 return DBUS_HANDLER_RESULT_HANDLED;
221 #else
222 // if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "ClientAppeared")) {
223 // me->info_msg("ClientAppeared");
224 // return DBUS_HANDLER_RESULT_HANDLED;
225 // }
227 // if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "ClientDisappeared")) {
228 // me->info_msg("ClientDisappeared");
229 // return DBUS_HANDLER_RESULT_HANDLED;
230 // }
232 if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "PortAppeared")) {
233 if (!dbus_message_get_args( message, &g_dbus_error,
234 DBUS_TYPE_UINT64, &new_graph_version,
235 DBUS_TYPE_UINT64, &client_id,
236 DBUS_TYPE_STRING, &client_name,
237 DBUS_TYPE_UINT64, &port_id,
238 DBUS_TYPE_STRING, &port_name,
239 DBUS_TYPE_UINT32, &port_flags,
240 DBUS_TYPE_UINT32, &port_type,
241 DBUS_TYPE_INVALID)) {
242 me->error_msg(str(boost::format("dbus_message_get_args() failed to extract "
243 "PortAppeared signal arguments (%s)") % g_dbus_error.message));
244 dbus_error_free(&g_dbus_error);
245 return DBUS_HANDLER_RESULT_HANDLED;
248 //me->info_msg(str(boost::format("PortAppeared, %s(%llu):%s(%llu), %lu, %lu") % client_name % client_id % port_name % port_id % port_flags % port_type));
250 if (!me->_server_started) {
251 me->_server_started = true;
252 me->signal_started.emit();
255 me->on_port_added(client_id, client_name, port_id, port_name, port_flags, port_type);
257 return DBUS_HANDLER_RESULT_HANDLED;
260 if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "PortDisappeared")) {
261 if (!dbus_message_get_args( message, &g_dbus_error,
262 DBUS_TYPE_UINT64, &new_graph_version,
263 DBUS_TYPE_UINT64, &client_id,
264 DBUS_TYPE_STRING, &client_name,
265 DBUS_TYPE_UINT64, &port_id,
266 DBUS_TYPE_STRING, &port_name,
267 DBUS_TYPE_INVALID)) {
268 me->error_msg(str(boost::format("dbus_message_get_args() failed to extract "
269 "PortDisappeared signal arguments (%s)") % g_dbus_error.message));
270 dbus_error_free(&g_dbus_error);
271 return DBUS_HANDLER_RESULT_HANDLED;
274 //me->info_msg(str(boost::format("PortDisappeared, %s(%llu):%s(%llu)") % client_name % client_id % port_name % port_id));
276 if (!me->_server_started) {
277 me->_server_started = true;
278 me->signal_started.emit();
281 me->on_port_removed(client_id, client_name, port_id, port_name);
283 return DBUS_HANDLER_RESULT_HANDLED;
286 if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "PortsConnected")) {
287 if (!dbus_message_get_args(message, &g_dbus_error,
288 DBUS_TYPE_UINT64, &new_graph_version,
289 DBUS_TYPE_UINT64, &client_id,
290 DBUS_TYPE_STRING, &client_name,
291 DBUS_TYPE_UINT64, &port_id,
292 DBUS_TYPE_STRING, &port_name,
293 DBUS_TYPE_UINT64, &client2_id,
294 DBUS_TYPE_STRING, &client2_name,
295 DBUS_TYPE_UINT64, &port2_id,
296 DBUS_TYPE_STRING, &port2_name,
297 DBUS_TYPE_UINT64, &connection_id,
298 DBUS_TYPE_INVALID)) {
299 me->error_msg(str(boost::format("dbus_message_get_args() failed to extract "
300 "PortsConnected signal arguments (%s)") % g_dbus_error.message));
301 dbus_error_free(&g_dbus_error);
302 return DBUS_HANDLER_RESULT_HANDLED;
305 if (!me->_server_started) {
306 me->_server_started = true;
307 me->signal_started.emit();
310 me->on_ports_connected(
311 connection_id,
312 client_id, client_name,
313 port_id, port_name,
314 client2_id, client2_name,
315 port2_id, port2_name);
317 return DBUS_HANDLER_RESULT_HANDLED;
320 if (dbus_message_is_signal(message, JACKDBUS_IFACE_PATCHBAY, "PortsDisconnected")) {
321 if (!dbus_message_get_args(message, &g_dbus_error,
322 DBUS_TYPE_UINT64, &new_graph_version,
323 DBUS_TYPE_UINT64, &client_id,
324 DBUS_TYPE_STRING, &client_name,
325 DBUS_TYPE_UINT64, &port_id,
326 DBUS_TYPE_STRING, &port_name,
327 DBUS_TYPE_UINT64, &client2_id,
328 DBUS_TYPE_STRING, &client2_name,
329 DBUS_TYPE_UINT64, &port2_id,
330 DBUS_TYPE_STRING, &port2_name,
331 DBUS_TYPE_UINT64, &connection_id,
332 DBUS_TYPE_INVALID)) {
333 me->error_msg(str(boost::format("dbus_message_get_args() failed to extract "
334 "PortsConnected signal arguments (%s)") % g_dbus_error.message));
335 dbus_error_free(&g_dbus_error);
336 return DBUS_HANDLER_RESULT_HANDLED;
339 if (!me->_server_started) {
340 me->_server_started = true;
341 me->signal_started.emit();
344 me->on_ports_disconnected(
345 connection_id,
346 client_id, client_name,
347 port_id, port_name,
348 client2_id, client2_name,
349 port2_id, port2_name);
351 return DBUS_HANDLER_RESULT_HANDLED;
353 #endif
355 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
358 bool
359 jack_proxy::call(
360 bool response_expected,
361 const char* iface,
362 const char* method,
363 DBusMessage** reply_ptr_ptr,
364 int in_type, ...)
366 va_list ap;
368 va_start(ap, in_type);
370 _server_responding = patchage_dbus_call_valist(
371 response_expected,
372 JACKDBUS_SERVICE,
373 JACKDBUS_OBJECT,
374 iface,
375 method,
376 reply_ptr_ptr,
377 in_type,
378 ap);
380 va_end(ap);
382 return _server_responding;
385 bool
386 jack_proxy::is_started()
388 DBusMessage* reply_ptr;
389 dbus_bool_t started;
391 if (!call(false, JACKDBUS_IFACE_CONTROL, "IsStarted", &reply_ptr, DBUS_TYPE_INVALID)) {
392 return false;
395 if (!dbus_message_get_args(reply_ptr, &g_dbus_error,
396 DBUS_TYPE_BOOLEAN, &started,
397 DBUS_TYPE_INVALID)) {
398 dbus_message_unref(reply_ptr);
399 dbus_error_free(&g_dbus_error);
400 error_msg("decoding reply of IsStarted failed.");
401 return false;
404 dbus_message_unref(reply_ptr);
406 return started;
410 void
411 jack_proxy::start_server()
413 DBusMessage* reply_ptr;
415 if (!call(false, JACKDBUS_IFACE_CONTROL, "StartServer", &reply_ptr, DBUS_TYPE_INVALID)) {
416 return;
419 dbus_message_unref(reply_ptr);
421 update_attached();
425 void
426 jack_proxy::stop_server()
428 DBusMessage* reply_ptr;
430 if (!call(false, JACKDBUS_IFACE_CONTROL, "StopServer", &reply_ptr, DBUS_TYPE_INVALID)) {
431 return;
434 dbus_message_unref(reply_ptr);
436 if (!_server_started) {
437 _server_started = false;
438 signal_stopped.emit();
442 void
443 jack_proxy::on_port_added(
444 dbus_uint64_t client_id,
445 const char * client_name,
446 dbus_uint64_t port_id,
447 const char * port_name,
448 dbus_uint32_t port_flags,
449 dbus_uint32_t port_type)
451 PortType local_port_type;
453 switch (port_type) {
454 case JACKDBUS_PORT_TYPE_AUDIO:
455 local_port_type = JACK_AUDIO;
456 break;
457 case JACKDBUS_PORT_TYPE_MIDI:
458 local_port_type = JACK_MIDI;
459 break;
460 default:
461 error_msg("Unknown JACK D-Bus port type");
462 return;
465 _app->on_port_added(
466 client_name,
467 port_name,
468 local_port_type,
469 port_flags & JACKDBUS_PORT_FLAG_INPUT,
470 port_flags & JACKDBUS_PORT_FLAG_TERMINAL);
473 void
474 jack_proxy::on_port_removed(
475 dbus_uint64_t client_id,
476 const char * client_name,
477 dbus_uint64_t port_id,
478 const char * port_name)
480 _app->on_port_removed(client_name, port_name);
482 if (_app->is_canvas_empty())
484 if (_server_started)
486 signal_stopped.emit();
489 _server_started = false;
493 void
494 jack_proxy::on_ports_connected(
495 dbus_uint64_t connection_id,
496 dbus_uint64_t client1_id,
497 const char* client1_name,
498 dbus_uint64_t port1_id,
499 const char* port1_name,
500 dbus_uint64_t client2_id,
501 const char* client2_name,
502 dbus_uint64_t port2_id,
503 const char* port2_name)
505 _app->on_ports_connected(client1_name, port1_name, client2_name, port2_name);
508 void
509 jack_proxy::on_ports_disconnected(
510 dbus_uint64_t connection_id,
511 dbus_uint64_t client1_id,
512 const char* client1_name,
513 dbus_uint64_t port1_id,
514 const char* port1_name,
515 dbus_uint64_t client2_id,
516 const char* client2_name,
517 dbus_uint64_t port2_id,
518 const char* port2_name)
520 _app->on_ports_disconnected(client1_name, port1_name, client2_name, port2_name);
523 void
524 jack_proxy::refresh_internal(bool force)
526 DBusMessage* reply_ptr;
527 DBusMessageIter iter;
528 dbus_uint64_t version;
529 const char * reply_signature;
530 DBusMessageIter clients_array_iter;
531 DBusMessageIter client_struct_iter;
532 DBusMessageIter ports_array_iter;
533 DBusMessageIter port_struct_iter;
534 DBusMessageIter connections_array_iter;
535 DBusMessageIter connection_struct_iter;
536 dbus_uint64_t client_id;
537 const char *client_name;
538 dbus_uint64_t port_id;
539 const char *port_name;
540 dbus_uint32_t port_flags;
541 dbus_uint32_t port_type;
542 dbus_uint64_t client2_id;
543 const char *client2_name;
544 dbus_uint64_t port2_id;
545 const char *port2_name;
546 dbus_uint64_t connection_id;
548 if (!_server_started)
550 info_msg("ignoring refresh request because JACK server is stopped");
551 return;
554 if (force) {
555 version = 0; // workaround module split/join stupidity
556 } else {
557 version = _graph_version;
560 if (!call(true, JACKDBUS_IFACE_PATCHBAY, "GetGraph", &reply_ptr, DBUS_TYPE_UINT64, &version, DBUS_TYPE_INVALID)) {
561 error_msg("GetGraph() failed.");
562 return;
565 reply_signature = dbus_message_get_signature(reply_ptr);
567 if (strcmp(reply_signature, "ta(tsa(tsuu))a(tstststst)") != 0) {
568 error_msg((std::string )"GetGraph() reply signature mismatch. " + reply_signature);
569 goto unref;
572 dbus_message_iter_init(reply_ptr, &iter);
574 //info_msg((std::string)"version " + (char)dbus_message_iter_get_arg_type(&iter));
575 dbus_message_iter_get_basic(&iter, &version);
576 dbus_message_iter_next(&iter);
578 if (!force && version <= _graph_version) {
579 goto unref;
582 _app->clear_canvas();
584 //info_msg(str(boost::format("got new graph version %llu") % version));
585 _graph_version = version;
587 //info_msg((std::string)"clients " + (char)dbus_message_iter_get_arg_type(&iter));
589 for (dbus_message_iter_recurse(&iter, &clients_array_iter);
590 dbus_message_iter_get_arg_type(&clients_array_iter) != DBUS_TYPE_INVALID;
591 dbus_message_iter_next(&clients_array_iter)) {
592 //info_msg((std::string)"a client " + (char)dbus_message_iter_get_arg_type(&clients_array_iter));
593 dbus_message_iter_recurse(&clients_array_iter, &client_struct_iter);
595 dbus_message_iter_get_basic(&client_struct_iter, &client_id);
596 dbus_message_iter_next(&client_struct_iter);
598 dbus_message_iter_get_basic(&client_struct_iter, &client_name);
599 dbus_message_iter_next(&client_struct_iter);
601 //info_msg((std::string)"client '" + client_name + "'");
603 for (dbus_message_iter_recurse(&client_struct_iter, &ports_array_iter);
604 dbus_message_iter_get_arg_type(&ports_array_iter) != DBUS_TYPE_INVALID;
605 dbus_message_iter_next(&ports_array_iter)) {
606 //info_msg((std::string)"a port " + (char)dbus_message_iter_get_arg_type(&ports_array_iter));
607 dbus_message_iter_recurse(&ports_array_iter, &port_struct_iter);
609 dbus_message_iter_get_basic(&port_struct_iter, &port_id);
610 dbus_message_iter_next(&port_struct_iter);
612 dbus_message_iter_get_basic(&port_struct_iter, &port_name);
613 dbus_message_iter_next(&port_struct_iter);
615 dbus_message_iter_get_basic(&port_struct_iter, &port_flags);
616 dbus_message_iter_next(&port_struct_iter);
618 dbus_message_iter_get_basic(&port_struct_iter, &port_type);
619 dbus_message_iter_next(&port_struct_iter);
621 //info_msg((std::string)"port: " + port_name);
623 on_port_added(client_id, client_name, port_id, port_name, port_flags, port_type);
626 dbus_message_iter_next(&client_struct_iter);
629 dbus_message_iter_next(&iter);
631 for (dbus_message_iter_recurse(&iter, &connections_array_iter);
632 dbus_message_iter_get_arg_type(&connections_array_iter) != DBUS_TYPE_INVALID;
633 dbus_message_iter_next(&connections_array_iter)) {
634 //info_msg((std::string)"a connection " + (char)dbus_message_iter_get_arg_type(&connections_array_iter));
635 dbus_message_iter_recurse(&connections_array_iter, &connection_struct_iter);
637 dbus_message_iter_get_basic(&connection_struct_iter, &client_id);
638 dbus_message_iter_next(&connection_struct_iter);
640 dbus_message_iter_get_basic(&connection_struct_iter, &client_name);
641 dbus_message_iter_next(&connection_struct_iter);
643 dbus_message_iter_get_basic(&connection_struct_iter, &port_id);
644 dbus_message_iter_next(&connection_struct_iter);
646 dbus_message_iter_get_basic(&connection_struct_iter, &port_name);
647 dbus_message_iter_next(&connection_struct_iter);
649 dbus_message_iter_get_basic(&connection_struct_iter, &client2_id);
650 dbus_message_iter_next(&connection_struct_iter);
652 dbus_message_iter_get_basic(&connection_struct_iter, &client2_name);
653 dbus_message_iter_next(&connection_struct_iter);
655 dbus_message_iter_get_basic(&connection_struct_iter, &port2_id);
656 dbus_message_iter_next(&connection_struct_iter);
658 dbus_message_iter_get_basic(&connection_struct_iter, &port2_name);
659 dbus_message_iter_next(&connection_struct_iter);
661 dbus_message_iter_get_basic(&connection_struct_iter, &connection_id);
662 dbus_message_iter_next(&connection_struct_iter);
664 //info_msg(str(boost::format("connection(%llu) %s(%llu):%s(%llu) <-> %s(%llu):%s(%llu)") %
665 // connection_id %
666 // client_name %
667 // client_id %
668 // port_name %
669 // port_id %
670 // client2_name %
671 // client2_id %
672 // port2_name %
673 // port2_id));
675 on_ports_connected(
676 connection_id,
677 client_id, client_name,
678 port_id, port_name,
679 client2_id, client2_name,
680 port2_id, port2_name);
683 unref:
684 dbus_message_unref(reply_ptr);
688 void
689 jack_proxy::refresh()
691 refresh_internal(true);
695 bool
696 jack_proxy::connect(
697 const char * client1_name,
698 const char * port1_name,
699 const char * client2_name,
700 const char * port2_name)
702 DBusMessage* reply_ptr;
704 if (!call(true, JACKDBUS_IFACE_PATCHBAY, "ConnectPortsByName", &reply_ptr,
705 DBUS_TYPE_STRING, &client1_name,
706 DBUS_TYPE_STRING, &port1_name,
707 DBUS_TYPE_STRING, &client2_name,
708 DBUS_TYPE_STRING, &port2_name,
709 DBUS_TYPE_INVALID)) {
710 error_msg("ConnectPortsByName() failed.");
711 return false;
714 return true;
718 bool
719 jack_proxy::disconnect(
720 const char * client1_name,
721 const char * port1_name,
722 const char * client2_name,
723 const char * port2_name)
725 DBusMessage* reply_ptr;
727 if (!call(true, JACKDBUS_IFACE_PATCHBAY, "DisconnectPortsByName", &reply_ptr,
728 DBUS_TYPE_STRING, &client1_name,
729 DBUS_TYPE_STRING, &port1_name,
730 DBUS_TYPE_STRING, &client2_name,
731 DBUS_TYPE_STRING, &port2_name,
732 DBUS_TYPE_INVALID)) {
733 error_msg("DisconnectPortsByName() failed.");
734 return false;
737 return true;
740 uint32_t
741 jack_proxy::buffer_size()
743 DBusMessage* reply_ptr;
744 dbus_uint32_t buffer_size;
746 if (_server_responding && !_server_started) {
747 goto fail;
750 if (!call(true, JACKDBUS_IFACE_CONTROL, "GetBufferSize", &reply_ptr, DBUS_TYPE_INVALID)) {
751 goto fail;
754 if (!dbus_message_get_args(reply_ptr, &g_dbus_error, DBUS_TYPE_UINT32, &buffer_size, DBUS_TYPE_INVALID)) {
755 dbus_message_unref(reply_ptr);
756 dbus_error_free(&g_dbus_error);
757 error_msg("decoding reply of GetBufferSize failed.");
758 goto fail;
761 dbus_message_unref(reply_ptr);
763 return buffer_size;
765 fail:
766 return 4096; // something fake, patchage needs it to match combobox value
770 bool
771 jack_proxy::set_buffer_size(uint32_t size)
773 DBusMessage* reply_ptr;
774 dbus_uint32_t buffer_size;
776 buffer_size = size;
778 if (!call(true, JACKDBUS_IFACE_CONTROL, "SetBufferSize", &reply_ptr, DBUS_TYPE_UINT32, &buffer_size, DBUS_TYPE_INVALID)) {
779 return false;
782 dbus_message_unref(reply_ptr);
784 return true;
788 float
789 jack_proxy::sample_rate()
791 DBusMessage* reply_ptr;
792 double sample_rate;
794 if (!call(true, JACKDBUS_IFACE_CONTROL, "GetSampleRate", &reply_ptr, DBUS_TYPE_INVALID)) {
795 return false;
798 if (!dbus_message_get_args(reply_ptr, &g_dbus_error, DBUS_TYPE_DOUBLE, &sample_rate, DBUS_TYPE_INVALID)) {
799 dbus_message_unref(reply_ptr);
800 dbus_error_free(&g_dbus_error);
801 error_msg("decoding reply of GetSampleRate failed.");
802 return false;
805 dbus_message_unref(reply_ptr);
807 return sample_rate;
811 bool
812 jack_proxy::is_realtime()
814 DBusMessage* reply_ptr;
815 dbus_bool_t realtime;
817 if (!call(true, JACKDBUS_IFACE_CONTROL, "IsRealtime", &reply_ptr, DBUS_TYPE_INVALID)) {
818 return false;
821 if (!dbus_message_get_args(reply_ptr, &g_dbus_error, DBUS_TYPE_BOOLEAN, &realtime, DBUS_TYPE_INVALID)) {
822 dbus_message_unref(reply_ptr);
823 dbus_error_free(&g_dbus_error);
824 error_msg("decoding reply of IsRealtime failed.");
825 return false;
828 dbus_message_unref(reply_ptr);
830 return realtime;
834 size_t
835 jack_proxy::xruns()
837 DBusMessage* reply_ptr;
838 dbus_uint32_t xruns;
840 if (_server_responding && !_server_started) {
841 return 0;
844 if (!call(true, JACKDBUS_IFACE_CONTROL, "GetXruns", &reply_ptr, DBUS_TYPE_INVALID)) {
845 return 0;
848 if (!dbus_message_get_args(reply_ptr, &g_dbus_error, DBUS_TYPE_UINT32, &xruns, DBUS_TYPE_INVALID)) {
849 dbus_message_unref(reply_ptr);
850 dbus_error_free(&g_dbus_error);
851 error_msg("decoding reply of GetXruns failed.");
852 return 0;
855 dbus_message_unref(reply_ptr);
857 return xruns;
861 void
862 jack_proxy::reset_xruns()
864 DBusMessage* reply_ptr;
866 if (!call(true, JACKDBUS_IFACE_CONTROL, "ResetXruns", &reply_ptr, DBUS_TYPE_INVALID)) {
867 return;
870 dbus_message_unref(reply_ptr);
874 float
875 jack_proxy::get_dsp_load()
877 DBusMessage* reply_ptr;
878 double load;
880 if (_server_responding && !_server_started) {
881 return 0.0;
884 if (!call(true, JACKDBUS_IFACE_CONTROL, "GetLoad", &reply_ptr, DBUS_TYPE_INVALID)) {
885 return 0.0;
888 if (!dbus_message_get_args(reply_ptr, &g_dbus_error, DBUS_TYPE_DOUBLE, &load, DBUS_TYPE_INVALID)) {
889 dbus_message_unref(reply_ptr);
890 dbus_error_free(&g_dbus_error);
891 error_msg("decoding reply of GetLoad failed.");
892 return 0.0;
895 dbus_message_unref(reply_ptr);
897 return load;
900 void
901 jack_proxy::start_transport()
903 //info_msg(__func__);
907 void
908 jack_proxy::stop_transport()
910 //info_msg(__func__);
914 void
915 jack_proxy::rewind_transport()
917 //info_msg(__func__);
920 void
921 jack_proxy::error_msg(const std::string& msg) const
923 _app->error_msg((std::string)"[JACKDBUS] " + msg);
926 void
927 jack_proxy::info_msg(const std::string& msg) const
929 _app->info_msg((std::string)"[JACKDBUS] " + msg);