Fix more warnings
[lash.git] / dbus / interface.c
blob9ad66d2b1502967be3dfd22e3de28459d669eea6
1 /*
2 * LASH
4 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
5 * Copyright (C) 2008 Nedko Arnaudov
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <string.h>
24 #include "common/debug.h"
26 #include "dbus/interface.h"
27 #include "dbus/error.h"
30 * Execute a method's function if the method specified in the method call
31 * object exists in the method array. Return true if the method was found,
32 * false otherwise.
33 * TODO: rewrite description ^
35 bool
36 interface_default_handler(const interface_t *interface,
37 method_call_t *call)
39 const method_t *ptr;
41 for (ptr = (const method_t *) interface->methods;
42 ptr && ptr->name;
43 ++ptr) {
44 if (strcmp(call->method_name, ptr->name) == 0) {
45 if (ptr->handler) {
46 call->interface = interface;
47 ptr->handler(call);
49 /* If the method handler didn't construct a return
50 message create a void one here */
51 // TODO: Also handle cases where the sender doesn't need a reply
52 if (!call->reply
53 && !(call->reply = dbus_message_new_method_return(call->message))) {
54 lash_error("Failed to construct void method return");
56 } else {
57 lash_dbus_error(call, LASH_DBUS_ERROR_GENERIC,
58 "Handler for method \"%s\" is NULL", ptr->name);
61 /* Found method */
62 return true;
66 /* Didn't find method */
67 return false;
70 /* EOF */