patchbay interface
[ladish.git] / dbus / interface.c
blob3fa9231f8f5a975b96750e3dd6528ab059c931e6
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
8 **************************************************************************
9 * This file contains D-Bus interface dispatcher
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 <string.h>
30 #include "../common/debug.h"
32 #include "interface.h"
33 #include "error.h"
36 * Execute a method's function if the method specified in the method call
37 * object exists in the method array. Return true if the method was found,
38 * false otherwise.
39 * TODO: rewrite description ^
41 bool
42 interface_default_handler(const interface_t *interface,
43 method_call_t *call)
45 const method_t *ptr;
47 for (ptr = (const method_t *) interface->methods;
48 ptr && ptr->name;
49 ++ptr) {
50 if (strcmp(call->method_name, ptr->name) == 0) {
51 if (ptr->handler) {
52 call->interface = interface;
53 ptr->handler(call);
55 /* If the method handler didn't construct a return
56 message create a void one here */
57 // TODO: Also handle cases where the sender doesn't need a reply
58 if (!call->reply
59 && !(call->reply = dbus_message_new_method_return(call->message))) {
60 lash_error("Failed to construct void method return");
62 } else {
63 lash_dbus_error(call, LASH_DBUS_ERROR_GENERIC,
64 "Handler for method \"%s\" is NULL", ptr->name);
67 /* Found method */
68 return true;
72 /* Didn't find method */
73 return false;
76 /* EOF */