add dbus command to allow checking of wether hardware is currently exported
[a2jmidid.git] / dbus_internal.h
blob802eadccdae85838c1e46f3523aa025277f73cba
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * ALSA SEQ < - > JACK MIDI bridge
5 * Copyright (c) 2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2007-2008 Juuso Alasuutari
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef DBUS_INTERNAL_H__9AE08E23_C592_46FB_84BD_E3D0E8721C07__INCLUDED
23 #define DBUS_INTERNAL_H__9AE08E23_C592_46FB_84BD_E3D0E8721C07__INCLUDED
25 #define A2J_DBUS_SERVICE_NAME "org.gna.home.a2jmidid"
26 #define A2J_DBUS_OBJECT_PATH "/"
28 struct a2j_dbus_method_call
30 void *context;
31 DBusConnection *connection;
32 const char *method_name;
33 DBusMessage *message;
34 DBusMessage *reply;
37 #define A2J_DBUS_DIRECTION_IN false
38 #define A2J_DBUS_DIRECTION_OUT true
40 struct a2j_dbus_interface_method_argument_descriptor
42 const char * name;
43 const char * type;
44 bool direction_out; /* A2J_DBUS_DIRECTION_XXX */
47 struct a2j_dbus_interface_method_descriptor
49 const char * name;
50 const struct a2j_dbus_interface_method_argument_descriptor * arguments;
51 void (* handler)(struct a2j_dbus_method_call * call);
54 struct a2j_dbus_interface_signal_argument_descriptor
56 const char * name;
57 const char * type;
60 struct a2j_dbus_interface_signal_descriptor
62 const char * name;
63 const struct a2j_dbus_interface_signal_argument_descriptor * arguments;
66 struct a2j_dbus_interface_descriptor
68 const char * name;
70 bool
71 (* handler)(
72 struct a2j_dbus_method_call * call,
73 const struct a2j_dbus_interface_method_descriptor * methods);
75 const struct a2j_dbus_interface_method_descriptor * methods;
76 const struct a2j_dbus_interface_signal_descriptor * signals;
79 struct a2j_dbus_object_descriptor
81 struct a2j_dbus_interface_descriptor ** interfaces;
82 void * context;
85 #define A2J_DBUS_METHOD_ARGUMENTS_BEGIN(method_name) \
86 static const \
87 struct a2j_dbus_interface_method_argument_descriptor method_name ## _arguments[] = \
90 #define A2J_DBUS_METHOD_ARGUMENT(argument_name, argument_type, argument_direction_out) \
91 { \
92 .name = argument_name, \
93 .type = argument_type, \
94 .direction_out = argument_direction_out \
97 #define A2J_DBUS_METHOD_ARGUMENTS_END \
98 A2J_DBUS_METHOD_ARGUMENT(NULL, NULL, false) \
101 #define A2J_DBUS_METHODS_BEGIN \
102 static const \
103 struct a2j_dbus_interface_method_descriptor methods_dtor[] = \
106 #define A2J_DBUS_METHOD_DESCRIBE(method_name, handler_name) \
108 .name = # method_name, \
109 .arguments = method_name ## _arguments, \
110 .handler = handler_name \
113 #define A2J_DBUS_METHODS_END \
115 .name = NULL, \
116 .arguments = NULL, \
117 .handler = NULL \
121 #define A2J_DBUS_SIGNAL_ARGUMENTS_BEGIN(signal_name) \
122 static const \
123 struct a2j_dbus_interface_signal_argument_descriptor signal_name ## _arguments[] = \
126 #define A2J_DBUS_SIGNAL_ARGUMENT(argument_name, argument_type) \
128 .name = argument_name, \
129 .type = argument_type \
132 #define A2J_DBUS_SIGNAL_ARGUMENTS_END \
133 A2J_DBUS_SIGNAL_ARGUMENT(NULL, NULL) \
136 #define A2J_DBUS_SIGNALS_BEGIN \
137 static const \
138 struct a2j_dbus_interface_signal_descriptor signals_dtor[] = \
141 #define A2J_DBUS_SIGNAL_DESCRIBE(signal_name) \
143 .name = # signal_name, \
144 .arguments = signal_name ## _arguments \
147 #define A2J_DBUS_SIGNALS_END \
149 .name = NULL, \
150 .arguments = NULL, \
154 #define A2J_DBUS_IFACE_BEGIN(iface_var, iface_name) \
155 struct a2j_dbus_interface_descriptor iface_var = \
157 .name = iface_name, \
158 .handler = a2j_dbus_run_method,
160 #define A2J_DBUS_IFACE_HANDLER(handler_func) \
161 .handler = handler_func,
163 #define A2J_DBUS_IFACE_EXPOSE_METHODS \
164 .methods = methods_dtor,
166 #define A2J_DBUS_IFACE_EXPOSE_SIGNALS \
167 .signals = signals_dtor,
169 #define A2J_DBUS_IFACE_END \
172 #define A2J_DBUS_ERROR_GENERIC A2J_DBUS_SERVICE_NAME ".error.generic"
173 #define A2J_DBUS_ERROR_UNKNOWN_METHOD A2J_DBUS_SERVICE_NAME ".error.unknown_method"
174 #define A2J_DBUS_ERROR_INVALID_ARGS A2J_DBUS_SERVICE_NAME ".error.invalid_args"
175 #define A2J_DBUS_ERROR_UNKNOWN_PORT A2J_DBUS_SERVICE_NAME ".error.unknown_port"
176 #define A2J_DBUS_ERROR_BRIDGE_NOT_RUNNING A2J_DBUS_SERVICE_NAME ".error.bridge_not_running"
177 #define A2J_DBUS_ERROR_BRIDGE_RUNNING A2J_DBUS_SERVICE_NAME ".error.bridge_running"
179 void
180 a2j_dbus_error(
181 void *dbus_call_context_ptr,
182 const char *error_name,
183 const char *format,
184 ...);
186 bool
187 a2j_dbus_run_method(
188 struct a2j_dbus_method_call * call,
189 const struct a2j_dbus_interface_method_descriptor * methods);
191 void
192 a2j_dbus_construct_method_return_single(
193 struct a2j_dbus_method_call * call_ptr,
194 int type,
195 void * arg_ptr);
197 void a2j_dbus_construct_method_return_void(struct a2j_dbus_method_call * call_ptr);
199 void
200 a2j_dbus_signal(
201 const char * path,
202 const char * interface,
203 const char * name,
204 int type,
205 ...);
207 extern struct a2j_dbus_interface_descriptor * g_a2j_dbus_interfaces[];
208 extern struct a2j_dbus_interface_descriptor g_a2j_iface_introspectable;
210 #endif /* #ifndef DBUS_INTERNAL_H__9AE08E23_C592_46FB_84BD_E3D0E8721C07__INCLUDED */