implement view switching from world tree
[ladish.git] / dbus / method.h
blob1358441972d58d8774059f6d8b9a1c1760adf79c
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
8 **************************************************************************
9 * This file contains interface to D-Bus methods helpers
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 #ifndef __LASH_DBUS_METHOD_H__
29 #define __LASH_DBUS_METHOD_H__
31 #include <stdbool.h>
32 #include <dbus/dbus.h>
34 #include "types.h"
36 struct _method_msg
38 const service_t *service;
39 DBusMessage *message;
40 void *context;
41 DBusFreeFunction context_free_func;
42 DBusPendingCallNotifyFunction return_handler;
45 struct _method_call
47 DBusConnection *connection;
48 const char *method_name;
49 DBusMessage *message;
50 DBusMessage *reply;
51 const interface_t *interface;
52 void *context;
55 struct _method_arg
57 const char *name;
58 const char *type;
59 const bool direction_in; /* false == out, true == in */
62 struct _method
64 const char *name;
65 const method_handler_t handler;
66 const method_arg_t *args;
69 void
70 method_return_new_void(method_call_t *call);
72 void
73 method_return_new_single(method_call_t *call,
74 int type,
75 const void *arg);
77 void
78 method_return_new_valist(method_call_t *call,
79 int type,
80 ...);
82 bool
83 method_return_verify(DBusMessage *msg,
84 const char **str);
86 bool
87 method_iter_append_variant(DBusMessageIter *iter,
88 int type,
89 const void *arg);
91 bool
92 method_iter_append_dict_entry(DBusMessageIter *iter,
93 int type,
94 const char *key,
95 const void *value,
96 int length);
98 bool
99 method_send(method_msg_t *call,
100 bool will_block);
102 void
103 method_return_send(method_call_t *call);
105 void
106 method_default_handler(DBusPendingCall *pending,
107 void *data);
109 bool
110 method_call_init(method_msg_t *call,
111 service_t *service,
112 void *return_context,
113 DBusPendingCallNotifyFunction return_handler,
114 const char *destination,
115 const char *path,
116 const char *interface,
117 const char *method);
119 bool
120 method_call_new_void(service_t *service,
121 void *return_context,
122 DBusPendingCallNotifyFunction return_handler,
123 bool will_block,
124 const char *destination,
125 const char *path,
126 const char *interface,
127 const char *method);
129 bool
130 method_call_new_single(service_t *service,
131 void *return_context,
132 DBusPendingCallNotifyFunction return_handler,
133 bool will_block,
134 const char *destination,
135 const char *path,
136 const char *interface,
137 const char *method,
138 int type,
139 const void *arg);
141 bool
142 method_call_new_valist(service_t *service,
143 void *return_context,
144 DBusPendingCallNotifyFunction return_handler,
145 bool will_block,
146 const char *destination,
147 const char *path,
148 const char *interface,
149 const char *method,
150 int type,
151 ...);
153 bool
154 method_iter_get_args(DBusMessageIter *iter,
155 ...);
157 bool
158 method_iter_get_dict_entry(DBusMessageIter *iter,
159 const char **key_ptr,
160 void *value_ptr,
161 int *type_ptr,
162 int *size_ptr);
164 #define METHOD_ARGS_BEGIN(method_name, descr) \
165 static const struct _method_arg method_name ## _args_dtor[] = \
168 #define METHOD_ARG_DESCRIBE_IN(arg_name, arg_type, descr) \
170 .name = arg_name, \
171 .type = arg_type, \
172 .direction_in = true \
175 #define METHOD_ARG_DESCRIBE_OUT(arg_name, arg_type, descr) \
177 .name = arg_name, \
178 .type = arg_type, \
179 .direction_in = false \
182 #define METHOD_ARGS_END \
184 .name = NULL, \
188 #define METHODS_BEGIN \
189 static const struct _method methods_dtor[] = \
192 #define METHOD_DESCRIBE(method_name, handler_name) \
194 .name = # method_name, \
195 .handler = handler_name, \
196 .args = method_name ## _args_dtor \
199 #define METHODS_END \
201 .name = NULL, \
202 .handler = NULL, \
203 .args = NULL \
207 #endif /* __LASH_DBUS_METHOD_H__ */