ladishd: actually remove app ports, simply logging does not make it happen
[ladish.git] / proxies / jmcore_proxy.c
blob79d15e959e528006020b0696056259883e1707f5
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains code that interfaces the jmcore 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 "jmcore_proxy.h"
28 #include "../dbus_constants.h"
30 int64_t g_jmcore_pid;
32 static void on_jmcore_life_status_changed(bool appeared)
34 g_jmcore_pid = 0;
37 bool jmcore_proxy_init(void)
39 if (!dbus_register_service_lifetime_hook(g_dbus_connection, JMCORE_SERVICE_NAME, on_jmcore_life_status_changed))
41 log_error("dbus_register_service_lifetime_hook() failed for a2j service");
42 return false;
45 return jmcore_proxy_get_pid_noncached(&g_jmcore_pid);
48 void jmcore_proxy_uninit(void)
50 dbus_unregister_service_lifetime_hook(g_dbus_connection, JMCORE_SERVICE_NAME);
53 int64_t jmcore_proxy_get_pid_cached(void)
55 if (g_jmcore_pid == 0)
57 jmcore_proxy_get_pid_noncached(&g_jmcore_pid);
60 return g_jmcore_pid;
63 bool jmcore_proxy_get_pid_noncached(int64_t * pid_ptr)
65 if (!dbus_call(JMCORE_SERVICE_NAME, JMCORE_OBJECT_PATH, JMCORE_IFACE, "get_pid", "", "x", pid_ptr))
67 log_error("jmcore::get_pid() failed.");
68 return false;
71 return true;
74 bool jmcore_proxy_create_link(bool midi, const char * input_port_name, const char * output_port_name)
76 dbus_bool_t dbus_midi = midi;
78 if (!dbus_call(JMCORE_SERVICE_NAME, JMCORE_OBJECT_PATH, JMCORE_IFACE, "create", "bss", &dbus_midi, &input_port_name, &output_port_name, ""))
80 log_error("jmcore::create() failed.");
81 return false;
84 return true;
87 bool jmcore_proxy_destroy_link(const char * port_name)
89 if (!dbus_call(JMCORE_SERVICE_NAME, JMCORE_OBJECT_PATH, JMCORE_IFACE, "destroy", "s", &port_name, ""))
91 log_error("jmcore::destroy() failed.");
92 return false;
95 return true;