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.

153 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. #include <stdint.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <assert.h>
  20. #include <dbus/dbus.h>
  21. #include "jackdbus.h"
  22. static char g_xml_data[102400];
  23. static
  24. void
  25. jack_controller_dbus_introspect(
  26. struct jack_dbus_method_call * call)
  27. {
  28. jack_dbus_construct_method_return_single(
  29. call,
  30. DBUS_TYPE_STRING,
  31. (message_arg_t)(const char *)g_xml_data);
  32. }
  33. JACK_DBUS_METHOD_ARGUMENTS_BEGIN(Introspect)
  34. JACK_DBUS_METHOD_ARGUMENT("xml_data", "s", true)
  35. JACK_DBUS_METHOD_ARGUMENTS_END
  36. JACK_DBUS_METHODS_BEGIN
  37. JACK_DBUS_METHOD_DESCRIBE(Introspect, jack_controller_dbus_introspect)
  38. JACK_DBUS_METHODS_END
  39. JACK_DBUS_IFACE_BEGIN(g_jack_controller_iface_introspectable, "org.freedesktop.DBus.Introspectable")
  40. JACK_DBUS_IFACE_EXPOSE_METHODS
  41. JACK_DBUS_IFACE_END
  42. static char * g_buffer_ptr;
  43. static
  44. void
  45. write_line_format(const char * format, ...)
  46. {
  47. va_list ap;
  48. va_start(ap, format);
  49. g_buffer_ptr += vsprintf(g_buffer_ptr, format, ap);
  50. va_end(ap);
  51. }
  52. static
  53. void
  54. write_line(const char * line)
  55. {
  56. write_line_format("%s\n", line);
  57. }
  58. void jack_controller_introspect_init() __attribute__((constructor));
  59. void
  60. jack_controller_introspect_init()
  61. {
  62. struct jack_dbus_interface_descriptor ** interface_ptr_ptr;
  63. const struct jack_dbus_interface_method_descriptor * method_ptr;
  64. const struct jack_dbus_interface_method_argument_descriptor * method_argument_ptr;
  65. const struct jack_dbus_interface_signal_descriptor * signal_ptr;
  66. const struct jack_dbus_interface_signal_argument_descriptor * signal_argument_ptr;
  67. g_buffer_ptr = g_xml_data;
  68. write_line("<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"");
  69. write_line("\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">");
  70. write_line("<node name=\"" JACK_CONTROLLER_OBJECT_PATH "\">");
  71. interface_ptr_ptr = g_jackcontroller_interfaces;
  72. while (*interface_ptr_ptr != NULL)
  73. {
  74. write_line_format(" <interface name=\"%s\">\n", (*interface_ptr_ptr)->name);
  75. if ((*interface_ptr_ptr)->methods != NULL)
  76. {
  77. method_ptr = (*interface_ptr_ptr)->methods;
  78. while (method_ptr->name != NULL)
  79. {
  80. write_line_format(" <method name=\"%s\">\n", method_ptr->name);
  81. method_argument_ptr = method_ptr->arguments;
  82. while (method_argument_ptr->name != NULL)
  83. {
  84. write_line_format(
  85. " <arg name=\"%s\" type=\"%s\" direction=\"%s\" />\n",
  86. method_argument_ptr->name,
  87. method_argument_ptr->type,
  88. method_argument_ptr->direction_out ? "out" : "in");
  89. method_argument_ptr++;
  90. }
  91. write_line(" </method>");
  92. method_ptr++;
  93. }
  94. }
  95. if ((*interface_ptr_ptr)->signals != NULL)
  96. {
  97. signal_ptr = (*interface_ptr_ptr)->signals;
  98. while (signal_ptr->name != NULL)
  99. {
  100. write_line_format(" <signal name=\"%s\">\n", signal_ptr->name);
  101. signal_argument_ptr = signal_ptr->arguments;
  102. while (signal_argument_ptr->name != NULL)
  103. {
  104. write_line_format(
  105. " <arg name=\"%s\" type=\"%s\" />\n",
  106. signal_argument_ptr->name,
  107. signal_argument_ptr->type);
  108. signal_argument_ptr++;
  109. }
  110. write_line(" </signal>");
  111. signal_ptr++;
  112. }
  113. }
  114. write_line(" </interface>");
  115. interface_ptr_ptr++;
  116. }
  117. write_line("</node>");
  118. *g_buffer_ptr = 0;
  119. }