1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation graph object that is backed 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 "graph_proxy.h"
31 struct list_head siblings
;
33 void (* clear
)(void * context
);
34 void (* client_appeared
)(void * context
, uint64_t id
, const char * name
);
35 void (* client_disappeared
)(void * context
, uint64_t id
);
36 void (* port_appeared
)(void * context
, uint64_t client_id
, uint64_t port_id
, const char * port_name
, bool is_input
, bool is_terminal
, bool is_midi
);
37 void (* port_renamed
)(void * context
, uint64_t client_id
, uint64_t port_id
, const char * old_port_name
, const char * new_port_name
);
38 void (* port_disappeared
)(void * context
, uint64_t client_id
, uint64_t port_id
);
39 void (* ports_connected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
);
40 void (* ports_disconnected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
);
45 struct list_head monitors
;
50 bool graph_dict_supported
;
53 static struct dbus_signal_hook g_signal_hooks
[];
55 static void clear(struct graph
* graph_ptr
)
57 struct list_head
* node_ptr
;
58 struct monitor
* monitor_ptr
;
60 list_for_each(node_ptr
, &graph_ptr
->monitors
)
62 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
63 monitor_ptr
->clear(monitor_ptr
->context
);
67 static void client_appeared(struct graph
* graph_ptr
, uint64_t id
, const char * name
)
69 struct list_head
* node_ptr
;
70 struct monitor
* monitor_ptr
;
72 list_for_each(node_ptr
, &graph_ptr
->monitors
)
74 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
75 monitor_ptr
->client_appeared(monitor_ptr
->context
, id
, name
);
79 static void client_disappeared(struct graph
* graph_ptr
, uint64_t id
)
81 struct list_head
* node_ptr
;
82 struct monitor
* monitor_ptr
;
84 list_for_each(node_ptr
, &graph_ptr
->monitors
)
86 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
87 monitor_ptr
->client_disappeared(monitor_ptr
->context
, id
);
94 struct graph
* graph_ptr
,
97 const char * port_name
,
101 struct list_head
* node_ptr
;
102 struct monitor
* monitor_ptr
;
107 if (port_type
!= JACKDBUS_PORT_TYPE_AUDIO
&& port_type
!= JACKDBUS_PORT_TYPE_MIDI
)
109 log_error("Unknown JACK D-Bus port type %d", (unsigned int)port_type
);
113 is_input
= port_flags
& JACKDBUS_PORT_FLAG_INPUT
;
114 is_terminal
= port_flags
& JACKDBUS_PORT_FLAG_TERMINAL
;
115 is_midi
= port_type
== JACKDBUS_PORT_TYPE_MIDI
;
117 list_for_each(node_ptr
, &graph_ptr
->monitors
)
119 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
120 monitor_ptr
->port_appeared(monitor_ptr
->context
, client_id
, port_id
, port_name
, is_input
, is_terminal
, is_midi
);
127 struct graph
* graph_ptr
,
131 struct list_head
* node_ptr
;
132 struct monitor
* monitor_ptr
;
134 list_for_each(node_ptr
, &graph_ptr
->monitors
)
136 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
137 monitor_ptr
->port_disappeared(monitor_ptr
->context
, client_id
, port_id
);
144 struct graph
* graph_ptr
,
147 const char * old_port_name
,
148 const char * new_port_name
)
150 struct list_head
* node_ptr
;
151 struct monitor
* monitor_ptr
;
153 list_for_each(node_ptr
, &graph_ptr
->monitors
)
155 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
156 monitor_ptr
->port_renamed(monitor_ptr
->context
, client_id
, port_id
, old_port_name
, new_port_name
);
163 struct graph
* graph_ptr
,
169 struct list_head
* node_ptr
;
170 struct monitor
* monitor_ptr
;
172 list_for_each(node_ptr
, &graph_ptr
->monitors
)
174 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
175 monitor_ptr
->ports_connected(monitor_ptr
->context
, client1_id
, port1_id
, client2_id
, port2_id
);
182 struct graph
* graph_ptr
,
188 struct list_head
* node_ptr
;
189 struct monitor
* monitor_ptr
;
191 list_for_each(node_ptr
, &graph_ptr
->monitors
)
193 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
194 monitor_ptr
->ports_disconnected(monitor_ptr
->context
, client1_id
, port1_id
, client2_id
, port2_id
);
198 static void refresh_internal(struct graph
* graph_ptr
, bool force
)
200 DBusMessage
* reply_ptr
;
201 DBusMessageIter iter
;
202 dbus_uint64_t version
;
203 const char * reply_signature
;
204 DBusMessageIter clients_array_iter
;
205 DBusMessageIter client_struct_iter
;
206 DBusMessageIter ports_array_iter
;
207 DBusMessageIter port_struct_iter
;
208 DBusMessageIter connections_array_iter
;
209 DBusMessageIter connection_struct_iter
;
210 dbus_uint64_t client_id
;
211 const char *client_name
;
212 dbus_uint64_t port_id
;
213 const char *port_name
;
214 dbus_uint32_t port_flags
;
215 dbus_uint32_t port_type
;
216 dbus_uint64_t client2_id
;
217 const char *client2_name
;
218 dbus_uint64_t port2_id
;
219 const char *port2_name
;
220 dbus_uint64_t connection_id
;
222 log_info("refresh_internal() called");
226 version
= 0; // workaround module split/join stupidity
230 version
= graph_ptr
->version
;
233 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "GetGraph", "t", &version
, NULL
, &reply_ptr
))
235 log_error("GetGraph() failed.");
239 reply_signature
= dbus_message_get_signature(reply_ptr
);
241 if (strcmp(reply_signature
, "ta(tsa(tsuu))a(tstststst)") != 0)
243 log_error("GetGraph() reply signature mismatch. '%s'", reply_signature
);
247 dbus_message_iter_init(reply_ptr
, &iter
);
249 //log_info_msg("version " + (char)dbus_message_iter_get_arg_type(&iter));
250 dbus_message_iter_get_basic(&iter
, &version
);
251 dbus_message_iter_next(&iter
);
253 if (!force
&& version
<= graph_ptr
->version
)
260 //log_info("got new graph version %llu", (unsigned long long)version);
261 graph_ptr
->version
= version
;
263 //info_msg((std::string)"clients " + (char)dbus_message_iter_get_arg_type(&iter));
265 for (dbus_message_iter_recurse(&iter
, &clients_array_iter
);
266 dbus_message_iter_get_arg_type(&clients_array_iter
) != DBUS_TYPE_INVALID
;
267 dbus_message_iter_next(&clients_array_iter
))
269 //info_msg((std::string)"a client " + (char)dbus_message_iter_get_arg_type(&clients_array_iter));
270 dbus_message_iter_recurse(&clients_array_iter
, &client_struct_iter
);
272 dbus_message_iter_get_basic(&client_struct_iter
, &client_id
);
273 dbus_message_iter_next(&client_struct_iter
);
275 dbus_message_iter_get_basic(&client_struct_iter
, &client_name
);
276 dbus_message_iter_next(&client_struct_iter
);
278 //info_msg((std::string)"client '" + client_name + "'");
280 client_appeared(graph_ptr
, client_id
, client_name
);
282 for (dbus_message_iter_recurse(&client_struct_iter
, &ports_array_iter
);
283 dbus_message_iter_get_arg_type(&ports_array_iter
) != DBUS_TYPE_INVALID
;
284 dbus_message_iter_next(&ports_array_iter
))
286 //info_msg((std::string)"a port " + (char)dbus_message_iter_get_arg_type(&ports_array_iter));
287 dbus_message_iter_recurse(&ports_array_iter
, &port_struct_iter
);
289 dbus_message_iter_get_basic(&port_struct_iter
, &port_id
);
290 dbus_message_iter_next(&port_struct_iter
);
292 dbus_message_iter_get_basic(&port_struct_iter
, &port_name
);
293 dbus_message_iter_next(&port_struct_iter
);
295 dbus_message_iter_get_basic(&port_struct_iter
, &port_flags
);
296 dbus_message_iter_next(&port_struct_iter
);
298 dbus_message_iter_get_basic(&port_struct_iter
, &port_type
);
299 dbus_message_iter_next(&port_struct_iter
);
301 //info_msg((std::string)"port: " + port_name);
303 port_appeared(graph_ptr
, client_id
, port_id
, port_name
, port_flags
, port_type
);
306 dbus_message_iter_next(&client_struct_iter
);
309 dbus_message_iter_next(&iter
);
311 for (dbus_message_iter_recurse(&iter
, &connections_array_iter
);
312 dbus_message_iter_get_arg_type(&connections_array_iter
) != DBUS_TYPE_INVALID
;
313 dbus_message_iter_next(&connections_array_iter
))
315 //info_msg((std::string)"a connection " + (char)dbus_message_iter_get_arg_type(&connections_array_iter));
316 dbus_message_iter_recurse(&connections_array_iter
, &connection_struct_iter
);
318 dbus_message_iter_get_basic(&connection_struct_iter
, &client_id
);
319 dbus_message_iter_next(&connection_struct_iter
);
321 dbus_message_iter_get_basic(&connection_struct_iter
, &client_name
);
322 dbus_message_iter_next(&connection_struct_iter
);
324 dbus_message_iter_get_basic(&connection_struct_iter
, &port_id
);
325 dbus_message_iter_next(&connection_struct_iter
);
327 dbus_message_iter_get_basic(&connection_struct_iter
, &port_name
);
328 dbus_message_iter_next(&connection_struct_iter
);
330 dbus_message_iter_get_basic(&connection_struct_iter
, &client2_id
);
331 dbus_message_iter_next(&connection_struct_iter
);
333 dbus_message_iter_get_basic(&connection_struct_iter
, &client2_name
);
334 dbus_message_iter_next(&connection_struct_iter
);
336 dbus_message_iter_get_basic(&connection_struct_iter
, &port2_id
);
337 dbus_message_iter_next(&connection_struct_iter
);
339 dbus_message_iter_get_basic(&connection_struct_iter
, &port2_name
);
340 dbus_message_iter_next(&connection_struct_iter
);
342 dbus_message_iter_get_basic(&connection_struct_iter
, &connection_id
);
343 dbus_message_iter_next(&connection_struct_iter
);
345 //info_msg(str(boost::format("connection(%llu) %s(%llu):%s(%llu) <-> %s(%llu):%s(%llu)") %
356 ports_connected(graph_ptr
, client_id
, port_id
, client2_id
, port2_id
);
360 dbus_message_unref(reply_ptr
);
365 const char * service
,
367 bool graph_dict_supported
,
368 graph_proxy_handle
* graph_proxy_handle_ptr
)
370 struct graph
* graph_ptr
;
372 graph_ptr
= malloc(sizeof(struct graph
));
373 if (graph_ptr
== NULL
)
375 log_error("malloc() failed to allocate struct graph");
379 graph_ptr
->service
= strdup(service
);
380 if (graph_ptr
->service
== NULL
)
382 log_error("strdup() failed too duplicate service name '%s'", service
);
386 graph_ptr
->object
= strdup(object
);
387 if (graph_ptr
->object
== NULL
)
389 log_error("strdup() failed too duplicate object name '%s'", object
);
393 INIT_LIST_HEAD(&graph_ptr
->monitors
);
395 graph_ptr
->version
= 0;
396 graph_ptr
->active
= false;
398 graph_ptr
->graph_dict_supported
= graph_dict_supported
;
400 *graph_proxy_handle_ptr
= (graph_proxy_handle
)graph_ptr
;
405 free(graph_ptr
->service
);
414 #define graph_ptr ((struct graph *)graph)
416 const char * graph_proxy_get_service(graph_proxy_handle graph
)
418 return graph_ptr
->service
;
421 const char * graph_proxy_get_object(graph_proxy_handle graph
)
423 return graph_ptr
->object
;
428 graph_proxy_handle graph
)
430 ASSERT(list_empty(&graph_ptr
->monitors
));
432 if (graph_ptr
->active
)
434 dbus_unregister_object_signal_hooks(
438 JACKDBUS_IFACE_PATCHBAY
);
441 free(graph_ptr
->object
);
442 free(graph_ptr
->service
);
447 graph_proxy_activate(
448 graph_proxy_handle graph
)
450 if (list_empty(&graph_ptr
->monitors
))
452 log_error("no monitors to activate");
456 if (graph_ptr
->active
)
458 log_error("graph already active");
462 if (!dbus_register_object_signal_hooks(
466 JACKDBUS_IFACE_PATCHBAY
,
473 graph_ptr
->active
= true;
475 refresh_internal(graph_ptr
, true);
482 graph_proxy_handle graph
,
484 void (* clear
)(void * context
),
485 void (* client_appeared
)(void * context
, uint64_t id
, const char * name
),
486 void (* client_disappeared
)(void * context
, uint64_t id
),
487 void (* port_appeared
)(void * context
, uint64_t client_id
, uint64_t port_id
, const char * port_name
, bool is_input
, bool is_terminal
, bool is_midi
),
488 void (* port_renamed
)(void * context
, uint64_t client_id
, uint64_t port_id
, const char * old_port_name
, const char * new_port_name
),
489 void (* port_disappeared
)(void * context
, uint64_t client_id
, uint64_t port_id
),
490 void (* ports_connected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
),
491 void (* ports_disconnected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
))
493 struct monitor
* monitor_ptr
;
495 if (graph_ptr
->active
)
500 monitor_ptr
= malloc(sizeof(struct monitor
));
501 if (monitor_ptr
== NULL
)
503 log_error("malloc() failed to allocate struct monitor");
507 monitor_ptr
->context
= context
;
508 monitor_ptr
->clear
= clear
;
509 monitor_ptr
->client_appeared
= client_appeared
;
510 monitor_ptr
->client_disappeared
= client_disappeared
;
511 monitor_ptr
->port_appeared
= port_appeared
;
512 monitor_ptr
->port_renamed
= port_renamed
;
513 monitor_ptr
->port_disappeared
= port_disappeared
;
514 monitor_ptr
->ports_connected
= ports_connected
;
515 monitor_ptr
->ports_disconnected
= ports_disconnected
;
517 list_add_tail(&monitor_ptr
->siblings
, &graph_ptr
->monitors
);
524 graph_proxy_handle graph
,
527 struct list_head
* node_ptr
;
528 struct monitor
* monitor_ptr
;
530 list_for_each(node_ptr
, &graph_ptr
->monitors
)
532 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
533 if (monitor_ptr
->context
== context
)
535 list_del(&monitor_ptr
->siblings
);
545 graph_proxy_connect_ports(
546 graph_proxy_handle graph
,
550 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "ConnectPortsByID", "tt", &port1_id
, &port2_id
, ""))
552 log_error("ConnectPortsByID() failed.");
557 graph_proxy_disconnect_ports(
558 graph_proxy_handle graph
,
562 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "DisconnectPortsByID", "tt", &port1_id
, &port2_id
, ""))
564 log_error("DisconnectPortsByID() failed.");
568 static void on_client_appeared(void * graph
, DBusMessage
* message_ptr
)
570 dbus_uint64_t new_graph_version
;
571 dbus_uint64_t client_id
;
572 const char * client_name
;
574 if (!dbus_message_get_args(
577 DBUS_TYPE_UINT64
, &new_graph_version
,
578 DBUS_TYPE_UINT64
, &client_id
,
579 DBUS_TYPE_STRING
, &client_name
,
582 log_error("dbus_message_get_args() failed to extract ClientAppeared signal arguments (%s)", g_dbus_error
.message
);
583 dbus_error_free(&g_dbus_error
);
587 //log_info("ClientAppeared, %s(%llu), graph %llu", client_name, client_id, new_graph_version);
589 if (new_graph_version
> graph_ptr
->version
)
591 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
592 graph_ptr
->version
= new_graph_version
;
593 client_appeared(graph_ptr
, client_id
, client_name
);
597 static void on_client_disappeared(void * graph
, DBusMessage
* message_ptr
)
599 dbus_uint64_t new_graph_version
;
600 dbus_uint64_t client_id
;
601 const char * client_name
;
603 if (!dbus_message_get_args(
606 DBUS_TYPE_UINT64
, &new_graph_version
,
607 DBUS_TYPE_UINT64
, &client_id
,
608 DBUS_TYPE_STRING
, &client_name
,
611 log_error("dbus_message_get_args() failed to extract ClientDisappeared signal arguments (%s)", g_dbus_error
.message
);
612 dbus_error_free(&g_dbus_error
);
616 //log_info("ClientDisappeared, %s(%llu)", client_name, client_id);
618 if (new_graph_version
> graph_ptr
->version
)
620 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
621 graph_ptr
->version
= new_graph_version
;
622 client_disappeared(graph_ptr
, client_id
);
626 static void on_port_appeared(void * graph
, DBusMessage
* message_ptr
)
628 dbus_uint64_t new_graph_version
;
629 dbus_uint64_t client_id
;
630 const char * client_name
;
631 dbus_uint64_t port_id
;
632 const char * port_name
;
633 dbus_uint32_t port_flags
;
634 dbus_uint32_t port_type
;
636 if (!dbus_message_get_args(
639 DBUS_TYPE_UINT64
, &new_graph_version
,
640 DBUS_TYPE_UINT64
, &client_id
,
641 DBUS_TYPE_STRING
, &client_name
,
642 DBUS_TYPE_UINT64
, &port_id
,
643 DBUS_TYPE_STRING
, &port_name
,
644 DBUS_TYPE_UINT32
, &port_flags
,
645 DBUS_TYPE_UINT32
, &port_type
,
648 log_error("dbus_message_get_args() failed to extract PortAppeared signal arguments (%s)", g_dbus_error
.message
);
649 dbus_error_free(&g_dbus_error
);
653 //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));
655 if (new_graph_version
> graph_ptr
->version
)
657 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
658 graph_ptr
->version
= new_graph_version
;
659 port_appeared(graph_ptr
, client_id
, port_id
, port_name
, port_flags
, port_type
);
663 static void on_port_renamed(void * graph
, DBusMessage
* message_ptr
)
665 dbus_uint64_t new_graph_version
;
666 dbus_uint64_t client_id
;
667 const char * client_name
;
668 dbus_uint64_t port_id
;
669 const char * old_port_name
;
670 const char * new_port_name
;
672 if (!dbus_message_get_args(
675 DBUS_TYPE_UINT64
, &new_graph_version
,
676 DBUS_TYPE_UINT64
, &client_id
,
677 DBUS_TYPE_STRING
, &client_name
,
678 DBUS_TYPE_UINT64
, &port_id
,
679 DBUS_TYPE_STRING
, &old_port_name
,
680 DBUS_TYPE_STRING
, &new_port_name
,
683 log_error("dbus_message_get_args() failed to extract PortRenamed signal arguments (%s)", g_dbus_error
.message
);
684 dbus_error_free(&g_dbus_error
);
688 if (new_graph_version
> graph_ptr
->version
)
690 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
691 graph_ptr
->version
= new_graph_version
;
692 port_renamed(graph_ptr
, client_id
, port_id
, old_port_name
, new_port_name
);
696 static void on_port_disappeared(void * graph
, DBusMessage
* message_ptr
)
698 dbus_uint64_t new_graph_version
;
699 dbus_uint64_t client_id
;
700 const char * client_name
;
701 dbus_uint64_t port_id
;
702 const char * port_name
;
704 if (!dbus_message_get_args(
707 DBUS_TYPE_UINT64
, &new_graph_version
,
708 DBUS_TYPE_UINT64
, &client_id
,
709 DBUS_TYPE_STRING
, &client_name
,
710 DBUS_TYPE_UINT64
, &port_id
,
711 DBUS_TYPE_STRING
, &port_name
,
714 log_error("dbus_message_get_args() failed to extract PortDisappeared signal arguments (%s)", g_dbus_error
.message
);
715 dbus_error_free(&g_dbus_error
);
719 //me->info_msg(str(boost::format("PortDisappeared, %s(%llu):%s(%llu)") % client_name % client_id % port_name % port_id));
721 if (new_graph_version
> graph_ptr
->version
)
723 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
724 graph_ptr
->version
= new_graph_version
;
725 port_disappeared(graph_ptr
, client_id
, port_id
);
729 static void on_ports_connected(void * graph
, DBusMessage
* message_ptr
)
731 dbus_uint64_t new_graph_version
;
732 dbus_uint64_t client_id
;
733 const char * client_name
;
734 dbus_uint64_t port_id
;
735 const char * port_name
;
736 dbus_uint64_t client2_id
;
737 const char * client2_name
;
738 dbus_uint64_t port2_id
;
739 const char * port2_name
;
740 dbus_uint64_t connection_id
;
742 if (!dbus_message_get_args(
745 DBUS_TYPE_UINT64
, &new_graph_version
,
746 DBUS_TYPE_UINT64
, &client_id
,
747 DBUS_TYPE_STRING
, &client_name
,
748 DBUS_TYPE_UINT64
, &port_id
,
749 DBUS_TYPE_STRING
, &port_name
,
750 DBUS_TYPE_UINT64
, &client2_id
,
751 DBUS_TYPE_STRING
, &client2_name
,
752 DBUS_TYPE_UINT64
, &port2_id
,
753 DBUS_TYPE_STRING
, &port2_name
,
754 DBUS_TYPE_UINT64
, &connection_id
,
757 log_error("dbus_message_get_args() failed to extract PortsConnected signal arguments (%s)", g_dbus_error
.message
);
758 dbus_error_free(&g_dbus_error
);
762 if (new_graph_version
> graph_ptr
->version
)
764 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
765 graph_ptr
->version
= new_graph_version
;
766 ports_connected(graph_ptr
, client_id
, port_id
, client2_id
, port2_id
);
770 static void on_ports_disconnected(void * graph
, DBusMessage
* message_ptr
)
772 dbus_uint64_t new_graph_version
;
773 dbus_uint64_t client_id
;
774 const char * client_name
;
775 dbus_uint64_t port_id
;
776 const char * port_name
;
777 dbus_uint64_t client2_id
;
778 const char * client2_name
;
779 dbus_uint64_t port2_id
;
780 const char * port2_name
;
781 dbus_uint64_t connection_id
;
783 if (!dbus_message_get_args(
786 DBUS_TYPE_UINT64
, &new_graph_version
,
787 DBUS_TYPE_UINT64
, &client_id
,
788 DBUS_TYPE_STRING
, &client_name
,
789 DBUS_TYPE_UINT64
, &port_id
,
790 DBUS_TYPE_STRING
, &port_name
,
791 DBUS_TYPE_UINT64
, &client2_id
,
792 DBUS_TYPE_STRING
, &client2_name
,
793 DBUS_TYPE_UINT64
, &port2_id
,
794 DBUS_TYPE_STRING
, &port2_name
,
795 DBUS_TYPE_UINT64
, &connection_id
,
798 log_error("dbus_message_get_args() failed to extract PortsConnected signal arguments (%s)", g_dbus_error
.message
);
799 dbus_error_free(&g_dbus_error
);
803 if (new_graph_version
> graph_ptr
->version
)
805 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
806 graph_ptr
->version
= new_graph_version
;
807 ports_disconnected(graph_ptr
, client_id
, port_id
, client2_id
, port2_id
);
812 graph_proxy_dict_entry_set(
813 graph_proxy_handle graph
,
814 uint32_t object_type
,
819 if (!graph_ptr
->graph_dict_supported
)
824 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_DICT
, "Set", "utss", &object_type
, &object_id
, &key
, &value
, ""))
826 log_error(IFACE_GRAPH_DICT
".Set() failed.");
834 graph_proxy_dict_entry_get(
835 graph_proxy_handle graph
,
836 uint32_t object_type
,
839 char ** value_ptr_ptr
)
841 DBusMessage
* reply_ptr
;
842 const char * reply_signature
;
843 DBusMessageIter iter
;
844 const char * cvalue_ptr
;
847 if (!graph_ptr
->graph_dict_supported
)
852 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_DICT
, "Get", "uts", &object_type
, &object_id
, &key
, NULL
, &reply_ptr
))
854 log_error(IFACE_GRAPH_DICT
".Get() failed.");
858 reply_signature
= dbus_message_get_signature(reply_ptr
);
860 if (strcmp(reply_signature
, "s") != 0)
862 log_error("reply signature is '%s' but expected signature is 's'", reply_signature
);
863 dbus_message_unref(reply_ptr
);
867 dbus_message_iter_init(reply_ptr
, &iter
);
868 dbus_message_iter_get_basic(&iter
, &cvalue_ptr
);
869 value_ptr
= strdup(cvalue_ptr
);
870 dbus_message_unref(reply_ptr
);
871 if (value_ptr
== NULL
)
873 log_error("strdup() failed for dict value");
876 *value_ptr_ptr
= value_ptr
;
881 graph_proxy_dict_entry_drop(
882 graph_proxy_handle graph
,
883 uint32_t object_type
,
887 if (!graph_ptr
->graph_dict_supported
)
892 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_DICT
, "Drop", "uts", &object_type
, &object_id
, &key
, ""))
894 log_error(IFACE_GRAPH_DICT
".Drop() failed.");
901 bool graph_proxy_get_client_pid(graph_proxy_handle graph
, uint64_t client_id
, int64_t * pid_ptr
)
903 if (!dbus_call(graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "GetClientPID", "t", &client_id
, "x", pid_ptr
))
905 log_error("GetClientPID() failed.");
912 /* this must be static because it is referenced by the
913 * dbus helper layer when hooks are active */
914 static struct dbus_signal_hook g_signal_hooks
[] =
916 {"ClientAppeared", on_client_appeared
},
917 {"ClientDisappeared", on_client_disappeared
},
918 {"PortAppeared", on_port_appeared
},
919 {"PortRenamed", on_port_renamed
},
920 {"PortDisappeared", on_port_disappeared
},
921 {"PortsConnected", on_ports_connected
},
922 {"PortsDisconnected", on_ports_disconnected
},