]> code.delx.au - pulseaudio/blob - src/pulsecore/dbus-objs/core.c
f59c478a2d005e13f904f1cf71d9e96ea2553ec9
[pulseaudio] / src / pulsecore / dbus-objs / core.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2009 Tanu Kaskinen
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <dbus/dbus.h>
27
28 #include <pulse/xmalloc.h>
29
30 #include <pulsecore/dbus-common.h>
31 #include <pulsecore/macro.h>
32
33 #include "core.h"
34
35 #define OBJECT_NAME "/org/pulseaudio/core"
36 #define INTERFACE_NAME "org.pulseaudio.Core"
37
38 struct pa_dbusobj_core {
39 pa_core *core;
40 };
41
42 static const char *introspection_snippet =
43 " <interface name=\""INTERFACE_NAME"\">"
44 " <method name=\"Test\">"
45 " <arg name=\"result\" type=\"s\" direction=\"out\"/>"
46 " </method>"
47 " </interface>";
48
49 static const char *methods[] = {
50 "Test",
51 NULL
52 };
53
54 static DBusHandlerResult handle_test(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_core *c) {
55 DBusMessage *reply = NULL;
56 const char *reply_message = "Hello!";
57
58 pa_assert(conn);
59 pa_assert(msg);
60 pa_assert(c);
61
62 if (!(reply = dbus_message_new_method_return(msg)))
63 goto oom;
64
65 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &reply_message, DBUS_TYPE_INVALID))
66 goto fail;
67
68 if (!dbus_connection_send(conn, reply, NULL))
69 goto oom;
70
71 dbus_message_unref(reply);
72
73 return DBUS_HANDLER_RESULT_HANDLED;
74
75 fail:
76 if (reply)
77 dbus_message_unref(reply);
78
79 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
80
81 oom:
82 if (reply)
83 dbus_message_unref(reply);
84
85 return DBUS_HANDLER_RESULT_NEED_MEMORY;
86 }
87
88 static DBusHandlerResult receive_cb(DBusConnection *connection, DBusMessage *message, void *user_data) {
89 pa_dbusobj_core *c = user_data;
90
91 pa_assert(connection);
92 pa_assert(message);
93 pa_assert(c);
94
95 if (dbus_message_is_method_call(message, INTERFACE_NAME, "Test"))
96 return handle_test(connection, message, c);
97
98 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
99 }
100
101 pa_dbusobj_core *pa_dbusobj_core_new(pa_core *core) {
102 pa_dbusobj_core *c;
103
104 pa_assert(core);
105
106 c = pa_xnew(pa_dbusobj_core, 1);
107 c->core = core;
108
109 pa_dbus_add_interface(core, OBJECT_NAME, INTERFACE_NAME, methods, introspection_snippet, receive_cb, c);
110
111 return c;
112 }
113
114 void pa_dbusobj_core_free(pa_dbusobj_core *c) {
115 pa_assert(c);
116
117 pa_dbus_remove_interface(c->core, OBJECT_NAME, INTERFACE_NAME);
118
119 pa_xfree(c);
120 }