root/proxies/jmcore_proxy.c @ 3af230cad5cdbb19784ffc8bac1a404eeac7c707

Revision 3af230cad5cdbb19784ffc8bac1a404eeac7c707, 2.8 KB (checked in by Nedko Arnaudov <nedko@…>, 21 months ago)

improved error message on jmcore::create() failures

  • Property mode set to 100644
Line 
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
30int64_t g_jmcore_pid;
31
32static void on_jmcore_life_status_changed(bool appeared)
33{
34  g_jmcore_pid = 0;
35}
36
37bool 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
48void jmcore_proxy_uninit(void)
49{
50  cdbus_unregister_service_lifetime_hook(cdbus_g_dbus_connection, JMCORE_SERVICE_NAME);
51}
52
53int64_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
63bool 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
74bool 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
87bool 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}
Note: See TracBrowser for help on using the browser.