| 1 | /* -*- Mode: C ; c-basic-offset: 2 -*- */ |
|---|
| 2 | /* |
|---|
| 3 | * LADI Session Handler (ladish) |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2010,2011 Nedko Arnaudov <nedko@arnaudov.name> |
|---|
| 6 | * |
|---|
| 7 | ************************************************************************** |
|---|
| 8 | * This file contains code that interfaces the jmcore through D-Bus |
|---|
| 9 | ************************************************************************** |
|---|
| 10 | * |
|---|
| 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. |
|---|
| 15 | * |
|---|
| 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. |
|---|
| 20 | * |
|---|
| 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. |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | #include "jmcore_proxy.h" |
|---|
| 28 | #include "../dbus_constants.h" |
|---|
| 29 | |
|---|
| 30 | int64_t g_jmcore_pid; |
|---|
| 31 | |
|---|
| 32 | static void on_jmcore_life_status_changed(bool appeared) |
|---|
| 33 | { |
|---|
| 34 | g_jmcore_pid = 0; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | bool jmcore_proxy_init(void) |
|---|
| 38 | { |
|---|
| 39 | if (!cdbus_register_service_lifetime_hook(cdbus_g_dbus_connection, JMCORE_SERVICE_NAME, on_jmcore_life_status_changed)) |
|---|
| 40 | { |
|---|
| 41 | log_error("dbus_register_service_lifetime_hook() failed for a2j service"); |
|---|
| 42 | return false; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | return jmcore_proxy_get_pid_noncached(&g_jmcore_pid); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void jmcore_proxy_uninit(void) |
|---|
| 49 | { |
|---|
| 50 | cdbus_unregister_service_lifetime_hook(cdbus_g_dbus_connection, JMCORE_SERVICE_NAME); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | int64_t jmcore_proxy_get_pid_cached(void) |
|---|
| 54 | { |
|---|
| 55 | if (g_jmcore_pid == 0) |
|---|
| 56 | { |
|---|
| 57 | jmcore_proxy_get_pid_noncached(&g_jmcore_pid); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | return g_jmcore_pid; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | bool jmcore_proxy_get_pid_noncached(int64_t * pid_ptr) |
|---|
| 64 | { |
|---|
| 65 | if (!cdbus_call(0, JMCORE_SERVICE_NAME, JMCORE_OBJECT_PATH, JMCORE_IFACE, "get_pid", "", "x", pid_ptr)) |
|---|
| 66 | { |
|---|
| 67 | log_error("jmcore::get_pid() failed."); |
|---|
| 68 | return false; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | return true; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | bool jmcore_proxy_create_link(bool midi, const char * input_port_name, const char * output_port_name) |
|---|
| 75 | { |
|---|
| 76 | dbus_bool_t dbus_midi = midi; |
|---|
| 77 | |
|---|
| 78 | if (!cdbus_call(0, JMCORE_SERVICE_NAME, JMCORE_OBJECT_PATH, JMCORE_IFACE, "create", "bss", &dbus_midi, &input_port_name, &output_port_name, "")) |
|---|
| 79 | { |
|---|
| 80 | log_error("jmcore::create() failed: %s", cdbus_call_last_error_get_message()); |
|---|
| 81 | return false; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | return true; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | bool jmcore_proxy_destroy_link(const char * port_name) |
|---|
| 88 | { |
|---|
| 89 | if (!cdbus_call(0, JMCORE_SERVICE_NAME, JMCORE_OBJECT_PATH, JMCORE_IFACE, "destroy", "s", &port_name, "")) |
|---|
| 90 | { |
|---|
| 91 | log_error("jmcore::destroy() failed."); |
|---|
| 92 | return false; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return true; |
|---|
| 96 | } |
|---|