2 This file is part of PulseAudio.
4 Copyright 2009 Tanu Kaskinen
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <dbus/dbus.h>
28 #include <pulse/xmalloc.h>
30 #include <pulsecore/dbus-common.h>
31 #include <pulsecore/macro.h>
35 #define OBJECT_NAME "/org/pulseaudio/core"
36 #define INTERFACE_NAME "org.pulseaudio.Core"
38 struct pa_dbusobj_core
{
42 static const char *introspection_snippet
=
43 " <interface name=\""INTERFACE_NAME
"\">"
44 " <method name=\"Test\">"
45 " <arg name=\"result\" type=\"s\" direction=\"out\"/>"
49 static const char *methods
[] = {
54 static DBusHandlerResult
handle_test(DBusConnection
*conn
, DBusMessage
*msg
, pa_dbusobj_core
*c
) {
55 DBusMessage
*reply
= NULL
;
56 const char *reply_message
= "Hello!";
62 if (!(reply
= dbus_message_new_method_return(msg
)))
65 if (!dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &reply_message
, DBUS_TYPE_INVALID
))
68 if (!dbus_connection_send(conn
, reply
, NULL
))
71 dbus_message_unref(reply
);
73 return DBUS_HANDLER_RESULT_HANDLED
;
77 dbus_message_unref(reply
);
79 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
83 dbus_message_unref(reply
);
85 return DBUS_HANDLER_RESULT_NEED_MEMORY
;
88 static DBusHandlerResult
receive_cb(DBusConnection
*connection
, DBusMessage
*message
, void *user_data
) {
89 pa_dbusobj_core
*c
= user_data
;
91 pa_assert(connection
);
95 if (dbus_message_is_method_call(message
, INTERFACE_NAME
, "Test"))
96 return handle_test(connection
, message
, c
);
98 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
101 pa_dbusobj_core
*pa_dbusobj_core_new(pa_core
*core
) {
106 c
= pa_xnew(pa_dbusobj_core
, 1);
109 pa_dbus_add_interface(core
, OBJECT_NAME
, INTERFACE_NAME
, methods
, introspection_snippet
, receive_cb
, c
);
114 void pa_dbusobj_core_free(pa_dbusobj_core
*c
) {
117 pa_dbus_remove_interface(c
->core
, OBJECT_NAME
, INTERFACE_NAME
);