NEWS -> CHANGELOG.rst -> NEWS.rst
[a2jmidid.git] / dbus_iface_introspectable.c
blob284b8c79b0ea23c8508f740e54a263e7698053d3
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 #include <stdbool.h>
23 #include <stdio.h>
24 #include <dbus/dbus.h>
26 #include "dbus_internal.h"
28 static char g_xml_data[102400];
30 static
31 void
32 a2j_dbus_introspect(
33 struct a2j_dbus_method_call * call)
35 const char * data;
37 data = g_xml_data;
39 a2j_dbus_construct_method_return_single(
40 call,
41 DBUS_TYPE_STRING,
42 &data);
45 A2J_DBUS_METHOD_ARGUMENTS_BEGIN(Introspect)
46 A2J_DBUS_METHOD_ARGUMENT("xml_data", DBUS_TYPE_STRING_AS_STRING, A2J_DBUS_DIRECTION_OUT)
47 A2J_DBUS_METHOD_ARGUMENTS_END
49 A2J_DBUS_METHODS_BEGIN
50 A2J_DBUS_METHOD_DESCRIBE(Introspect, a2j_dbus_introspect)
51 A2J_DBUS_METHODS_END
53 A2J_DBUS_IFACE_BEGIN(g_a2j_iface_introspectable, "org.freedesktop.DBus.Introspectable")
54 A2J_DBUS_IFACE_EXPOSE_METHODS
55 A2J_DBUS_IFACE_END
57 static char * g_buffer_ptr;
59 static
60 void
61 write_line_format(const char * format, ...)
63 va_list ap;
65 va_start(ap, format);
66 g_buffer_ptr += vsprintf(g_buffer_ptr, format, ap);
67 va_end(ap);
70 static
71 void
72 write_line(const char * line)
74 write_line_format("%s\n", line);
77 void a2j_introspect_init() __attribute__((constructor));
79 void
80 a2j_introspect_init()
82 struct a2j_dbus_interface_descriptor ** interface_ptr_ptr;
83 const struct a2j_dbus_interface_method_descriptor * method_ptr;
84 const struct a2j_dbus_interface_method_argument_descriptor * method_argument_ptr;
85 const struct a2j_dbus_interface_signal_descriptor * signal_ptr;
86 const struct a2j_dbus_interface_signal_argument_descriptor * signal_argument_ptr;
88 g_buffer_ptr = g_xml_data;
90 write_line("<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"");
91 write_line("\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">");
93 write_line("<node name=\"" A2J_DBUS_OBJECT_PATH "\">");
95 interface_ptr_ptr = g_a2j_dbus_interfaces;
97 while (*interface_ptr_ptr != NULL)
99 write_line_format(" <interface name=\"%s\">\n", (*interface_ptr_ptr)->name);
101 if ((*interface_ptr_ptr)->methods != NULL)
103 method_ptr = (*interface_ptr_ptr)->methods;
104 while (method_ptr->name != NULL)
106 write_line_format(" <method name=\"%s\">\n", method_ptr->name);
108 method_argument_ptr = method_ptr->arguments;
110 while (method_argument_ptr->name != NULL)
112 write_line_format(
113 " <arg name=\"%s\" type=\"%s\" direction=\"%s\" />\n",
114 method_argument_ptr->name,
115 method_argument_ptr->type,
116 method_argument_ptr->direction_out ? "out" : "in");
117 method_argument_ptr++;
120 write_line(" </method>");
121 method_ptr++;
125 if ((*interface_ptr_ptr)->signals != NULL)
127 signal_ptr = (*interface_ptr_ptr)->signals;
128 while (signal_ptr->name != NULL)
130 write_line_format(" <signal name=\"%s\">\n", signal_ptr->name);
132 signal_argument_ptr = signal_ptr->arguments;
134 while (signal_argument_ptr->name != NULL)
136 write_line_format(
137 " <arg name=\"%s\" type=\"%s\" />\n",
138 signal_argument_ptr->name,
139 signal_argument_ptr->type);
140 signal_argument_ptr++;
143 write_line(" </signal>");
144 signal_ptr++;
148 write_line(" </interface>");
149 interface_ptr_ptr++;
152 write_line("</node>");
154 *g_buffer_ptr = 0;