Add new JackBasePosixMutex class.
[jack2.git] / dbus / controller_iface_introspectable.c
blob8b1a644ce6a21deb3a636f8ac8b0abf4c6af6d1e
1 /* -*- Mode: C ; c-basic-offset: 4 -*- */
2 /*
3 Copyright (C) 2007-2008 Nedko Arnaudov
4 Copyright (C) 2007-2008 Juuso Alasuutari
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.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #if defined(HAVE_CONFIG_H)
22 #include "config.h"
23 #endif
25 #include <stdint.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <assert.h>
29 #include <dbus/dbus.h>
31 #include "jackdbus.h"
33 static char g_xml_data[102400];
35 static
36 void
37 jack_controller_dbus_introspect(
38 struct jack_dbus_method_call * call)
40 jack_dbus_construct_method_return_single(
41 call,
42 DBUS_TYPE_STRING,
43 (message_arg_t)(const char *)g_xml_data);
46 JACK_DBUS_METHOD_ARGUMENTS_BEGIN(Introspect)
47 JACK_DBUS_METHOD_ARGUMENT("xml_data", "s", true)
48 JACK_DBUS_METHOD_ARGUMENTS_END
50 JACK_DBUS_METHODS_BEGIN
51 JACK_DBUS_METHOD_DESCRIBE(Introspect, jack_controller_dbus_introspect)
52 JACK_DBUS_METHODS_END
54 JACK_DBUS_IFACE_BEGIN(g_jack_controller_iface_introspectable, "org.freedesktop.DBus.Introspectable")
55 JACK_DBUS_IFACE_EXPOSE_METHODS
56 JACK_DBUS_IFACE_END
58 static char * g_buffer_ptr;
60 static
61 void
62 write_line_format(const char * format, ...)
64 va_list ap;
66 va_start(ap, format);
67 g_buffer_ptr += vsprintf(g_buffer_ptr, format, ap);
68 va_end(ap);
71 static
72 void
73 write_line(const char * line)
75 write_line_format("%s\n", line);
78 void jack_controller_introspect_init() __attribute__((constructor));
80 void
81 jack_controller_introspect_init()
83 struct jack_dbus_interface_descriptor ** interface_ptr_ptr;
84 const struct jack_dbus_interface_method_descriptor * method_ptr;
85 const struct jack_dbus_interface_method_argument_descriptor * method_argument_ptr;
86 const struct jack_dbus_interface_signal_descriptor * signal_ptr;
87 const struct jack_dbus_interface_signal_argument_descriptor * signal_argument_ptr;
89 g_buffer_ptr = g_xml_data;
91 write_line("<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"");
92 write_line("\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">");
94 write_line("<node name=\"" JACK_CONTROLLER_OBJECT_PATH "\">");
96 interface_ptr_ptr = g_jackcontroller_interfaces;
98 while (*interface_ptr_ptr != NULL)
100 write_line_format(" <interface name=\"%s\">\n", (*interface_ptr_ptr)->name);
102 if ((*interface_ptr_ptr)->methods != NULL)
104 method_ptr = (*interface_ptr_ptr)->methods;
105 while (method_ptr->name != NULL)
107 write_line_format(" <method name=\"%s\">\n", method_ptr->name);
109 method_argument_ptr = method_ptr->arguments;
111 while (method_argument_ptr->name != NULL)
113 write_line_format(
114 " <arg name=\"%s\" type=\"%s\" direction=\"%s\" />\n",
115 method_argument_ptr->name,
116 method_argument_ptr->type,
117 method_argument_ptr->direction_out ? "out" : "in");
118 method_argument_ptr++;
121 write_line(" </method>");
122 method_ptr++;
126 if ((*interface_ptr_ptr)->signals != NULL)
128 signal_ptr = (*interface_ptr_ptr)->signals;
129 while (signal_ptr->name != NULL)
131 write_line_format(" <signal name=\"%s\">\n", signal_ptr->name);
133 signal_argument_ptr = signal_ptr->arguments;
135 while (signal_argument_ptr->name != NULL)
137 write_line_format(
138 " <arg name=\"%s\" type=\"%s\" />\n",
139 signal_argument_ptr->name,
140 signal_argument_ptr->type);
141 signal_argument_ptr++;
144 write_line(" </signal>");
145 signal_ptr++;
149 write_line(" </interface>");
150 interface_ptr_ptr++;
153 write_line("</node>");
155 *g_buffer_ptr = 0;