Remove the not reliable initial jack canvas arrange
[ladish.git] / daemon / patchbay.c
blobf41ed0233072c1731bfcb7165eb56be826e80cf7
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari
8 **************************************************************************
9 * This file contains implementation of the D-Bus patchbay interface helpers
10 **************************************************************************
12 * LADI Session Handler is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * LADI Session Handler is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
24 * or write to the Free Software Foundation, Inc.,
25 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "common.h"
29 #include "patchbay.h"
30 #include "../dbus/error.h"
32 #define impl_ptr ((struct patchbay_implementator *)call_ptr->context)
34 static void get_all_ports(method_call_t * call_ptr)
36 DBusMessageIter iter, sub_iter;
38 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
39 if (call_ptr->reply == NULL)
41 goto fail;
44 dbus_message_iter_init_append(call_ptr->reply, &iter);
46 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub_iter))
48 goto fail_unref;
51 if (!dbus_message_iter_close_container(&iter, &sub_iter))
53 goto fail_unref;
56 return;
58 fail_unref:
59 dbus_message_unref(call_ptr->reply);
60 call_ptr->reply = NULL;
62 fail:
63 lash_error("Ran out of memory trying to construct method return");
66 static void get_graph(method_call_t * call_ptr)
68 dbus_uint64_t known_version;
69 dbus_uint64_t current_version;
70 DBusMessageIter iter;
71 DBusMessageIter clients_array_iter;
72 DBusMessageIter connections_array_iter;
73 #if 0
74 DBusMessageIter ports_array_iter;
75 DBusMessageIter client_struct_iter;
76 DBusMessageIter port_struct_iter;
77 DBusMessageIter connection_struct_iter;
78 #endif
80 //lash_info("get_graph() called");
82 if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_UINT64, &known_version, DBUS_TYPE_INVALID))
84 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
85 dbus_error_free(&g_dbus_error);
86 return;
89 //lash_info("Getting graph, known version is %" PRIu64, known_version);
91 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
92 if (call_ptr->reply == NULL)
94 lash_error("Ran out of memory trying to construct method return");
95 goto exit;
98 dbus_message_iter_init_append(call_ptr->reply, &iter);
100 current_version = impl_ptr->get_graph_version(impl_ptr->this);
101 if (known_version > current_version)
103 lash_dbus_error(
104 call_ptr,
105 LASH_DBUS_ERROR_INVALID_ARGS,
106 "known graph version %" PRIu64 " is newer than actual version %" PRIu64,
107 known_version,
108 current_version);
109 goto exit;
112 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT64, &current_version))
114 goto nomem;
117 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(tsa(tsuu))", &clients_array_iter))
119 goto nomem;
122 if (known_version < current_version)
124 #if 0
125 list_for_each(client_node_ptr, &patchbay_ptr->graph.clients)
127 client_ptr = list_entry(client_node_ptr, struct jack_graph_client, siblings);
129 if (!dbus_message_iter_open_container (&clients_array_iter, DBUS_TYPE_STRUCT, NULL, &client_struct_iter))
131 goto nomem_close_clients_array;
134 if (!dbus_message_iter_append_basic(&client_struct_iter, DBUS_TYPE_UINT64, &client_ptr->id))
136 goto nomem_close_client_struct;
139 if (!dbus_message_iter_append_basic(&client_struct_iter, DBUS_TYPE_STRING, &client_ptr->name))
141 goto nomem_close_client_struct;
144 if (!dbus_message_iter_open_container(&client_struct_iter, DBUS_TYPE_ARRAY, "(tsuu)", &ports_array_iter))
146 goto nomem_close_client_struct;
149 list_for_each(port_node_ptr, &client_ptr->ports)
151 port_ptr = list_entry(port_node_ptr, struct jack_graph_port, siblings_client);
153 if (!dbus_message_iter_open_container(&ports_array_iter, DBUS_TYPE_STRUCT, NULL, &port_struct_iter))
155 goto nomem_close_ports_array;
158 if (!dbus_message_iter_append_basic(&port_struct_iter, DBUS_TYPE_UINT64, &port_ptr->id))
160 goto nomem_close_port_struct;
163 if (!dbus_message_iter_append_basic(&port_struct_iter, DBUS_TYPE_STRING, &port_ptr->name))
165 goto nomem_close_port_struct;
168 if (!dbus_message_iter_append_basic(&port_struct_iter, DBUS_TYPE_UINT32, &port_ptr->flags))
170 goto nomem_close_port_struct;
173 if (!dbus_message_iter_append_basic(&port_struct_iter, DBUS_TYPE_UINT32, &port_ptr->type))
175 goto nomem_close_port_struct;
178 if (!dbus_message_iter_close_container(&ports_array_iter, &port_struct_iter))
180 goto nomem_close_ports_array;
184 if (!dbus_message_iter_close_container(&client_struct_iter, &ports_array_iter))
186 goto nomem_close_client_struct;
189 if (!dbus_message_iter_close_container(&clients_array_iter, &client_struct_iter))
191 goto nomem_close_clients_array;
194 #endif
197 if (!dbus_message_iter_close_container(&iter, &clients_array_iter))
199 goto nomem;
202 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(tstststst)", &connections_array_iter))
204 goto nomem;
207 if (known_version < current_version)
209 #if 0
210 list_for_each(connection_node_ptr, &patchbay_ptr->graph.connections)
212 connection_ptr = list_entry(connection_node_ptr, struct jack_graph_connection, siblings);
214 if (!dbus_message_iter_open_container(&connections_array_iter, DBUS_TYPE_STRUCT, NULL, &connection_struct_iter))
216 goto nomem_close_connections_array;
219 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port1->client->id))
221 goto nomem_close_connection_struct;
224 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port1->client->name))
226 goto nomem_close_connection_struct;
229 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port1->id))
231 goto nomem_close_connection_struct;
234 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port1->name))
236 goto nomem_close_connection_struct;
239 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port2->client->id))
241 goto nomem_close_connection_struct;
244 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port2->client->name))
246 goto nomem_close_connection_struct;
249 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port2->id))
251 goto nomem_close_connection_struct;
254 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port2->name))
256 goto nomem_close_connection_struct;
259 if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->id))
261 goto nomem_close_connection_struct;
264 if (!dbus_message_iter_close_container(&connections_array_iter, &connection_struct_iter))
266 goto nomem_close_connections_array;
269 #endif
272 if (!dbus_message_iter_close_container(&iter, &connections_array_iter))
274 goto nomem;
277 return;
279 #if 0
280 nomem_close_connection_struct:
281 dbus_message_iter_close_container(&connections_array_iter, &connection_struct_iter);
283 nomem_close_connections_array:
284 dbus_message_iter_close_container(&iter, &connections_array_iter);
285 goto nomem_unlock;
287 nomem_close_port_struct:
288 dbus_message_iter_close_container(&ports_array_iter, &port_struct_iter);
290 nomem_close_ports_array:
291 dbus_message_iter_close_container(&client_struct_iter, &ports_array_iter);
293 nomem_close_client_struct:
294 dbus_message_iter_close_container(&clients_array_iter, &client_struct_iter);
296 nomem_close_clients_array:
297 dbus_message_iter_close_container(&iter, &clients_array_iter);
298 #endif
300 nomem:
301 dbus_message_unref(call_ptr->reply);
302 call_ptr->reply = NULL;
303 lash_error("Ran out of memory trying to construct method return");
305 exit:
306 return;
309 static void connect_ports_by_name(method_call_t * call_ptr)
311 method_return_new_void(call_ptr);
314 static void connect_ports_by_id(method_call_t * call_ptr)
316 method_return_new_void(call_ptr);
319 static void disconnect_ports_by_name(method_call_t * call_ptr)
321 method_return_new_void(call_ptr);
324 static void disconnect_ports_by_id(method_call_t * call_ptr)
326 method_return_new_void(call_ptr);
329 static void disconnect_ports_by_connection_id(method_call_t * call_ptr)
331 method_return_new_void(call_ptr);
334 static void get_client_pid(method_call_t * call_ptr)
336 int64_t pid = 0;
337 method_return_new_single(call_ptr, DBUS_TYPE_INT64, &pid);
340 METHOD_ARGS_BEGIN(GetAllPorts, "Get all ports")
341 METHOD_ARG_DESCRIBE_IN("ports_list", "as", "List of all ports")
342 METHOD_ARGS_END
344 METHOD_ARGS_BEGIN(GetGraph, "Get whole graph")
345 METHOD_ARG_DESCRIBE_IN("known_graph_version", DBUS_TYPE_UINT64_AS_STRING, "Known graph version")
346 METHOD_ARG_DESCRIBE_OUT("current_graph_version", DBUS_TYPE_UINT64_AS_STRING, "Current graph version")
347 METHOD_ARG_DESCRIBE_OUT("clients_and_ports", "a(tsa(tsuu))", "Clients and their ports")
348 METHOD_ARG_DESCRIBE_OUT("connections", "a(tstststst)", "Connections array")
349 METHOD_ARGS_END
351 METHOD_ARGS_BEGIN(ConnectPortsByName, "Connect ports")
352 METHOD_ARG_DESCRIBE_IN("client1_name", DBUS_TYPE_STRING_AS_STRING, "name first port client")
353 METHOD_ARG_DESCRIBE_IN("port1_name", DBUS_TYPE_STRING_AS_STRING, "name of first port")
354 METHOD_ARG_DESCRIBE_IN("client2_name", DBUS_TYPE_STRING_AS_STRING, "name second port client")
355 METHOD_ARG_DESCRIBE_IN("port2_name", DBUS_TYPE_STRING_AS_STRING, "name of second port")
356 METHOD_ARGS_END
358 METHOD_ARGS_BEGIN(ConnectPortsByID, "Connect ports")
359 METHOD_ARG_DESCRIBE_IN("port1_id", DBUS_TYPE_UINT64_AS_STRING, "id of first port")
360 METHOD_ARG_DESCRIBE_IN("port2_id", DBUS_TYPE_UINT64_AS_STRING, "if of second port")
361 METHOD_ARGS_END
363 METHOD_ARGS_BEGIN(DisconnectPortsByName, "Disconnect ports")
364 METHOD_ARG_DESCRIBE_IN("client1_name", DBUS_TYPE_STRING_AS_STRING, "name first port client")
365 METHOD_ARG_DESCRIBE_IN("port1_name", DBUS_TYPE_STRING_AS_STRING, "name of first port")
366 METHOD_ARG_DESCRIBE_IN("client2_name", DBUS_TYPE_STRING_AS_STRING, "name second port client")
367 METHOD_ARG_DESCRIBE_IN("port2_name", DBUS_TYPE_STRING_AS_STRING, "name of second port")
368 METHOD_ARGS_END
370 METHOD_ARGS_BEGIN(DisconnectPortsByID, "Disconnect ports")
371 METHOD_ARG_DESCRIBE_IN("port1_id", DBUS_TYPE_UINT64_AS_STRING, "id of first port")
372 METHOD_ARG_DESCRIBE_IN("port2_id", DBUS_TYPE_UINT64_AS_STRING, "if of second port")
373 METHOD_ARGS_END
375 METHOD_ARGS_BEGIN(DisconnectPortsByConnectionID, "Disconnect ports")
376 METHOD_ARG_DESCRIBE_IN("connection_id", DBUS_TYPE_UINT64_AS_STRING, "id of connection to disconnect")
377 METHOD_ARGS_END
379 METHOD_ARGS_BEGIN(GetClientPID, "get process id of client")
380 METHOD_ARG_DESCRIBE_IN("client_id", DBUS_TYPE_UINT64_AS_STRING, "id of client")
381 METHOD_ARG_DESCRIBE_OUT("process_id", DBUS_TYPE_INT64_AS_STRING, "pid of client")
382 METHOD_ARGS_END
384 METHODS_BEGIN
385 METHOD_DESCRIBE(GetAllPorts, get_all_ports)
386 METHOD_DESCRIBE(GetGraph, get_graph)
387 METHOD_DESCRIBE(ConnectPortsByName, connect_ports_by_name)
388 METHOD_DESCRIBE(ConnectPortsByID, connect_ports_by_id)
389 METHOD_DESCRIBE(DisconnectPortsByName, disconnect_ports_by_name)
390 METHOD_DESCRIBE(DisconnectPortsByID, disconnect_ports_by_id)
391 METHOD_DESCRIBE(DisconnectPortsByConnectionID, disconnect_ports_by_connection_id)
392 METHOD_DESCRIBE(GetClientPID, get_client_pid)
393 METHODS_END
395 SIGNAL_ARGS_BEGIN(GraphChanged, "")
396 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
397 SIGNAL_ARGS_END
399 SIGNAL_ARGS_BEGIN(ClientAppeared, "")
400 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
401 SIGNAL_ARG_DESCRIBE("client_id", DBUS_TYPE_UINT64_AS_STRING, "")
402 SIGNAL_ARG_DESCRIBE("client_name", DBUS_TYPE_STRING_AS_STRING, "")
403 SIGNAL_ARGS_END
405 SIGNAL_ARGS_BEGIN(ClientDisappeared, "")
406 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
407 SIGNAL_ARG_DESCRIBE("client_id", DBUS_TYPE_UINT64_AS_STRING, "")
408 SIGNAL_ARG_DESCRIBE("client_name", DBUS_TYPE_STRING_AS_STRING, "")
409 SIGNAL_ARGS_END
411 SIGNAL_ARGS_BEGIN(PortAppeared, "")
412 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
413 SIGNAL_ARG_DESCRIBE("client_id", DBUS_TYPE_UINT64_AS_STRING, "")
414 SIGNAL_ARG_DESCRIBE("client_name", DBUS_TYPE_STRING_AS_STRING, "")
415 SIGNAL_ARG_DESCRIBE("port_id", DBUS_TYPE_UINT64_AS_STRING, "")
416 SIGNAL_ARG_DESCRIBE("port_name", DBUS_TYPE_STRING_AS_STRING, "")
417 SIGNAL_ARG_DESCRIBE("port_flags", DBUS_TYPE_UINT32_AS_STRING, "")
418 SIGNAL_ARG_DESCRIBE("port_type", DBUS_TYPE_UINT32_AS_STRING, "")
419 SIGNAL_ARGS_END
421 SIGNAL_ARGS_BEGIN(PortDisappeared, "")
422 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
423 SIGNAL_ARG_DESCRIBE("client_id", DBUS_TYPE_UINT64_AS_STRING, "")
424 SIGNAL_ARG_DESCRIBE("client_name", DBUS_TYPE_STRING_AS_STRING, "")
425 SIGNAL_ARG_DESCRIBE("port_id", DBUS_TYPE_UINT64_AS_STRING, "")
426 SIGNAL_ARG_DESCRIBE("port_name", DBUS_TYPE_STRING_AS_STRING, "")
427 SIGNAL_ARGS_END
429 SIGNAL_ARGS_BEGIN(PortsConnected, "")
430 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
431 SIGNAL_ARG_DESCRIBE("client1_id", DBUS_TYPE_UINT64_AS_STRING, "")
432 SIGNAL_ARG_DESCRIBE("client1_name", DBUS_TYPE_STRING_AS_STRING, "")
433 SIGNAL_ARG_DESCRIBE("port1_id", DBUS_TYPE_UINT64_AS_STRING, "")
434 SIGNAL_ARG_DESCRIBE("port1_name", DBUS_TYPE_STRING_AS_STRING, "")
435 SIGNAL_ARG_DESCRIBE("client2_id", DBUS_TYPE_UINT64_AS_STRING, "")
436 SIGNAL_ARG_DESCRIBE("client2_name", DBUS_TYPE_STRING_AS_STRING, "")
437 SIGNAL_ARG_DESCRIBE("port2_id", DBUS_TYPE_UINT64_AS_STRING, "")
438 SIGNAL_ARG_DESCRIBE("port2_name", DBUS_TYPE_STRING_AS_STRING, "")
439 SIGNAL_ARG_DESCRIBE("connection_id", DBUS_TYPE_UINT64_AS_STRING, "")
440 SIGNAL_ARGS_END
442 SIGNAL_ARGS_BEGIN(PortsDisconnected, "")
443 SIGNAL_ARG_DESCRIBE("new_graph_version", DBUS_TYPE_UINT64_AS_STRING, "")
444 SIGNAL_ARG_DESCRIBE("client1_id", DBUS_TYPE_UINT64_AS_STRING, "")
445 SIGNAL_ARG_DESCRIBE("client1_name", DBUS_TYPE_STRING_AS_STRING, "")
446 SIGNAL_ARG_DESCRIBE("port1_id", DBUS_TYPE_UINT64_AS_STRING, "")
447 SIGNAL_ARG_DESCRIBE("port1_name", DBUS_TYPE_STRING_AS_STRING, "")
448 SIGNAL_ARG_DESCRIBE("client2_id", DBUS_TYPE_UINT64_AS_STRING, "")
449 SIGNAL_ARG_DESCRIBE("client2_name", DBUS_TYPE_STRING_AS_STRING, "")
450 SIGNAL_ARG_DESCRIBE("port2_id", DBUS_TYPE_UINT64_AS_STRING, "")
451 SIGNAL_ARG_DESCRIBE("port2_name", DBUS_TYPE_STRING_AS_STRING, "")
452 SIGNAL_ARG_DESCRIBE("connection_id", DBUS_TYPE_UINT64_AS_STRING, "")
453 SIGNAL_ARGS_END
455 SIGNALS_BEGIN
456 SIGNAL_DESCRIBE(GraphChanged)
457 SIGNAL_DESCRIBE(ClientAppeared)
458 SIGNAL_DESCRIBE(ClientDisappeared)
459 SIGNAL_DESCRIBE(PortAppeared)
460 SIGNAL_DESCRIBE(PortDisappeared)
461 SIGNAL_DESCRIBE(PortsConnected)
462 SIGNAL_DESCRIBE(PortsDisconnected)
463 SIGNALS_END
465 INTERFACE_BEGIN(g_interface_patchbay, "org.jackaudio.JackPatchbay")
466 INTERFACE_DEFAULT_HANDLER
467 INTERFACE_EXPOSE_METHODS
468 INTERFACE_EXPOSE_SIGNALS
469 INTERFACE_END