gui: dialog for starting programs now starts them through ladishd
[ladish.git] / gui / app_supervisor_proxy.c
blob44f717c725c2c92be697109f14b8977aec0c3166
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of code that interfaces
9 * app supervisor object through D-Bus
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 "app_supervisor_proxy.h"
29 #include "../dbus/helpers.h"
30 #include "../dbus_constants.h"
32 struct ladish_app_supervisor_proxy
34 char * service;
35 char * object;
36 uint64_t version;
39 bool ladish_app_supervisor_proxy_create(const char * service, const char * object, ladish_app_supervisor_proxy_handle * handle_ptr)
41 struct ladish_app_supervisor_proxy * proxy_ptr;
43 proxy_ptr = malloc(sizeof(struct ladish_app_supervisor_proxy));
44 if (proxy_ptr == NULL)
46 log_error("malloc() failed to allocate struct proxy");
47 goto fail;
50 proxy_ptr->service = strdup(service);
51 if (proxy_ptr->service == NULL)
53 log_error("strdup() failed too duplicate service name '%s'", service);
54 goto free_proxy;
57 proxy_ptr->object = strdup(object);
58 if (proxy_ptr->object == NULL)
60 log_error("strdup() failed too duplicate object name '%s'", object);
61 goto free_service;
64 proxy_ptr->version = 0;
66 *handle_ptr = (ladish_app_supervisor_proxy_handle)proxy_ptr;
68 return true;
70 free_service:
71 free(proxy_ptr->service);
73 free_proxy:
74 free(proxy_ptr);
76 fail:
77 return false;
80 #define proxy_ptr ((struct ladish_app_supervisor_proxy *)proxy)
82 void ladish_app_supervisor_proxy_destroy(ladish_app_supervisor_proxy_handle proxy)
84 free(proxy_ptr->object);
85 free(proxy_ptr->service);
86 free(proxy_ptr);
89 bool ladish_app_supervisor_proxy_run_custom(ladish_app_supervisor_proxy_handle proxy, const char * command, const char * name, bool run_in_terminal)
91 dbus_bool_t terminal;
92 if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_APP_SUPERVISOR, "RunCustom", "bss", &terminal, &command, &name, ""))
94 log_error("RunCustom() failed.");
95 return false;
98 return true;
101 #undef proxy_ptr