| 1 | /* -*- Mode: C ; c-basic-offset: 2 -*- */ |
|---|
| 2 | /* |
|---|
| 3 | * LADI Session Handler (ladish) |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name> |
|---|
| 6 | * |
|---|
| 7 | ************************************************************************** |
|---|
| 8 | * This file contains implementation of code that interfaces |
|---|
| 9 | * app supervisor object through D-Bus |
|---|
| 10 | ************************************************************************** |
|---|
| 11 | * |
|---|
| 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. |
|---|
| 16 | * |
|---|
| 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. |
|---|
| 21 | * |
|---|
| 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. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #include "app_supervisor_proxy.h" |
|---|
| 29 | #include "../dbus/helpers.h" |
|---|
| 30 | #include "../dbus_constants.h" |
|---|
| 31 | |
|---|
| 32 | struct ladish_app_supervisor_proxy |
|---|
| 33 | { |
|---|
| 34 | char * service; |
|---|
| 35 | char * object; |
|---|
| 36 | uint64_t version; |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | bool ladish_app_supervisor_proxy_create(const char * service, const char * object, ladish_app_supervisor_proxy_handle * handle_ptr) |
|---|
| 40 | { |
|---|
| 41 | struct ladish_app_supervisor_proxy * proxy_ptr; |
|---|
| 42 | |
|---|
| 43 | proxy_ptr = malloc(sizeof(struct ladish_app_supervisor_proxy)); |
|---|
| 44 | if (proxy_ptr == NULL) |
|---|
| 45 | { |
|---|
| 46 | log_error("malloc() failed to allocate struct proxy"); |
|---|
| 47 | goto fail; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | proxy_ptr->service = strdup(service); |
|---|
| 51 | if (proxy_ptr->service == NULL) |
|---|
| 52 | { |
|---|
| 53 | log_error("strdup() failed too duplicate service name '%s'", service); |
|---|
| 54 | goto free_proxy; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | proxy_ptr->object = strdup(object); |
|---|
| 58 | if (proxy_ptr->object == NULL) |
|---|
| 59 | { |
|---|
| 60 | log_error("strdup() failed too duplicate object name '%s'", object); |
|---|
| 61 | goto free_service; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | proxy_ptr->version = 0; |
|---|
| 65 | |
|---|
| 66 | *handle_ptr = (ladish_app_supervisor_proxy_handle)proxy_ptr; |
|---|
| 67 | |
|---|
| 68 | return true; |
|---|
| 69 | |
|---|
| 70 | free_service: |
|---|
| 71 | free(proxy_ptr->service); |
|---|
| 72 | |
|---|
| 73 | free_proxy: |
|---|
| 74 | free(proxy_ptr); |
|---|
| 75 | |
|---|
| 76 | fail: |
|---|
| 77 | return false; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | #define proxy_ptr ((struct ladish_app_supervisor_proxy *)proxy) |
|---|
| 81 | |
|---|
| 82 | void ladish_app_supervisor_proxy_destroy(ladish_app_supervisor_proxy_handle proxy) |
|---|
| 83 | { |
|---|
| 84 | free(proxy_ptr->object); |
|---|
| 85 | free(proxy_ptr->service); |
|---|
| 86 | free(proxy_ptr); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | bool ladish_app_supervisor_proxy_run_custom(ladish_app_supervisor_proxy_handle proxy, const char * command, const char * name, bool run_in_terminal) |
|---|
| 90 | { |
|---|
| 91 | dbus_bool_t terminal; |
|---|
| 92 | if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_APP_SUPERVISOR, "RunCustom", "bss", &terminal, &command, &name, "")) |
|---|
| 93 | { |
|---|
| 94 | log_error("RunCustom() failed."); |
|---|
| 95 | return false; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | return true; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | #undef proxy_ptr |
|---|