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.

157 lines
4.5KB

  1. /* -*- Mode: C ; c-basic-offset: 4 -*- */
  2. /*
  3. Copyright (C) 2007-2008 Nedko Arnaudov
  4. Copyright (C) 2007-2008 Juuso Alasuutari
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #if defined(HAVE_CONFIG_H)
  17. #include "config.h"
  18. #endif
  19. #include <stdint.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <assert.h>
  23. #include <dbus/dbus.h>
  24. #include "jackdbus.h"
  25. static char g_xml_data[102400];
  26. static
  27. void
  28. jack_controller_dbus_introspect(
  29. struct jack_dbus_method_call * call)
  30. {
  31. jack_dbus_construct_method_return_single(
  32. call,
  33. DBUS_TYPE_STRING,
  34. (message_arg_t)(const char *)g_xml_data);
  35. }
  36. JACK_DBUS_METHOD_ARGUMENTS_BEGIN(Introspect)
  37. JACK_DBUS_METHOD_ARGUMENT("xml_data", "s", true)
  38. JACK_DBUS_METHOD_ARGUMENTS_END
  39. JACK_DBUS_METHODS_BEGIN
  40. JACK_DBUS_METHOD_DESCRIBE(Introspect, jack_controller_dbus_introspect)
  41. JACK_DBUS_METHODS_END
  42. JACK_DBUS_IFACE_BEGIN(g_jack_controller_iface_introspectable, "org.freedesktop.DBus.Introspectable")
  43. JACK_DBUS_IFACE_EXPOSE_METHODS
  44. JACK_DBUS_IFACE_END
  45. static char * g_buffer_ptr;
  46. static
  47. void
  48. write_line_format(const char * format, ...)
  49. {
  50. va_list ap;
  51. va_start(ap, format);
  52. g_buffer_ptr += vsprintf(g_buffer_ptr, format, ap);
  53. va_end(ap);
  54. }
  55. static
  56. void
  57. write_line(const char * line)
  58. {
  59. write_line_format("%s\n", line);
  60. }
  61. void jack_controller_introspect_init() __attribute__((constructor));
  62. void
  63. jack_controller_introspect_init()
  64. {
  65. struct jack_dbus_interface_descriptor ** interface_ptr_ptr;
  66. const struct jack_dbus_interface_method_descriptor * method_ptr;
  67. const struct jack_dbus_interface_method_argument_descriptor * method_argument_ptr;
  68. const struct jack_dbus_interface_signal_descriptor * signal_ptr;
  69. const struct jack_dbus_interface_signal_argument_descriptor * signal_argument_ptr;
  70. g_buffer_ptr = g_xml_data;
  71. write_line("<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"");
  72. write_line("\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">");
  73. write_line("<node name=\"" JACK_CONTROLLER_OBJECT_PATH "\">");
  74. interface_ptr_ptr = g_jackcontroller_interfaces;
  75. while (*interface_ptr_ptr != NULL)
  76. {
  77. write_line_format(" <interface name=\"%s\">\n", (*interface_ptr_ptr)->name);
  78. if ((*interface_ptr_ptr)->methods != NULL)
  79. {
  80. method_ptr = (*interface_ptr_ptr)->methods;
  81. while (method_ptr->name != NULL)
  82. {
  83. write_line_format(" <method name=\"%s\">\n", method_ptr->name);
  84. method_argument_ptr = method_ptr->arguments;
  85. while (method_argument_ptr->name != NULL)
  86. {
  87. write_line_format(
  88. " <arg name=\"%s\" type=\"%s\" direction=\"%s\" />\n",
  89. method_argument_ptr->name,
  90. method_argument_ptr->type,
  91. method_argument_ptr->direction_out ? "out" : "in");
  92. method_argument_ptr++;
  93. }
  94. write_line(" </method>");
  95. method_ptr++;
  96. }
  97. }
  98. if ((*interface_ptr_ptr)->signals != NULL)
  99. {
  100. signal_ptr = (*interface_ptr_ptr)->signals;
  101. while (signal_ptr->name != NULL)
  102. {
  103. write_line_format(" <signal name=\"%s\">\n", signal_ptr->name);
  104. signal_argument_ptr = signal_ptr->arguments;
  105. while (signal_argument_ptr->name != NULL)
  106. {
  107. write_line_format(
  108. " <arg name=\"%s\" type=\"%s\" />\n",
  109. signal_argument_ptr->name,
  110. signal_argument_ptr->type);
  111. signal_argument_ptr++;
  112. }
  113. write_line(" </signal>");
  114. signal_ptr++;
  115. }
  116. }
  117. write_line(" </interface>");
  118. interface_ptr_ptr++;
  119. }
  120. write_line("</node>");
  121. *g_buffer_ptr = 0;
  122. }