10 #include <security-server.h>
11 #define COOKIE_SIZE 20
14 #include "include/mm_sound_mgr_ipc_dbus.h"
15 #include "include/mm_sound_mgr_ipc.h"
16 #include "../include/mm_sound_dbus.h"
19 #define BUS_NAME_SOUND_SERVER "org.tizen.SoundServer"
20 #define OBJECT_SOUND_SERVER "/org/tizen/SoundServer1"
21 #define INTERFACE_SOUND_SERVER "org.tizen.SoundServer1"
23 /* workaround for AF volume gain tuning */
24 #define PROC_DBUS_OBJECT "/Org/Tizen/ResourceD/Process"
25 #define PROC_DBUS_INTERFACE "org.tizen.resourced.process"
26 #define PROC_DBUS_METHOD "ProcExclude"
28 /* Introspection data for the service we are exporting */
29 static const gchar introspection_xml[] =
31 " <interface name='org.tizen.SoundServer1'>"
32 " <method name='MethodTest1'>"
33 " <arg type='i' name='num1' direction='in'/>"
34 " <arg type='i' name='num2' direction='in'/>"
35 " <arg type='i' name='multiple' direction='out'/>"
37 " <method name='GetBTA2DPStatus'>"
38 " <arg type='b' name='is_bt_on' direction='out'/>"
39 " <arg type='s' name='bt_name' direction='out'/>"
41 " <method name='PlayFileStart'>"
42 " <arg type='s' name='filename' direction='in'/>"
43 " <arg type='i' name='tone' direction='in'/>"
44 " <arg type='i' name='repeat' direction='in'/>"
45 " <arg type='i' name='volume' direction='in'/>"
46 " <arg type='i' name='vol_config' direction='in'/>"
47 " <arg type='i' name='priority' direction='in'/>"
48 " <arg type='i' name='session_type' direction='in'/>"
49 " <arg type='i' name='session_option' direction='in'/>"
50 " <arg type='i' name='client_pid' direction='in'/>"
51 " <arg type='i' name='handle_route' direction='in'/>"
52 " <arg type='b' name='enable_session' direction='in'/>"
53 " <arg type='s' name='stream_type' direction='in'/>"
54 " <arg type='i' name='stream_index' direction='in'/>"
55 " <arg type='i' name='handle' direction='out'/>"
57 " <method name='PlayFileStartWithStreamInfo'>"
58 " <arg type='s' name='filename' direction='in'/>"
59 " <arg type='i' name='repeat' direction='in'/>"
60 " <arg type='i' name='volume' direction='in'/>"
61 " <arg type='i' name='priority' direction='in'/>"
62 " <arg type='i' name='client_pid' direction='in'/>"
63 " <arg type='i' name='handle_route' direction='in'/>"
64 " <arg type='s' name='stream_type' direction='in'/>"
65 " <arg type='i' name='stream_index' direction='in'/>"
66 " <arg type='i' name='handle' direction='out'/>"
68 " <method name='PlayFileStop'>"
69 " <arg type='i' name='handle' direction='in'/>"
71 " <method name='ClearFocus'>"
72 " <arg type='i' name='pid' direction='in'/>"
74 " <method name='PlayDTMF'>"
75 " <arg type='i' name='tone' direction='in'/>"
76 " <arg type='i' name='repeat' direction='in'/>"
77 " <arg type='i' name='volume' direction='in'/>"
78 " <arg type='i' name='vol_config' direction='in'/>"
79 " <arg type='i' name='session_type' direction='in'/>"
80 " <arg type='i' name='session_option' direction='in'/>"
81 " <arg type='i' name='client_pid' direction='in'/>"
82 " <arg type='b' name='enable_session' direction='in'/>"
83 " <arg type='s' name='stream_type' direction='in'/>"
84 " <arg type='i' name='stream_index' direction='in'/>"
85 " <arg type='i' name='handle' direction='out'/>"
87 " <method name='PlayDTMFWithStreamInfo'>"
88 " <arg type='i' name='tone' direction='in'/>"
89 " <arg type='i' name='repeat' direction='in'/>"
90 " <arg type='i' name='volume' direction='in'/>"
91 " <arg type='i' name='client_pid' direction='in'/>"
92 " <arg type='s' name='stream_type' direction='in'/>"
93 " <arg type='i' name='stream_index' direction='in'/>"
94 " <arg type='i' name='handle' direction='out'/>"
96 " <method name='GetConnectedDeviceList'>"
97 " <arg type='i' name='device_mask' direction='in'/>"
98 " <arg type='a(iiiis)' name='device_list' direction='out'/>"
102 static GDBusConnection* conn_g;
104 static void handle_method_play_file_start(GDBusMethodInvocation* invocation);
105 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation);
106 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation);
107 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation);
108 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation);
109 static void handle_method_clear_focus(GDBusMethodInvocation* invocation);
110 static void handle_method_test(GDBusMethodInvocation* invocation);
111 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation);
113 /* Currently , Just using method's name and handler */
114 /* TODO : generate introspection xml automatically, with these value include argument and reply */
115 /* TODO : argument check with these information */
116 /* TODO : divide object and interface with features (ex. play, path, device) */
117 static mm_sound_dbus_method_intf_t methods[AUDIO_METHOD_MAX] = {
118 [AUDIO_METHOD_TEST] = {
120 .name = "MethodTest1",
122 .handler = handle_method_test
124 [AUDIO_METHOD_PLAY_FILE_START] = {
126 .name = "PlayFileStart",
128 .handler = handle_method_play_file_start
130 [AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO] = {
132 .name = "PlayFileStartWithStreamInfo",
134 .handler = handle_method_play_file_start_with_stream_info
136 [AUDIO_METHOD_PLAY_FILE_STOP] = {
138 .name = "PlayFileStop",
140 .handler = handle_method_play_file_stop
142 [AUDIO_METHOD_CLEAR_FOCUS] = {
144 .name = "ClearFocus",
146 .handler = handle_method_clear_focus
148 [AUDIO_METHOD_PLAY_DTMF] = {
152 .handler = handle_method_play_dtmf
154 [AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO] = {
156 .name = "PlayDTMFWithStreamInfo",
158 .handler = handle_method_play_dtmf_with_stream_info
160 [AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST] = {
162 .name = "GetConnectedDeviceList",
164 .handler = handle_method_get_connected_device_list
168 static GDBusNodeInfo *introspection_data = NULL;
169 guint sound_server_owner_id ;
172 For pass error code with 'g_dbus_method_invocation_return_error'
173 We have to use some glib features like GError, GQuark
175 /* Only For error types which is currently being used in server-side */
176 static const GDBusErrorEntry mm_sound_error_entries[] =
178 {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
179 {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
180 {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
181 {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
182 {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
183 {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
184 {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
185 {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
186 {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
187 {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
188 {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
189 {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
190 {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
191 {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
192 {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
193 {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
194 {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
195 {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
196 {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
199 static const char* _convert_error_code(int err_code)
203 for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
204 if (err_code == mm_sound_error_entries[i].error_code) {
205 return mm_sound_error_entries[i].dbus_error_name;
209 return "org.tizen.multimedia.common.Unknown";
212 static int mm_sound_mgr_ipc_dbus_send_signal(audio_event_t event, GVariant *parameter)
214 if(mm_sound_dbus_emit_signal(AUDIO_PROVIDER_SOUND_SERVER, event, parameter) != MM_ERROR_NONE) {
215 debug_error("Sound Server Emit signal failed");
216 return MM_ERROR_SOUND_INTERNAL;
218 return MM_ERROR_NONE;
221 static int _get_sender_pid(GDBusMethodInvocation* invocation)
226 GDBusConnection * connection = NULL;
229 connection = g_dbus_method_invocation_get_connection(invocation);
230 sender = g_dbus_method_invocation_get_sender(invocation);
232 debug_error ("connection = %p, sender = %s", connection, sender);
234 value = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
235 "org.freedesktop.DBus", "GetConnectionUnixProcessID",
236 g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
238 g_variant_get(value, "(u)", &pid);
239 debug_error ("Sender PID = [%d]", pid);
241 debug_error ("err code = %d, err msg = %s", err->code, err->message);
246 static void _method_call_return_value(GDBusMethodInvocation *invocation, GVariant *params)
248 const char *method_name;
249 method_name = g_dbus_method_invocation_get_method_name(invocation);
250 debug_error("Method Call '%s' success", method_name);
251 g_dbus_method_invocation_return_value(invocation, params);
253 static void _method_call_return_error(GDBusMethodInvocation *invocation, int ret)
255 const char *err_name, *method_name;
256 err_name = _convert_error_code(ret);
257 method_name = g_dbus_method_invocation_get_method_name(invocation);
258 debug_error("Method Call '%s' failed, err '%s(%X)'", method_name, err_name, ret);
259 g_dbus_method_invocation_return_dbus_error(invocation, err_name, "failed");
262 static void handle_method_test(GDBusMethodInvocation* invocation)
264 int ret = MM_ERROR_NONE;
265 int val = 0, val2 = 0;
266 GVariant* params = NULL;
270 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
271 debug_error("Parameter for Method is NULL");
272 ret = MM_ERROR_SOUND_INTERNAL;
276 g_variant_get(params, "(ii)", &val, &val2);
277 debug_log("Got value : %d , %d", val, val2);
279 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_TEST, g_variant_new("(i)", val+val2))) != MM_ERROR_NONE) {
280 debug_error("signal send error : %X", ret);
282 debug_error("signal send success");
286 if (ret == MM_ERROR_NONE) {
287 _method_call_return_value(invocation, g_variant_new("(i)", val * val2));
289 ret = MM_ERROR_INVALID_ARGUMENT;
290 _method_call_return_error(invocation, ret);
296 static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
298 gchar* filename = NULL;
299 char *stream_type = NULL;
300 gint32 ret = MM_ERROR_NONE, slotid = 0;
301 gint32 tone = 0, repeat = 0, volume = 0, vol_config = 0, priority = 0;
302 gint32 session_type = 0, session_option = 0, pid = 0, handle_route =0, stream_index = 0;
303 gboolean enable_session = 0;
304 GVariant *params = NULL;
308 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
309 debug_error("Parameter for Method is NULL");
310 ret = MM_ERROR_SOUND_INTERNAL;
314 g_variant_get(params, "(siiiiiiiiibsi)", &filename, &tone, &repeat, &volume,
315 &vol_config, &priority, &session_type, &session_option, &pid, &handle_route, &enable_session, &stream_type, &stream_index);
317 debug_error("filename null");
318 ret = MM_ERROR_SOUND_INTERNAL;
321 ret = _MMSoundMgrIpcPlayFile(filename, tone, repeat, volume, vol_config, priority,
322 session_type, session_option, _get_sender_pid(invocation), handle_route, enable_session, &slotid, stream_type, stream_index);
325 if (ret == MM_ERROR_NONE) {
326 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
328 _method_call_return_error(invocation, ret);
334 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation)
336 gchar* filename = NULL;
337 char *stream_type = NULL;
338 gint32 ret = MM_ERROR_NONE, slotid = 0;
339 gint32 repeat = 0, volume = 0, priority = 0, pid = 0, handle_route =0, stream_index = 0;
340 GVariant *params = NULL;
344 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
345 debug_error("Parameter for Method is NULL");
346 ret = MM_ERROR_SOUND_INTERNAL;
350 g_variant_get(params, "(siiiiisi)", &filename, &repeat, &volume,
351 &priority, &pid, &handle_route, &stream_type, &stream_index);
353 debug_error("filename null");
354 ret = MM_ERROR_SOUND_INTERNAL;
357 ret = _MMSoundMgrIpcPlayFileWithStreamInfo(filename, repeat, volume, priority,
358 _get_sender_pid(invocation), handle_route, &slotid, stream_type, stream_index);
361 if (ret == MM_ERROR_NONE) {
362 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
364 _method_call_return_error(invocation, ret);
370 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation)
372 int ret = MM_ERROR_NONE, slotid = 0;
373 int tone = 0, repeat = 0, volume = 0, vol_config = 0, session_type = 0, session_option = 0, pid = 0, stream_index = 0;
374 char* stream_type = NULL;
375 gboolean enable_session = 0;
376 GVariant *params = NULL;
380 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
381 debug_error("Parameter for Method is NULL");
382 ret = MM_ERROR_SOUND_INTERNAL;
386 g_variant_get(params, "(iiiiiiibsi)", &tone, &repeat, &volume,
387 &vol_config, &session_type, &session_option, &pid, &enable_session, &stream_type, &stream_index);
388 debug_error("volume - %d", volume);
389 ret = _MMSoundMgrIpcPlayDTMF(tone, repeat, volume, vol_config,
390 session_type, session_option, _get_sender_pid(invocation), enable_session, &slotid, stream_type, stream_index);
393 if (ret == MM_ERROR_NONE) {
394 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
396 _method_call_return_error(invocation, ret);
403 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation)
405 int ret = MM_ERROR_NONE, slotid = 0;
406 int tone = 0, repeat = 0, volume = 0, pid = 0, stream_index = 0;
407 char* stream_type = NULL;
408 GVariant *params = NULL;
412 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
413 debug_error("Parameter for Method is NULL");
414 ret = MM_ERROR_SOUND_INTERNAL;
418 g_variant_get(params, "(iiiisi)", &tone, &repeat, &volume, &pid, &stream_type, &stream_index);
419 ret = _MMSoundMgrIpcPlayDTMFWithStreamInfo(tone, repeat, volume, _get_sender_pid(invocation), &slotid, stream_type, stream_index);
422 if (ret == MM_ERROR_NONE) {
423 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
425 _method_call_return_error(invocation, ret);
431 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation)
433 int ret = MM_ERROR_NONE;
435 GVariant *params = NULL;
439 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
440 debug_error("Parameter for Method is NULL");
441 ret = MM_ERROR_SOUND_INTERNAL;
445 g_variant_get(params, "(i)", &handle);
446 ret = _MMSoundMgrIpcStop(handle);
449 if (ret == MM_ERROR_NONE) {
450 _method_call_return_value(invocation, g_variant_new("()"));
452 _method_call_return_error(invocation, ret);
458 static void handle_method_clear_focus(GDBusMethodInvocation* invocation)
460 int ret = MM_ERROR_NONE;
462 GVariant *params = NULL;
466 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
467 debug_error("Parameter for Method is NULL");
468 ret = MM_ERROR_SOUND_INTERNAL;
472 g_variant_get(params, "(i)", &pid);
473 ret = _MMSoundMgrIpcClearFocus(pid);
476 if (ret == MM_ERROR_NONE) {
477 _method_call_return_value(invocation, g_variant_new("()"));
479 _method_call_return_error(invocation, ret);
485 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation)
487 int ret = MM_ERROR_NONE;
488 GVariant *params = NULL;
489 GVariantBuilder reply_builder;
491 int devices_num = 0, device_idx = 0;
492 mm_sound_device_t *device_list = NULL, *device_entry = NULL;
494 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
495 debug_error("Parameter for Method is NULL");
496 ret = MM_ERROR_SOUND_INTERNAL;
500 g_variant_get(params, "(i)", &mask_flags);
501 debug_log("Get device list with device_flag %X", mask_flags);
502 if ((ret = __mm_sound_mgr_ipc_get_current_connected_device_list(mask_flags, &device_list, &devices_num))==MM_ERROR_NONE) {
503 g_variant_builder_init(&reply_builder, G_VARIANT_TYPE("(a(iiiis))"));
504 g_variant_builder_open(&reply_builder, G_VARIANT_TYPE("a(iiiis)"));
505 for (device_idx = 0; device_idx < devices_num; device_idx++) {
506 device_entry = &device_list[device_idx];
507 // debug_log("device(%d): id(%d), type(%d), io(%d), state(%d), name(%s) ", device_idx, device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
508 g_variant_builder_add(&reply_builder, "(iiiis)", device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
510 g_variant_builder_close(&reply_builder);
514 if (ret == MM_ERROR_NONE) {
515 _method_call_return_value(invocation, g_variant_builder_end(&reply_builder));
516 debug_log("Reply Sent");
518 _method_call_return_error(invocation, ret);
522 static void handle_method_call(GDBusConnection *connection,
524 const gchar *object_path,
525 const gchar *interface_name,
526 const gchar *method_name,
527 GVariant *parameters,
528 GDBusMethodInvocation *invocation,
534 debug_error("Parameter Null");
537 debug_log("Method Call, obj : %s, intf : %s, method : %s", object_path, interface_name, method_name);
539 for (method_idx = 0; method_idx < AUDIO_METHOD_MAX; method_idx++) {
540 if (!g_strcmp0(method_name, methods[method_idx].info.name)) {
541 methods[method_idx].handler(invocation);
547 static GVariant* handle_get_property(GDBusConnection *connection,
549 const gchar *object_path,
550 const gchar *interface_name,
551 const gchar *property_name,
555 debug_log("Get Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
559 static gboolean handle_set_property(GDBusConnection *connection,
561 const gchar *object_path,
562 const gchar *interface_name,
563 const gchar *property_name,
568 debug_log("Set Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
572 static const GDBusInterfaceVTable interface_vtable =
579 static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
582 debug_log("Bus Acquired (%s)", name);
585 reg_id = g_dbus_connection_register_object(connection,
587 introspection_data->interfaces[0],
593 debug_error("Register object(%s) failed", OBJECT_SOUND_SERVER);
599 static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
601 debug_log("Name Acquired (%s)", name);
604 static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
606 debug_log("Name Lost (%s)", name);
609 static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_name, guint* owner_id)
613 debug_log("Own name (%s) for sound-server", wellknown_name);
615 oid = g_bus_own_name(bus_type, wellknown_name , G_BUS_NAME_OWNER_FLAGS_NONE,
616 on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
618 debug_error("Dbus own name failed");
619 return MM_ERROR_SOUND_INTERNAL;
624 return MM_ERROR_NONE;
627 static void _mm_sound_mgr_dbus_unown_name(guint oid)
629 debug_log("Unown name for Sound-Server");
631 g_bus_unown_name(oid);
635 int __mm_sound_mgr_ipc_dbus_notify_device_connected (mm_sound_device_t *device, gboolean is_connected)
637 int ret = MM_ERROR_NONE;
638 GVariantBuilder builder;
639 GVariant* param = NULL;
641 debug_log("Send device connected signal");
643 g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)b)"));
644 g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
645 g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
646 g_variant_builder_close(&builder);
647 g_variant_builder_add(&builder, "b", is_connected);
648 param = g_variant_builder_end(&builder);
650 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_DEVICE_CONNECTED, param))!= MM_ERROR_NONE) {
651 debug_error("Send device connected signal failed");
654 debug_error("Build variant for dbus param failed");
660 int __mm_sound_mgr_ipc_dbus_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type)
662 int ret = MM_ERROR_NONE;
663 GVariantBuilder builder;
664 GVariant* param = NULL;
666 debug_log("Send device info changed signal");
668 g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)i)"));
669 g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
670 g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
671 g_variant_builder_close(&builder);
672 g_variant_builder_add(&builder, "i", changed_device_info_type);
673 param = g_variant_builder_end(&builder);
675 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_DEVICE_INFO_CHANGED, param)) != MM_ERROR_NONE) {
676 debug_error("Send device info changed signal failed");
679 debug_error("Build variant for dbus param failed");
685 int __mm_sound_mgr_ipc_dbus_notify_volume_changed(unsigned int vol_type, unsigned int value)
687 int ret = MM_ERROR_NONE;
688 GVariant* param = NULL;
690 debug_log("Send Signal volume changed signal");
692 param = g_variant_new("(uu)", vol_type, value);
694 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_VOLUME_CHANGED, param)) != MM_ERROR_NONE) {
695 debug_error("Send device connected signal failed");
698 debug_error("Build variant for dbus param failed");
704 int __mm_sound_mgr_ipc_dbus_notify_play_file_end(int handle)
706 int ret = MM_ERROR_NONE;
707 GVariant* param = NULL;
709 debug_log("Send play file ended signal");
711 param = g_variant_new("(i)", handle);
713 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_PLAY_FILE_END, param)) != MM_ERROR_NONE) {
714 debug_error("Send play file end for '%d' failed", handle);
717 debug_error("Build variant for dbus param failed");
723 int __mm_sound_mgr_ipc_dbus_notify_active_device_changed(int device_in, int device_out)
725 return MM_ERROR_SOUND_INTERNAL;
728 int __mm_sound_mgr_ipc_dbus_notify_available_device_changed(int device_in, int device_out, int available)
730 return MM_ERROR_SOUND_INTERNAL;
733 #define PA_BUS_NAME "org.pulseaudio.Server"
734 #define PA_STREAM_MANAGER_OBJECT_PATH "/org/pulseaudio/StreamManager"
735 #define PA_STREAM_MANAGER_INTERFACE "org.pulseaudio.StreamManager"
736 #define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST "GetStreamList"
737 int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
739 int ret = MM_ERROR_NONE;
740 GVariant *result = NULL;
741 GVariant *child = NULL;
742 GDBusConnection *conn = NULL;
746 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
748 LOGE("g_bus_get_sync() error (%s)", err->message);
750 ret = MM_ERROR_SOUND_INTERNAL;
753 result = g_dbus_connection_call_sync (conn,
755 PA_STREAM_MANAGER_OBJECT_PATH,
756 PA_STREAM_MANAGER_INTERFACE,
757 PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST,
759 G_VARIANT_TYPE("(vv)"),
760 G_DBUS_CALL_FLAGS_NONE,
764 if (!result && err) {
765 debug_error("g_dbus_connection_call_sync() error (%s)", err->message);
766 ret = MM_ERROR_SOUND_INTERNAL;
769 GVariant *item = NULL;
770 child = g_variant_get_child_value(result, 0);
771 item = g_variant_get_variant(child);
774 g_variant_iter_init(&iter, item);
775 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
776 debug_log ("name : %s", name);
777 stream_list->stream_types[i++] = strdup(name);
779 g_variant_iter_free (&iter);
780 g_variant_unref (item);
781 g_variant_unref (child);
783 child = g_variant_get_child_value(result, 1);
784 item = g_variant_get_variant(child);
787 g_variant_iter_init(&iter, item);
788 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
789 debug_log ("priority : %d", priority);
790 stream_list->priorities[i++] = priority;
792 g_variant_iter_free (&iter);
793 g_variant_unref (item);
794 g_variant_unref (child);
796 g_variant_unref(result);
798 g_object_unref(conn);
803 int MMSoundMgrDbusInit(void)
807 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
808 if (!introspection_data)
809 return MM_ERROR_SOUND_INTERNAL;
811 if (_mm_sound_mgr_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_SOUND_SERVER, &sound_server_owner_id) != MM_ERROR_NONE) {
812 debug_error ("dbus own name for sound-server error\n");
813 return MM_ERROR_SOUND_INTERNAL;
818 return MM_ERROR_NONE;
821 void MMSoundMgrDbusFini(void)
825 _mm_sound_mgr_dbus_unown_name(sound_server_owner_id);
826 g_dbus_node_info_unref (introspection_data);