jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
12KB

  1. /* -*- Mode: C ; c-basic-offset: 4 -*- */
  2. /*
  3. Copyright (C) 2007,2008 Nedko Arnaudov
  4. Copyright (C) 2007-2008 Juuso Alasuutari
  5. Copyright (C) 2008 Marc-Olivier Barre
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #ifndef DBUS_H__3DB2458F_44B2_43EA_882A_9F888DF71A88__INCLUDED
  18. #define DBUS_H__3DB2458F_44B2_43EA_882A_9F888DF71A88__INCLUDED
  19. #include <stdbool.h>
  20. #define JACK_DBUS_DEBUG
  21. //#define DISABLE_SIGNAL_MAGIC
  22. #define DEFAULT_XDG_CONFIG "/.config"
  23. #define DEFAULT_XDG_LOG "/.log"
  24. #define JACKDBUS_DIR "/jack"
  25. #define JACKDBUS_LOG "/jackdbus.log"
  26. #define JACKDBUS_CONF "/conf.xml"
  27. extern char *g_jackdbus_config_dir;
  28. extern size_t g_jackdbus_config_dir_len; /* without terminating '\0' char */
  29. extern int g_exit_command;
  30. bool
  31. jack_controller_settings_init();
  32. void
  33. jack_controller_settings_uninit();
  34. #define JACK_DBUS_ERROR_UNKNOWN_METHOD "org.jackaudio.Error.UnknownMethod"
  35. #define JACK_DBUS_ERROR_SERVER_NOT_RUNNING "org.jackaudio.Error.ServerNotRunning"
  36. #define JACK_DBUS_ERROR_SERVER_RUNNING "org.jackaudio.Error.ServerRunning"
  37. #define JACK_DBUS_ERROR_UNKNOWN_DRIVER "org.jackaudio.Error.UnknownDriver"
  38. #define JACK_DBUS_ERROR_UNKNOWN_INTERNAL "org.jackaudio.Error.UnknownInternal"
  39. #define JACK_DBUS_ERROR_UNKNOWN_PARAMETER "org.jackaudio.Error.UnknownParameter"
  40. #define JACK_DBUS_ERROR_INVALID_ARGS "org.jackaudio.Error.InvalidArgs"
  41. #define JACK_DBUS_ERROR_GENERIC "org.jackaudio.Error.Generic"
  42. #define JACK_DBUS_ERROR_FATAL "org.jackaudio.Error.Fatal"
  43. struct jack_dbus_method_call
  44. {
  45. void *context;
  46. DBusConnection *connection;
  47. const char *method_name;
  48. DBusMessage *message;
  49. DBusMessage *reply;
  50. };
  51. struct jack_dbus_interface_method_argument_descriptor
  52. {
  53. const char * name;
  54. const char * type;
  55. bool direction_out; /* true - out, false - in */
  56. };
  57. struct jack_dbus_interface_method_descriptor
  58. {
  59. const char * name;
  60. const struct jack_dbus_interface_method_argument_descriptor * arguments;
  61. void (* handler)(struct jack_dbus_method_call * call);
  62. };
  63. struct jack_dbus_interface_signal_argument_descriptor
  64. {
  65. const char * name;
  66. const char * type;
  67. };
  68. struct jack_dbus_interface_signal_descriptor
  69. {
  70. const char * name;
  71. const struct jack_dbus_interface_signal_argument_descriptor * arguments;
  72. };
  73. struct jack_dbus_interface_descriptor
  74. {
  75. const char * name;
  76. bool
  77. (* handler)(
  78. struct jack_dbus_method_call * call,
  79. const struct jack_dbus_interface_method_descriptor * methods);
  80. const struct jack_dbus_interface_method_descriptor * methods;
  81. const struct jack_dbus_interface_signal_descriptor * signals;
  82. };
  83. struct jack_dbus_object_descriptor
  84. {
  85. struct jack_dbus_interface_descriptor ** interfaces;
  86. void * context;
  87. };
  88. typedef union
  89. {
  90. unsigned char byte;
  91. dbus_bool_t boolean;
  92. dbus_int16_t int16;
  93. dbus_uint16_t uint16;
  94. dbus_int32_t int32;
  95. dbus_uint32_t uint32;
  96. dbus_int64_t int64;
  97. dbus_uint64_t uint64;
  98. double doubl;
  99. const char *string;
  100. } message_arg_t;
  101. #define JACK_DBUS_METHOD_ARGUMENTS_BEGIN(method_name) \
  102. static const \
  103. struct jack_dbus_interface_method_argument_descriptor method_name ## _arguments[] = \
  104. {
  105. #define JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(method_name, descr) \
  106. static const \
  107. struct jack_dbus_interface_method_argument_descriptor method_name ## _arguments[] = \
  108. {
  109. #define JACK_DBUS_METHOD_ARGUMENT(argument_name, argument_type, argument_direction_out) \
  110. { \
  111. .name = argument_name, \
  112. .type = argument_type, \
  113. .direction_out = argument_direction_out \
  114. },
  115. #define JACK_DBUS_METHOD_ARGUMENT_IN(argument_name, argument_type, descr) \
  116. { \
  117. .name = argument_name, \
  118. .type = argument_type, \
  119. .direction_out = false \
  120. },
  121. #define JACK_DBUS_METHOD_ARGUMENT_OUT(argument_name, argument_type, descr) \
  122. { \
  123. .name = argument_name, \
  124. .type = argument_type, \
  125. .direction_out = true \
  126. },
  127. #define JACK_DBUS_METHOD_ARGUMENT(argument_name, argument_type, argument_direction_out) \
  128. { \
  129. .name = argument_name, \
  130. .type = argument_type, \
  131. .direction_out = argument_direction_out \
  132. },
  133. #define JACK_DBUS_METHOD_ARGUMENTS_END \
  134. JACK_DBUS_METHOD_ARGUMENT(NULL, NULL, false) \
  135. };
  136. #define JACK_DBUS_METHODS_BEGIN \
  137. static const \
  138. struct jack_dbus_interface_method_descriptor methods_dtor[] = \
  139. {
  140. #define JACK_DBUS_METHOD_DESCRIBE(method_name, handler_name) \
  141. { \
  142. .name = # method_name, \
  143. .arguments = method_name ## _arguments, \
  144. .handler = handler_name \
  145. },
  146. #define JACK_DBUS_METHODS_END \
  147. { \
  148. .name = NULL, \
  149. .arguments = NULL, \
  150. .handler = NULL \
  151. } \
  152. };
  153. #define JACK_DBUS_SIGNAL_ARGUMENTS_BEGIN(signal_name) \
  154. static const \
  155. struct jack_dbus_interface_signal_argument_descriptor signal_name ## _arguments[] = \
  156. {
  157. #define JACK_DBUS_SIGNAL_ARGUMENT(argument_name, argument_type) \
  158. { \
  159. .name = argument_name, \
  160. .type = argument_type \
  161. },
  162. #define JACK_DBUS_SIGNAL_ARGUMENTS_END \
  163. JACK_DBUS_SIGNAL_ARGUMENT(NULL, NULL) \
  164. };
  165. #define JACK_DBUS_SIGNALS_BEGIN \
  166. static const \
  167. struct jack_dbus_interface_signal_descriptor signals_dtor[] = \
  168. {
  169. #define JACK_DBUS_SIGNAL_DESCRIBE(signal_name) \
  170. { \
  171. .name = # signal_name, \
  172. .arguments = signal_name ## _arguments \
  173. },
  174. #define JACK_DBUS_SIGNALS_END \
  175. { \
  176. .name = NULL, \
  177. .arguments = NULL, \
  178. } \
  179. };
  180. #define JACK_DBUS_IFACE_BEGIN(iface_var, iface_name) \
  181. struct jack_dbus_interface_descriptor iface_var = \
  182. { \
  183. .name = iface_name, \
  184. .handler = jack_dbus_run_method,
  185. #define JACK_DBUS_IFACE_HANDLER(handler_func) \
  186. .handler = handler_func,
  187. #define JACK_DBUS_IFACE_EXPOSE_METHODS \
  188. .methods = methods_dtor,
  189. #define JACK_DBUS_IFACE_EXPOSE_SIGNALS \
  190. .signals = signals_dtor,
  191. #define JACK_DBUS_IFACE_END \
  192. };
  193. DBusHandlerResult
  194. jack_dbus_message_handler(
  195. DBusConnection *connection,
  196. DBusMessage *message,
  197. void *data);
  198. void
  199. jack_dbus_message_handler_unregister(
  200. DBusConnection *connection,
  201. void *data);
  202. bool
  203. jack_dbus_run_method(
  204. struct jack_dbus_method_call * call,
  205. const struct jack_dbus_interface_method_descriptor * methods);
  206. void
  207. jack_dbus_error(
  208. void *dbus_call_context_ptr,
  209. const char *error_name,
  210. const char *format,
  211. ...);
  212. void
  213. jack_dbus_only_error(
  214. void *dbus_call_context_ptr,
  215. const char *error_name,
  216. const char *format,
  217. ...);
  218. bool
  219. jack_dbus_get_method_args(
  220. struct jack_dbus_method_call *call,
  221. int type,
  222. ...);
  223. bool
  224. jack_dbus_get_method_args_string_and_variant(
  225. struct jack_dbus_method_call *call,
  226. const char **arg1,
  227. message_arg_t *arg2,
  228. int *type_ptr);
  229. bool
  230. jack_dbus_get_method_args_two_strings_and_variant(
  231. struct jack_dbus_method_call *call,
  232. const char **arg1,
  233. const char **arg2,
  234. message_arg_t *arg3,
  235. int *type_ptr);
  236. bool
  237. jack_dbus_message_append_variant(
  238. DBusMessageIter *iter,
  239. int type,
  240. const char *signature,
  241. message_arg_t *arg);
  242. void
  243. jack_dbus_construct_method_return_empty(
  244. struct jack_dbus_method_call * call);
  245. void
  246. jack_dbus_construct_method_return_single(
  247. struct jack_dbus_method_call *call,
  248. int type,
  249. message_arg_t arg);
  250. void
  251. jack_dbus_construct_method_return_array_of_strings(
  252. struct jack_dbus_method_call *call,
  253. unsigned int num_members,
  254. const char **array);
  255. void
  256. jack_dbus_send_signal(
  257. const char *sender_object_path,
  258. const char *iface,
  259. const char *signal_name,
  260. int first_arg_type,
  261. ...);
  262. #define JACK_CONTROLLER_OBJECT_PATH "/org/jackaudio/Controller"
  263. extern struct jack_dbus_interface_descriptor * g_jackcontroller_interfaces[];
  264. extern DBusConnection * g_connection;
  265. #endif /* #ifndef DBUS_H__3DB2458F_44B2_43EA_882A_9F888DF71A88__INCLUDED */