1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009,2010,2011 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_renamed
)(void * context
, uint64_t client_id
, const char * old_client_name
, const char * new_client_name
);
36 void (* client_disappeared
)(void * context
, uint64_t id
);
37 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
);
38 void (* port_renamed
)(void * context
, uint64_t client_id
, uint64_t port_id
, const char * old_port_name
, const char * new_port_name
);
39 void (* port_disappeared
)(void * context
, uint64_t client_id
, uint64_t port_id
);
40 void (* ports_connected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
);
41 void (* ports_disconnected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
);
46 struct list_head monitors
;
51 bool graph_dict_supported
;
52 bool graph_manager_supported
;
55 static struct cdbus_signal_hook g_signal_hooks
[];
57 static void clear(struct graph
* graph_ptr
)
59 struct list_head
* node_ptr
;
60 struct monitor
* monitor_ptr
;
62 list_for_each(node_ptr
, &graph_ptr
->monitors
)
64 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
65 monitor_ptr
->clear(monitor_ptr
->context
);
69 static void client_appeared(struct graph
* graph_ptr
, uint64_t id
, const char * name
)
71 struct list_head
* node_ptr
;
72 struct monitor
* monitor_ptr
;
74 list_for_each(node_ptr
, &graph_ptr
->monitors
)
76 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
77 monitor_ptr
->client_appeared(monitor_ptr
->context
, id
, name
);
84 struct graph
* graph_ptr
,
86 const char * old_client_name
,
87 const char * new_client_name
)
89 struct list_head
* node_ptr
;
90 struct monitor
* monitor_ptr
;
92 list_for_each(node_ptr
, &graph_ptr
->monitors
)
94 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
95 if (monitor_ptr
->client_renamed
!= NULL
)
97 monitor_ptr
->client_renamed(monitor_ptr
->context
, client_id
, old_client_name
, new_client_name
);
102 static void client_disappeared(struct graph
* graph_ptr
, uint64_t id
)
104 struct list_head
* node_ptr
;
105 struct monitor
* monitor_ptr
;
107 list_for_each(node_ptr
, &graph_ptr
->monitors
)
109 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
110 monitor_ptr
->client_disappeared(monitor_ptr
->context
, id
);
117 struct graph
* graph_ptr
,
120 const char * port_name
,
124 struct list_head
* node_ptr
;
125 struct monitor
* monitor_ptr
;
130 if (port_type
!= JACKDBUS_PORT_TYPE_AUDIO
&& port_type
!= JACKDBUS_PORT_TYPE_MIDI
)
132 log_error("Unknown JACK D-Bus port type %d", (unsigned int)port_type
);
136 is_input
= port_flags
& JACKDBUS_PORT_FLAG_INPUT
;
137 is_terminal
= port_flags
& JACKDBUS_PORT_FLAG_TERMINAL
;
138 is_midi
= port_type
== JACKDBUS_PORT_TYPE_MIDI
;
140 list_for_each(node_ptr
, &graph_ptr
->monitors
)
142 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
143 monitor_ptr
->port_appeared(monitor_ptr
->context
, client_id
, port_id
, port_name
, is_input
, is_terminal
, is_midi
);
150 struct graph
* graph_ptr
,
154 struct list_head
* node_ptr
;
155 struct monitor
* monitor_ptr
;
157 list_for_each(node_ptr
, &graph_ptr
->monitors
)
159 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
160 monitor_ptr
->port_disappeared(monitor_ptr
->context
, client_id
, port_id
);
167 struct graph
* graph_ptr
,
170 const char * old_port_name
,
171 const char * new_port_name
)
173 struct list_head
* node_ptr
;
174 struct monitor
* monitor_ptr
;
176 list_for_each(node_ptr
, &graph_ptr
->monitors
)
178 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
179 monitor_ptr
->port_renamed(monitor_ptr
->context
, client_id
, port_id
, old_port_name
, new_port_name
);
186 struct graph
* graph_ptr
,
192 struct list_head
* node_ptr
;
193 struct monitor
* monitor_ptr
;
195 list_for_each(node_ptr
, &graph_ptr
->monitors
)
197 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
198 monitor_ptr
->ports_connected(monitor_ptr
->context
, client1_id
, port1_id
, client2_id
, port2_id
);
205 struct graph
* graph_ptr
,
211 struct list_head
* node_ptr
;
212 struct monitor
* monitor_ptr
;
214 list_for_each(node_ptr
, &graph_ptr
->monitors
)
216 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
217 monitor_ptr
->ports_disconnected(monitor_ptr
->context
, client1_id
, port1_id
, client2_id
, port2_id
);
221 static void refresh_internal(struct graph
* graph_ptr
, bool force
)
223 DBusMessage
* reply_ptr
;
224 DBusMessageIter iter
;
225 dbus_uint64_t version
;
226 const char * reply_signature
;
227 DBusMessageIter clients_array_iter
;
228 DBusMessageIter client_struct_iter
;
229 DBusMessageIter ports_array_iter
;
230 DBusMessageIter port_struct_iter
;
231 DBusMessageIter connections_array_iter
;
232 DBusMessageIter connection_struct_iter
;
233 dbus_uint64_t client_id
;
234 const char *client_name
;
235 dbus_uint64_t port_id
;
236 const char *port_name
;
237 dbus_uint32_t port_flags
;
238 dbus_uint32_t port_type
;
239 dbus_uint64_t client2_id
;
240 const char *client2_name
;
241 dbus_uint64_t port2_id
;
242 const char *port2_name
;
243 dbus_uint64_t connection_id
;
245 log_info("refresh_internal() called");
249 version
= 0; // workaround module split/join stupidity
253 version
= graph_ptr
->version
;
256 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "GetGraph", "t", &version
, NULL
, &reply_ptr
))
258 log_error("GetGraph() failed.");
262 reply_signature
= dbus_message_get_signature(reply_ptr
);
264 if (strcmp(reply_signature
, "ta(tsa(tsuu))a(tstststst)") != 0)
266 log_error("GetGraph() reply signature mismatch. '%s'", reply_signature
);
270 dbus_message_iter_init(reply_ptr
, &iter
);
272 //log_info_msg("version " + (char)dbus_message_iter_get_arg_type(&iter));
273 dbus_message_iter_get_basic(&iter
, &version
);
274 dbus_message_iter_next(&iter
);
276 if (!force
&& version
<= graph_ptr
->version
)
283 //log_info("got new graph version %llu", (unsigned long long)version);
284 graph_ptr
->version
= version
;
286 //info_msg((std::string)"clients " + (char)dbus_message_iter_get_arg_type(&iter));
288 for (dbus_message_iter_recurse(&iter
, &clients_array_iter
);
289 dbus_message_iter_get_arg_type(&clients_array_iter
) != DBUS_TYPE_INVALID
;
290 dbus_message_iter_next(&clients_array_iter
))
292 //info_msg((std::string)"a client " + (char)dbus_message_iter_get_arg_type(&clients_array_iter));
293 dbus_message_iter_recurse(&clients_array_iter
, &client_struct_iter
);
295 dbus_message_iter_get_basic(&client_struct_iter
, &client_id
);
296 dbus_message_iter_next(&client_struct_iter
);
298 dbus_message_iter_get_basic(&client_struct_iter
, &client_name
);
299 dbus_message_iter_next(&client_struct_iter
);
301 //info_msg((std::string)"client '" + client_name + "'");
303 client_appeared(graph_ptr
, client_id
, client_name
);
305 for (dbus_message_iter_recurse(&client_struct_iter
, &ports_array_iter
);
306 dbus_message_iter_get_arg_type(&ports_array_iter
) != DBUS_TYPE_INVALID
;
307 dbus_message_iter_next(&ports_array_iter
))
309 //info_msg((std::string)"a port " + (char)dbus_message_iter_get_arg_type(&ports_array_iter));
310 dbus_message_iter_recurse(&ports_array_iter
, &port_struct_iter
);
312 dbus_message_iter_get_basic(&port_struct_iter
, &port_id
);
313 dbus_message_iter_next(&port_struct_iter
);
315 dbus_message_iter_get_basic(&port_struct_iter
, &port_name
);
316 dbus_message_iter_next(&port_struct_iter
);
318 dbus_message_iter_get_basic(&port_struct_iter
, &port_flags
);
319 dbus_message_iter_next(&port_struct_iter
);
321 dbus_message_iter_get_basic(&port_struct_iter
, &port_type
);
322 dbus_message_iter_next(&port_struct_iter
);
324 //info_msg((std::string)"port: " + port_name);
326 port_appeared(graph_ptr
, client_id
, port_id
, port_name
, port_flags
, port_type
);
329 dbus_message_iter_next(&client_struct_iter
);
332 dbus_message_iter_next(&iter
);
334 for (dbus_message_iter_recurse(&iter
, &connections_array_iter
);
335 dbus_message_iter_get_arg_type(&connections_array_iter
) != DBUS_TYPE_INVALID
;
336 dbus_message_iter_next(&connections_array_iter
))
338 //info_msg((std::string)"a connection " + (char)dbus_message_iter_get_arg_type(&connections_array_iter));
339 dbus_message_iter_recurse(&connections_array_iter
, &connection_struct_iter
);
341 dbus_message_iter_get_basic(&connection_struct_iter
, &client_id
);
342 dbus_message_iter_next(&connection_struct_iter
);
344 dbus_message_iter_get_basic(&connection_struct_iter
, &client_name
);
345 dbus_message_iter_next(&connection_struct_iter
);
347 dbus_message_iter_get_basic(&connection_struct_iter
, &port_id
);
348 dbus_message_iter_next(&connection_struct_iter
);
350 dbus_message_iter_get_basic(&connection_struct_iter
, &port_name
);
351 dbus_message_iter_next(&connection_struct_iter
);
353 dbus_message_iter_get_basic(&connection_struct_iter
, &client2_id
);
354 dbus_message_iter_next(&connection_struct_iter
);
356 dbus_message_iter_get_basic(&connection_struct_iter
, &client2_name
);
357 dbus_message_iter_next(&connection_struct_iter
);
359 dbus_message_iter_get_basic(&connection_struct_iter
, &port2_id
);
360 dbus_message_iter_next(&connection_struct_iter
);
362 dbus_message_iter_get_basic(&connection_struct_iter
, &port2_name
);
363 dbus_message_iter_next(&connection_struct_iter
);
365 dbus_message_iter_get_basic(&connection_struct_iter
, &connection_id
);
366 dbus_message_iter_next(&connection_struct_iter
);
368 //info_msg(str(boost::format("connection(%llu) %s(%llu):%s(%llu) <-> %s(%llu):%s(%llu)") %
379 ports_connected(graph_ptr
, client_id
, port_id
, client2_id
, port2_id
);
383 dbus_message_unref(reply_ptr
);
388 const char * service
,
390 bool graph_dict_supported
,
391 bool graph_manager_supported
,
392 graph_proxy_handle
* graph_proxy_handle_ptr
)
394 struct graph
* graph_ptr
;
396 graph_ptr
= malloc(sizeof(struct graph
));
397 if (graph_ptr
== NULL
)
399 log_error("malloc() failed to allocate struct graph");
403 graph_ptr
->service
= strdup(service
);
404 if (graph_ptr
->service
== NULL
)
406 log_error("strdup() failed too duplicate service name '%s'", service
);
410 graph_ptr
->object
= strdup(object
);
411 if (graph_ptr
->object
== NULL
)
413 log_error("strdup() failed too duplicate object name '%s'", object
);
417 INIT_LIST_HEAD(&graph_ptr
->monitors
);
419 graph_ptr
->version
= 0;
420 graph_ptr
->active
= false;
422 graph_ptr
->graph_dict_supported
= graph_dict_supported
;
423 graph_ptr
->graph_manager_supported
= graph_manager_supported
;
425 *graph_proxy_handle_ptr
= (graph_proxy_handle
)graph_ptr
;
430 free(graph_ptr
->service
);
439 #define graph_ptr ((struct graph *)graph)
441 const char * graph_proxy_get_service(graph_proxy_handle graph
)
443 return graph_ptr
->service
;
446 const char * graph_proxy_get_object(graph_proxy_handle graph
)
448 return graph_ptr
->object
;
453 graph_proxy_handle graph
)
455 ASSERT(list_empty(&graph_ptr
->monitors
));
457 if (graph_ptr
->active
)
459 cdbus_unregister_object_signal_hooks(
460 cdbus_g_dbus_connection
,
463 JACKDBUS_IFACE_PATCHBAY
);
466 free(graph_ptr
->object
);
467 free(graph_ptr
->service
);
472 graph_proxy_activate(
473 graph_proxy_handle graph
)
475 if (list_empty(&graph_ptr
->monitors
))
477 log_error("no monitors to activate");
481 if (graph_ptr
->active
)
483 log_error("graph already active");
487 if (!cdbus_register_object_signal_hooks(
488 cdbus_g_dbus_connection
,
491 JACKDBUS_IFACE_PATCHBAY
,
498 graph_ptr
->active
= true;
500 refresh_internal(graph_ptr
, true);
507 graph_proxy_handle graph
,
509 void (* clear
)(void * context
),
510 void (* client_appeared
)(void * context
, uint64_t id
, const char * name
),
511 void (* client_renamed
)(void * context
, uint64_t client_id
, const char * old_client_name
, const char * new_client_name
),
512 void (* client_disappeared
)(void * context
, uint64_t id
),
513 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
),
514 void (* port_renamed
)(void * context
, uint64_t client_id
, uint64_t port_id
, const char * old_port_name
, const char * new_port_name
),
515 void (* port_disappeared
)(void * context
, uint64_t client_id
, uint64_t port_id
),
516 void (* ports_connected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
),
517 void (* ports_disconnected
)(void * context
, uint64_t client1_id
, uint64_t port1_id
, uint64_t client2_id
, uint64_t port2_id
))
519 struct monitor
* monitor_ptr
;
521 if (graph_ptr
->active
)
526 monitor_ptr
= malloc(sizeof(struct monitor
));
527 if (monitor_ptr
== NULL
)
529 log_error("malloc() failed to allocate struct monitor");
533 monitor_ptr
->context
= context
;
534 monitor_ptr
->clear
= clear
;
535 monitor_ptr
->client_appeared
= client_appeared
;
536 monitor_ptr
->client_renamed
= client_renamed
;
537 monitor_ptr
->client_disappeared
= client_disappeared
;
538 monitor_ptr
->port_appeared
= port_appeared
;
539 monitor_ptr
->port_renamed
= port_renamed
;
540 monitor_ptr
->port_disappeared
= port_disappeared
;
541 monitor_ptr
->ports_connected
= ports_connected
;
542 monitor_ptr
->ports_disconnected
= ports_disconnected
;
544 list_add_tail(&monitor_ptr
->siblings
, &graph_ptr
->monitors
);
551 graph_proxy_handle graph
,
554 struct list_head
* node_ptr
;
555 struct monitor
* monitor_ptr
;
557 list_for_each(node_ptr
, &graph_ptr
->monitors
)
559 monitor_ptr
= list_entry(node_ptr
, struct monitor
, siblings
);
560 if (monitor_ptr
->context
== context
)
562 list_del(&monitor_ptr
->siblings
);
572 graph_proxy_connect_ports(
573 graph_proxy_handle graph
,
577 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "ConnectPortsByID", "tt", &port1_id
, &port2_id
, ""))
579 log_error("ConnectPortsByID() failed.");
587 graph_proxy_disconnect_ports(
588 graph_proxy_handle graph
,
592 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "DisconnectPortsByID", "tt", &port1_id
, &port2_id
, ""))
594 log_error("DisconnectPortsByID() failed.");
601 static void on_client_appeared(void * graph
, DBusMessage
* message_ptr
)
603 dbus_uint64_t new_graph_version
;
604 dbus_uint64_t client_id
;
605 const char * client_name
;
607 if (!dbus_message_get_args(
610 DBUS_TYPE_UINT64
, &new_graph_version
,
611 DBUS_TYPE_UINT64
, &client_id
,
612 DBUS_TYPE_STRING
, &client_name
,
615 log_error("dbus_message_get_args() failed to extract ClientAppeared signal arguments (%s)", cdbus_g_dbus_error
.message
);
616 dbus_error_free(&cdbus_g_dbus_error
);
620 //log_info("ClientAppeared, %s(%llu), graph %llu", client_name, client_id, new_graph_version);
622 if (new_graph_version
> graph_ptr
->version
)
624 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
625 graph_ptr
->version
= new_graph_version
;
626 client_appeared(graph_ptr
, client_id
, client_name
);
630 static void on_client_renamed(void * graph
, DBusMessage
* message_ptr
)
632 dbus_uint64_t new_graph_version
;
633 dbus_uint64_t client_id
;
634 const char * old_client_name
;
635 const char * new_client_name
;
637 if (!dbus_message_get_args(
640 DBUS_TYPE_UINT64
, &new_graph_version
,
641 DBUS_TYPE_UINT64
, &client_id
,
642 DBUS_TYPE_STRING
, &old_client_name
,
643 DBUS_TYPE_STRING
, &new_client_name
,
646 log_error("dbus_message_get_args() failed to extract ClientRenamed signal arguments (%s)", cdbus_g_dbus_error
.message
);
647 dbus_error_free(&cdbus_g_dbus_error
);
651 if (new_graph_version
> graph_ptr
->version
)
653 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
654 graph_ptr
->version
= new_graph_version
;
655 client_renamed(graph_ptr
, client_id
, old_client_name
, new_client_name
);
659 static void on_client_disappeared(void * graph
, DBusMessage
* message_ptr
)
661 dbus_uint64_t new_graph_version
;
662 dbus_uint64_t client_id
;
663 const char * client_name
;
665 if (!dbus_message_get_args(
668 DBUS_TYPE_UINT64
, &new_graph_version
,
669 DBUS_TYPE_UINT64
, &client_id
,
670 DBUS_TYPE_STRING
, &client_name
,
673 log_error("dbus_message_get_args() failed to extract ClientDisappeared signal arguments (%s)", cdbus_g_dbus_error
.message
);
674 dbus_error_free(&cdbus_g_dbus_error
);
678 //log_info("ClientDisappeared, %s(%llu)", client_name, client_id);
680 if (new_graph_version
> graph_ptr
->version
)
682 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
683 graph_ptr
->version
= new_graph_version
;
684 client_disappeared(graph_ptr
, client_id
);
688 static void on_port_appeared(void * graph
, DBusMessage
* message_ptr
)
690 dbus_uint64_t new_graph_version
;
691 dbus_uint64_t client_id
;
692 const char * client_name
;
693 dbus_uint64_t port_id
;
694 const char * port_name
;
695 dbus_uint32_t port_flags
;
696 dbus_uint32_t port_type
;
698 if (!dbus_message_get_args(
701 DBUS_TYPE_UINT64
, &new_graph_version
,
702 DBUS_TYPE_UINT64
, &client_id
,
703 DBUS_TYPE_STRING
, &client_name
,
704 DBUS_TYPE_UINT64
, &port_id
,
705 DBUS_TYPE_STRING
, &port_name
,
706 DBUS_TYPE_UINT32
, &port_flags
,
707 DBUS_TYPE_UINT32
, &port_type
,
710 log_error("dbus_message_get_args() failed to extract PortAppeared signal arguments (%s)", cdbus_g_dbus_error
.message
);
711 dbus_error_free(&cdbus_g_dbus_error
);
715 //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));
717 if (new_graph_version
> graph_ptr
->version
)
719 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
720 graph_ptr
->version
= new_graph_version
;
721 port_appeared(graph_ptr
, client_id
, port_id
, port_name
, port_flags
, port_type
);
725 static void on_port_renamed(void * graph
, DBusMessage
* message_ptr
)
727 dbus_uint64_t new_graph_version
;
728 dbus_uint64_t client_id
;
729 const char * client_name
;
730 dbus_uint64_t port_id
;
731 const char * old_port_name
;
732 const char * new_port_name
;
734 if (!dbus_message_get_args(
737 DBUS_TYPE_UINT64
, &new_graph_version
,
738 DBUS_TYPE_UINT64
, &client_id
,
739 DBUS_TYPE_STRING
, &client_name
,
740 DBUS_TYPE_UINT64
, &port_id
,
741 DBUS_TYPE_STRING
, &old_port_name
,
742 DBUS_TYPE_STRING
, &new_port_name
,
745 log_error("dbus_message_get_args() failed to extract PortRenamed signal arguments (%s)", cdbus_g_dbus_error
.message
);
746 dbus_error_free(&cdbus_g_dbus_error
);
750 if (new_graph_version
> graph_ptr
->version
)
752 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
753 graph_ptr
->version
= new_graph_version
;
754 port_renamed(graph_ptr
, client_id
, port_id
, old_port_name
, new_port_name
);
758 static void on_port_disappeared(void * graph
, DBusMessage
* message_ptr
)
760 dbus_uint64_t new_graph_version
;
761 dbus_uint64_t client_id
;
762 const char * client_name
;
763 dbus_uint64_t port_id
;
764 const char * port_name
;
766 if (!dbus_message_get_args(
769 DBUS_TYPE_UINT64
, &new_graph_version
,
770 DBUS_TYPE_UINT64
, &client_id
,
771 DBUS_TYPE_STRING
, &client_name
,
772 DBUS_TYPE_UINT64
, &port_id
,
773 DBUS_TYPE_STRING
, &port_name
,
776 log_error("dbus_message_get_args() failed to extract PortDisappeared signal arguments (%s)", cdbus_g_dbus_error
.message
);
777 dbus_error_free(&cdbus_g_dbus_error
);
781 //me->info_msg(str(boost::format("PortDisappeared, %s(%llu):%s(%llu)") % client_name % client_id % port_name % port_id));
783 if (new_graph_version
> graph_ptr
->version
)
785 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
786 graph_ptr
->version
= new_graph_version
;
787 port_disappeared(graph_ptr
, client_id
, port_id
);
791 static void on_ports_connected(void * graph
, DBusMessage
* message_ptr
)
793 dbus_uint64_t new_graph_version
;
794 dbus_uint64_t client_id
;
795 const char * client_name
;
796 dbus_uint64_t port_id
;
797 const char * port_name
;
798 dbus_uint64_t client2_id
;
799 const char * client2_name
;
800 dbus_uint64_t port2_id
;
801 const char * port2_name
;
802 dbus_uint64_t connection_id
;
804 if (!dbus_message_get_args(
807 DBUS_TYPE_UINT64
, &new_graph_version
,
808 DBUS_TYPE_UINT64
, &client_id
,
809 DBUS_TYPE_STRING
, &client_name
,
810 DBUS_TYPE_UINT64
, &port_id
,
811 DBUS_TYPE_STRING
, &port_name
,
812 DBUS_TYPE_UINT64
, &client2_id
,
813 DBUS_TYPE_STRING
, &client2_name
,
814 DBUS_TYPE_UINT64
, &port2_id
,
815 DBUS_TYPE_STRING
, &port2_name
,
816 DBUS_TYPE_UINT64
, &connection_id
,
819 log_error("dbus_message_get_args() failed to extract PortsConnected signal arguments (%s)", cdbus_g_dbus_error
.message
);
820 dbus_error_free(&cdbus_g_dbus_error
);
824 if (new_graph_version
> graph_ptr
->version
)
826 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
827 graph_ptr
->version
= new_graph_version
;
828 ports_connected(graph_ptr
, client_id
, port_id
, client2_id
, port2_id
);
832 static void on_ports_disconnected(void * graph
, DBusMessage
* message_ptr
)
834 dbus_uint64_t new_graph_version
;
835 dbus_uint64_t client_id
;
836 const char * client_name
;
837 dbus_uint64_t port_id
;
838 const char * port_name
;
839 dbus_uint64_t client2_id
;
840 const char * client2_name
;
841 dbus_uint64_t port2_id
;
842 const char * port2_name
;
843 dbus_uint64_t connection_id
;
845 if (!dbus_message_get_args(
848 DBUS_TYPE_UINT64
, &new_graph_version
,
849 DBUS_TYPE_UINT64
, &client_id
,
850 DBUS_TYPE_STRING
, &client_name
,
851 DBUS_TYPE_UINT64
, &port_id
,
852 DBUS_TYPE_STRING
, &port_name
,
853 DBUS_TYPE_UINT64
, &client2_id
,
854 DBUS_TYPE_STRING
, &client2_name
,
855 DBUS_TYPE_UINT64
, &port2_id
,
856 DBUS_TYPE_STRING
, &port2_name
,
857 DBUS_TYPE_UINT64
, &connection_id
,
860 log_error("dbus_message_get_args() failed to extract PortsConnected signal arguments (%s)", cdbus_g_dbus_error
.message
);
861 dbus_error_free(&cdbus_g_dbus_error
);
865 if (new_graph_version
> graph_ptr
->version
)
867 //log_info("got new graph version %llu", (unsigned long long)new_graph_version);
868 graph_ptr
->version
= new_graph_version
;
869 ports_disconnected(graph_ptr
, client_id
, port_id
, client2_id
, port2_id
);
874 graph_proxy_dict_entry_set(
875 graph_proxy_handle graph
,
876 uint32_t object_type
,
881 if (!graph_ptr
->graph_dict_supported
)
886 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_DICT
, "Set", "utss", &object_type
, &object_id
, &key
, &value
, ""))
888 log_error(IFACE_GRAPH_DICT
".Set() failed.");
896 graph_proxy_dict_entry_get(
897 graph_proxy_handle graph
,
898 uint32_t object_type
,
901 char ** value_ptr_ptr
)
903 DBusMessage
* reply_ptr
;
904 const char * reply_signature
;
905 DBusMessageIter iter
;
906 const char * cvalue_ptr
;
909 if (!graph_ptr
->graph_dict_supported
)
914 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_DICT
, "Get", "uts", &object_type
, &object_id
, &key
, NULL
, &reply_ptr
))
916 log_error(IFACE_GRAPH_DICT
".Get() failed.");
920 reply_signature
= dbus_message_get_signature(reply_ptr
);
922 if (strcmp(reply_signature
, "s") != 0)
924 log_error("reply signature is '%s' but expected signature is 's'", reply_signature
);
925 dbus_message_unref(reply_ptr
);
929 dbus_message_iter_init(reply_ptr
, &iter
);
930 dbus_message_iter_get_basic(&iter
, &cvalue_ptr
);
931 value_ptr
= strdup(cvalue_ptr
);
932 dbus_message_unref(reply_ptr
);
933 if (value_ptr
== NULL
)
935 log_error("strdup() failed for dict value");
938 *value_ptr_ptr
= value_ptr
;
943 graph_proxy_dict_entry_drop(
944 graph_proxy_handle graph
,
945 uint32_t object_type
,
949 if (!graph_ptr
->graph_dict_supported
)
954 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_DICT
, "Drop", "uts", &object_type
, &object_id
, &key
, ""))
956 log_error(IFACE_GRAPH_DICT
".Drop() failed.");
963 bool graph_proxy_get_client_pid(graph_proxy_handle graph
, uint64_t client_id
, pid_t
* pid_ptr
)
967 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, JACKDBUS_IFACE_PATCHBAY
, "GetClientPID", "t", &client_id
, "x", &pid
))
969 log_error("GetClientPID() failed.");
980 graph_proxy_handle graph
,
983 if (!graph_ptr
->graph_manager_supported
)
988 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "Split", "t", &client_id
, ""))
990 log_error(IFACE_GRAPH_MANAGER
".Split() failed.");
999 graph_proxy_handle graph
,
1000 uint64_t client1_id
,
1001 uint64_t client2_id
)
1003 if (!graph_ptr
->graph_manager_supported
)
1008 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "Join", "tt", &client1_id
, &client2_id
, ""))
1010 log_error(IFACE_GRAPH_MANAGER
".Join() failed.");
1018 graph_proxy_rename_client(
1019 graph_proxy_handle graph
,
1021 const char * newname
)
1023 if (!graph_ptr
->graph_manager_supported
)
1028 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "RenameClient", "ts", &client_id
, &newname
, ""))
1030 log_error(IFACE_GRAPH_MANAGER
".RenameClient() failed.");
1038 graph_proxy_rename_port(
1039 graph_proxy_handle graph
,
1041 const char * newname
)
1043 if (!graph_ptr
->graph_manager_supported
)
1048 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "RenamePort", "ts", &port_id
, &newname
, ""))
1050 log_error(IFACE_GRAPH_MANAGER
".RenamePort() failed.");
1058 graph_proxy_move_port(
1059 graph_proxy_handle graph
,
1063 if (!graph_ptr
->graph_manager_supported
)
1068 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "MovePort", "tt", &port_id
, &client_id
, ""))
1070 log_error(IFACE_GRAPH_MANAGER
".MovePort() failed.");
1078 graph_proxy_new_client(
1079 graph_proxy_handle graph
,
1081 uint64_t * client_id_ptr
)
1083 if (!graph_ptr
->graph_manager_supported
)
1088 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "NewClient", "s", &name
, "t", client_id_ptr
))
1090 log_error(IFACE_GRAPH_MANAGER
".NewClient() failed.");
1098 graph_proxy_remove_client(
1099 graph_proxy_handle graph
,
1102 if (!graph_ptr
->graph_manager_supported
)
1107 if (!cdbus_call(0, graph_ptr
->service
, graph_ptr
->object
, IFACE_GRAPH_MANAGER
, "RemoveClient", "t", &client_id
, ""))
1109 log_error(IFACE_GRAPH_MANAGER
".RemoveClient() failed.");
1116 /* this must be static because it is referenced by the
1117 * dbus helper layer when hooks are active */
1118 static struct cdbus_signal_hook g_signal_hooks
[] =
1120 {"ClientAppeared", on_client_appeared
},
1121 {"ClientRenamed", on_client_renamed
},
1122 {"ClientDisappeared", on_client_disappeared
},
1123 {"PortAppeared", on_port_appeared
},
1124 {"PortRenamed", on_port_renamed
},
1125 {"PortDisappeared", on_port_disappeared
},
1126 {"PortsConnected", on_ports_connected
},
1127 {"PortsDisconnected", on_ports_disconnected
},