9 #include "include/mm_sound_mgr_ipc_dbus.h"
10 #include "include/mm_sound_mgr_ipc.h"
11 #include "../include/mm_sound_dbus.h"
14 #define BUS_NAME_SOUND_SERVER "org.tizen.SoundServer"
15 #define OBJECT_SOUND_SERVER "/org/tizen/SoundServer1"
16 #define INTERFACE_SOUND_SERVER "org.tizen.SoundServer1"
18 /* workaround for AF volume gain tuning */
19 #define PROC_DBUS_OBJECT "/Org/Tizen/ResourceD/Process"
20 #define PROC_DBUS_INTERFACE "org.tizen.resourced.process"
21 #define PROC_DBUS_METHOD "ProcExclude"
23 /* Introspection data for the service we are exporting */
24 static const gchar introspection_xml[] =
26 " <interface name='org.tizen.SoundServer1'>"
27 " <method name='MethodTest1'>"
28 " <arg type='i' name='num1' direction='in'/>"
29 " <arg type='i' name='num2' direction='in'/>"
30 " <arg type='i' name='multiple' direction='out'/>"
32 " <method name='GetBTA2DPStatus'>"
33 " <arg type='b' name='is_bt_on' direction='out'/>"
34 " <arg type='s' name='bt_name' direction='out'/>"
36 " <method name='PlayFileStart'>"
37 " <arg type='s' name='filename' direction='in'/>"
38 " <arg type='i' name='tone' direction='in'/>"
39 " <arg type='i' name='repeat' direction='in'/>"
40 " <arg type='i' name='volume' direction='in'/>"
41 " <arg type='i' name='vol_config' direction='in'/>"
42 " <arg type='i' name='priority' direction='in'/>"
43 " <arg type='i' name='session_type' direction='in'/>"
44 " <arg type='i' name='session_option' direction='in'/>"
45 " <arg type='i' name='client_pid' direction='in'/>"
46 " <arg type='i' name='handle_route' direction='in'/>"
47 " <arg type='b' name='enable_session' direction='in'/>"
48 " <arg type='s' name='stream_type' direction='in'/>"
49 " <arg type='i' name='stream_index' direction='in'/>"
50 " <arg type='i' name='handle' direction='out'/>"
52 " <method name='PlayFileStartWithStreamInfo'>"
53 " <arg type='s' name='filename' direction='in'/>"
54 " <arg type='i' name='repeat' direction='in'/>"
55 " <arg type='i' name='volume' direction='in'/>"
56 " <arg type='i' name='priority' direction='in'/>"
57 " <arg type='i' name='client_pid' direction='in'/>"
58 " <arg type='i' name='handle_route' direction='in'/>"
59 " <arg type='s' name='stream_type' direction='in'/>"
60 " <arg type='i' name='stream_index' direction='in'/>"
61 " <arg type='i' name='handle' direction='out'/>"
63 " <method name='PlayFileStop'>"
64 " <arg type='i' name='handle' direction='in'/>"
66 #ifdef FOCUS_INTEGRATION
67 " <method name='ClearFocus'>"
68 " <arg type='i' name='pid' direction='in'/>"
71 " <method name='PlayDTMF'>"
72 " <arg type='i' name='tone' direction='in'/>"
73 " <arg type='i' name='repeat' direction='in'/>"
74 " <arg type='i' name='volume' direction='in'/>"
75 " <arg type='i' name='vol_config' direction='in'/>"
76 " <arg type='i' name='session_type' direction='in'/>"
77 " <arg type='i' name='session_option' direction='in'/>"
78 " <arg type='i' name='client_pid' direction='in'/>"
79 " <arg type='b' name='enable_session' direction='in'/>"
80 " <arg type='s' name='stream_type' direction='in'/>"
81 " <arg type='i' name='stream_index' direction='in'/>"
82 " <arg type='i' name='handle' direction='out'/>"
84 " <method name='PlayDTMFWithStreamInfo'>"
85 " <arg type='i' name='tone' direction='in'/>"
86 " <arg type='i' name='repeat' direction='in'/>"
87 " <arg type='i' name='volume' direction='in'/>"
88 " <arg type='i' name='client_pid' direction='in'/>"
89 " <arg type='s' name='stream_type' direction='in'/>"
90 " <arg type='i' name='stream_index' direction='in'/>"
91 " <arg type='i' name='handle' direction='out'/>"
93 " <method name='GetConnectedDeviceList'>"
94 " <arg type='i' name='device_mask' direction='in'/>"
95 " <arg type='a(iiiis)' name='device_list' direction='out'/>"
99 static GDBusConnection* conn_g;
101 static void handle_method_play_file_start(GDBusMethodInvocation* invocation);
102 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation);
103 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation);
104 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation);
105 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation);
106 #ifdef FOCUS_INTEGRATION
107 static void handle_method_clear_focus(GDBusMethodInvocation* invocation);
109 static void handle_method_test(GDBusMethodInvocation* invocation);
110 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation);
112 /* Currently , Just using method's name and handler */
113 /* TODO : generate introspection xml automatically, with these value include argument and reply */
114 /* TODO : argument check with these information */
115 /* TODO : divide object and interface with features (ex. play, path, device) */
116 static mm_sound_dbus_method_intf_t methods[AUDIO_METHOD_MAX] = {
117 [AUDIO_METHOD_TEST] = {
119 .name = "MethodTest1",
121 .handler = handle_method_test
123 [AUDIO_METHOD_PLAY_FILE_START] = {
125 .name = "PlayFileStart",
127 .handler = handle_method_play_file_start
129 [AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO] = {
131 .name = "PlayFileStartWithStreamInfo",
133 .handler = handle_method_play_file_start_with_stream_info
135 [AUDIO_METHOD_PLAY_FILE_STOP] = {
137 .name = "PlayFileStop",
139 .handler = handle_method_play_file_stop
141 #ifdef FOCUS_INTEGRATION
142 [AUDIO_METHOD_CLEAR_FOCUS] = {
144 .name = "ClearFocus",
146 .handler = handle_method_clear_focus
149 [AUDIO_METHOD_PLAY_DTMF] = {
153 .handler = handle_method_play_dtmf
155 [AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO] = {
157 .name = "PlayDTMFWithStreamInfo",
159 .handler = handle_method_play_dtmf_with_stream_info
161 [AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST] = {
163 .name = "GetConnectedDeviceList",
165 .handler = handle_method_get_connected_device_list
169 static GDBusNodeInfo *introspection_data = NULL;
170 guint sound_server_owner_id ;
173 For pass error code with 'g_dbus_method_invocation_return_error'
174 We have to use some glib features like GError, GQuark
176 /* Only For error types which is currently being used in server-side */
177 static const GDBusErrorEntry mm_sound_error_entries[] =
179 {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
180 {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
181 {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
182 {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
183 {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
184 {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
185 {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
186 {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
187 {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
188 {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
189 {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
190 {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
191 {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
192 {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
193 {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
194 {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
195 {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
196 {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
197 {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
200 static const char* _convert_error_code(int err_code)
204 for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
205 if (err_code == mm_sound_error_entries[i].error_code) {
206 return mm_sound_error_entries[i].dbus_error_name;
210 return "org.tizen.multimedia.common.Unknown";
213 static int mm_sound_mgr_ipc_dbus_send_signal(audio_event_t event, GVariant *parameter)
215 if(mm_sound_dbus_emit_signal(AUDIO_PROVIDER_SOUND_SERVER, event, parameter) != MM_ERROR_NONE) {
216 debug_error("Sound Server Emit signal failed");
217 return MM_ERROR_SOUND_INTERNAL;
219 return MM_ERROR_NONE;
222 static int _get_sender_pid(GDBusMethodInvocation* invocation)
227 GDBusConnection * connection = NULL;
230 connection = g_dbus_method_invocation_get_connection(invocation);
231 sender = g_dbus_method_invocation_get_sender(invocation);
233 debug_error("connection = %p, sender = %s", connection, sender);
235 value = g_dbus_connection_call_sync(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
236 "org.freedesktop.DBus", "GetConnectionUnixProcessID",
237 g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
239 g_variant_get(value, "(u)", &pid);
240 debug_msg("Sender PID = [%d]", pid);
241 g_variant_unref(value);
243 debug_error("err code = %d, err msg = %s", err->code, err->message);
248 static void _method_call_return_value(GDBusMethodInvocation *invocation, GVariant *params)
250 const char *method_name;
251 method_name = g_dbus_method_invocation_get_method_name(invocation);
252 debug_msg("Method Call '%s' success", method_name);
253 g_dbus_method_invocation_return_value(invocation, params);
255 static void _method_call_return_error(GDBusMethodInvocation *invocation, int ret)
257 const char *err_name, *method_name;
258 err_name = _convert_error_code(ret);
259 method_name = g_dbus_method_invocation_get_method_name(invocation);
260 debug_error("Method Call '%s' failed, err '%s(%X)'", method_name, err_name, ret);
261 g_dbus_method_invocation_return_dbus_error(invocation, err_name, "failed");
264 static void handle_method_test(GDBusMethodInvocation* invocation)
266 int ret = MM_ERROR_NONE;
267 int val = 0, val2 = 0;
268 GVariant *params = NULL;
272 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
273 debug_error("Parameter for Method is NULL");
274 ret = MM_ERROR_SOUND_INTERNAL;
278 g_variant_get(params, "(ii)", &val, &val2);
279 debug_log("Got value : %d , %d", val, val2);
281 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_TEST, g_variant_new("(i)", val+val2))) != MM_ERROR_NONE) {
282 debug_error("signal send error : %X", ret);
284 debug_error("signal send success");
288 if (ret == MM_ERROR_NONE) {
289 _method_call_return_value(invocation, g_variant_new("(i)", val * val2));
291 ret = MM_ERROR_INVALID_ARGUMENT;
292 _method_call_return_error(invocation, ret);
298 static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
300 gchar* filename = NULL;
301 char *stream_type = NULL;
302 gint32 ret = MM_ERROR_NONE, slotid = 0;
303 gint32 tone = 0, repeat = 0, volume = 0, vol_config = 0, priority = 0;
304 gint32 session_type = 0, session_option = 0, pid = 0, handle_route =0, stream_index = 0;
305 gboolean enable_session = 0;
306 GVariant *params = NULL;
310 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
311 debug_error("Parameter for Method is NULL");
312 ret = MM_ERROR_SOUND_INTERNAL;
316 g_variant_get(params, "(siiiiiiiiibsi)", &filename, &tone, &repeat, &volume,
317 &vol_config, &priority, &session_type, &session_option, &pid, &handle_route, &enable_session, &stream_type, &stream_index);
319 debug_error("filename null");
320 ret = MM_ERROR_SOUND_INTERNAL;
323 ret = _MMSoundMgrIpcPlayFile(filename, tone, repeat, volume, vol_config, priority,
324 session_type, session_option, _get_sender_pid(invocation), handle_route, enable_session, &slotid, stream_type, stream_index);
327 if (ret == MM_ERROR_NONE) {
328 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
330 _method_call_return_error(invocation, ret);
336 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation)
338 gchar* filename = NULL;
339 char *stream_type = NULL;
340 gint32 ret = MM_ERROR_NONE, slotid = 0;
341 gint32 repeat = 0, volume = 0, priority = 0, pid = 0, handle_route =0, stream_index = 0;
342 GVariant *params = NULL;
346 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
347 debug_error("Parameter for Method is NULL");
348 ret = MM_ERROR_SOUND_INTERNAL;
352 g_variant_get(params, "(siiiiisi)", &filename, &repeat, &volume,
353 &priority, &pid, &handle_route, &stream_type, &stream_index);
355 debug_error("filename null");
356 ret = MM_ERROR_SOUND_INTERNAL;
359 ret = _MMSoundMgrIpcPlayFileWithStreamInfo(filename, repeat, volume, priority,
360 _get_sender_pid(invocation), handle_route, &slotid, stream_type, stream_index);
363 if (ret == MM_ERROR_NONE) {
364 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
366 _method_call_return_error(invocation, ret);
372 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation)
374 int ret = MM_ERROR_NONE, slotid = 0;
375 int tone = 0, repeat = 0, volume = 0, vol_config = 0, session_type = 0, session_option = 0, pid = 0, stream_index = 0;
376 char* stream_type = NULL;
377 gboolean enable_session = 0;
378 GVariant *params = NULL;
382 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
383 debug_error("Parameter for Method is NULL");
384 ret = MM_ERROR_SOUND_INTERNAL;
388 g_variant_get(params, "(iiiiiiibsi)", &tone, &repeat, &volume,
389 &vol_config, &session_type, &session_option, &pid, &enable_session, &stream_type, &stream_index);
390 debug_error("volume - %d", volume);
391 ret = _MMSoundMgrIpcPlayDTMF(tone, repeat, volume, vol_config,
392 session_type, session_option, _get_sender_pid(invocation), enable_session, &slotid, stream_type, stream_index);
395 if (ret == MM_ERROR_NONE) {
396 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
398 _method_call_return_error(invocation, ret);
405 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation)
407 int ret = MM_ERROR_NONE, slotid = 0;
408 int tone = 0, repeat = 0, volume = 0, pid = 0, stream_index = 0;
409 char* stream_type = NULL;
410 GVariant *params = NULL;
414 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
415 debug_error("Parameter for Method is NULL");
416 ret = MM_ERROR_SOUND_INTERNAL;
420 g_variant_get(params, "(iiiisi)", &tone, &repeat, &volume, &pid, &stream_type, &stream_index);
421 ret = _MMSoundMgrIpcPlayDTMFWithStreamInfo(tone, repeat, volume, _get_sender_pid(invocation), &slotid, stream_type, stream_index);
424 if (ret == MM_ERROR_NONE) {
425 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
427 _method_call_return_error(invocation, ret);
433 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation)
435 int ret = MM_ERROR_NONE;
437 GVariant *params = NULL;
441 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
442 debug_error("Parameter for Method is NULL");
443 ret = MM_ERROR_SOUND_INTERNAL;
447 g_variant_get(params, "(i)", &handle);
448 ret = _MMSoundMgrIpcStop(handle);
451 if (ret == MM_ERROR_NONE) {
452 _method_call_return_value(invocation, g_variant_new("()"));
454 _method_call_return_error(invocation, ret);
460 #ifdef FOCUS_INTEGRATION
461 static void handle_method_clear_focus(GDBusMethodInvocation* invocation)
463 int ret = MM_ERROR_NONE;
465 GVariant *params = NULL;
469 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
470 debug_error("Parameter for Method is NULL");
471 ret = MM_ERROR_SOUND_INTERNAL;
475 g_variant_get(params, "(i)", &pid);
476 ret = _MMSoundMgrIpcClearFocus(pid);
479 if (ret == MM_ERROR_NONE) {
480 _method_call_return_value(invocation, g_variant_new("()"));
482 _method_call_return_error(invocation, ret);
489 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation)
491 int ret = MM_ERROR_NONE;
492 GVariant *params = NULL;
493 GVariantBuilder reply_builder;
495 int devices_num = 0, device_idx = 0;
496 mm_sound_device_t *device_list = NULL, *device_entry = NULL;
498 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
499 debug_error("Parameter for Method is NULL");
500 ret = MM_ERROR_SOUND_INTERNAL;
504 g_variant_get(params, "(i)", &mask_flags);
505 debug_log("Get device list with device_flag %X", mask_flags);
506 if ((ret = __mm_sound_mgr_ipc_get_current_connected_device_list(mask_flags, &device_list, &devices_num))==MM_ERROR_NONE) {
507 g_variant_builder_init(&reply_builder, G_VARIANT_TYPE("(a(iiiis))"));
508 g_variant_builder_open(&reply_builder, G_VARIANT_TYPE("a(iiiis)"));
509 for (device_idx = 0; device_idx < devices_num; device_idx++) {
510 device_entry = &device_list[device_idx];
511 // 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);
512 g_variant_builder_add(&reply_builder, "(iiiis)", device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
514 g_variant_builder_close(&reply_builder);
518 if (ret == MM_ERROR_NONE) {
519 _method_call_return_value(invocation, g_variant_builder_end(&reply_builder));
520 debug_log("Reply Sent");
522 _method_call_return_error(invocation, ret);
526 static void handle_method_call(GDBusConnection *connection,
528 const gchar *object_path,
529 const gchar *interface_name,
530 const gchar *method_name,
531 GVariant *parameters,
532 GDBusMethodInvocation *invocation,
538 debug_error("Parameter Null");
541 debug_log("Method Call, obj : %s, intf : %s, method : %s", object_path, interface_name, method_name);
543 for (method_idx = 0; method_idx < AUDIO_METHOD_MAX; method_idx++) {
544 if (!g_strcmp0(method_name, methods[method_idx].info.name)) {
545 methods[method_idx].handler(invocation);
551 static GVariant* handle_get_property(GDBusConnection *connection,
553 const gchar *object_path,
554 const gchar *interface_name,
555 const gchar *property_name,
559 debug_log("Get Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
563 static gboolean handle_set_property(GDBusConnection *connection,
565 const gchar *object_path,
566 const gchar *interface_name,
567 const gchar *property_name,
572 debug_log("Set Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
576 static const GDBusInterfaceVTable interface_vtable =
583 static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
586 debug_log("Bus Acquired (%s)", name);
589 reg_id = g_dbus_connection_register_object(connection,
591 introspection_data->interfaces[0],
597 debug_error("Register object(%s) failed", OBJECT_SOUND_SERVER);
603 static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
605 debug_log("Name Acquired (%s)", name);
608 static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
610 debug_log("Name Lost (%s)", name);
613 static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_name, guint* owner_id)
617 debug_log("Own name (%s) for sound-server", wellknown_name);
619 oid = g_bus_own_name(bus_type, wellknown_name, G_BUS_NAME_OWNER_FLAGS_NONE,
620 on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
622 debug_error("Dbus own name failed");
623 return MM_ERROR_SOUND_INTERNAL;
628 debug_log("OwnerID (%d) for sound-server", *owner_id);
630 return MM_ERROR_NONE;
633 static void _mm_sound_mgr_dbus_unown_name(guint oid)
635 debug_log("Unown name for Sound-Server [%d]", oid);
637 g_bus_unown_name(oid);
641 int __mm_sound_mgr_ipc_dbus_notify_device_connected(mm_sound_device_t *device, gboolean is_connected)
643 int ret = MM_ERROR_NONE;
644 GVariantBuilder builder;
645 GVariant* param = NULL;
647 debug_log("Send device connected signal");
649 g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)b)"));
650 g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
651 g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
652 g_variant_builder_close(&builder);
653 g_variant_builder_add(&builder, "b", is_connected);
654 param = g_variant_builder_end(&builder);
656 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_DEVICE_CONNECTED, param))!= MM_ERROR_NONE) {
657 debug_error("Send device connected signal failed");
660 debug_error("Build variant for dbus param failed");
666 int __mm_sound_mgr_ipc_dbus_notify_device_info_changed(mm_sound_device_t *device, int changed_device_info_type)
668 int ret = MM_ERROR_NONE;
669 GVariantBuilder builder;
670 GVariant* param = NULL;
672 debug_log("Send device info changed signal");
674 g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)i)"));
675 g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
676 g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
677 g_variant_builder_close(&builder);
678 g_variant_builder_add(&builder, "i", changed_device_info_type);
679 param = g_variant_builder_end(&builder);
681 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_DEVICE_INFO_CHANGED, param)) != MM_ERROR_NONE) {
682 debug_error("Send device info changed signal failed");
685 debug_error("Build variant for dbus param failed");
691 int __mm_sound_mgr_ipc_dbus_notify_volume_changed(unsigned int vol_type, unsigned int value)
693 int ret = MM_ERROR_NONE;
694 GVariant* param = NULL;
696 debug_log("Send Signal volume changed signal");
698 param = g_variant_new("(uu)", vol_type, value);
700 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_VOLUME_CHANGED, param)) != MM_ERROR_NONE) {
701 debug_error("Send device connected signal failed");
704 debug_error("Build variant for dbus param failed");
710 int __mm_sound_mgr_ipc_dbus_notify_play_file_end(int handle)
712 int ret = MM_ERROR_NONE;
713 GVariant* param = NULL;
715 debug_log("Send play file ended signal");
717 param = g_variant_new("(i)", handle);
719 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_PLAY_FILE_END, param)) != MM_ERROR_NONE) {
720 debug_error("Send play file end for '%d' failed", handle);
723 debug_error("Build variant for dbus param failed");
729 int __mm_sound_mgr_ipc_dbus_notify_active_device_changed(int device_in, int device_out)
731 return MM_ERROR_SOUND_INTERNAL;
734 int __mm_sound_mgr_ipc_dbus_notify_available_device_changed(int device_in, int device_out, int available)
736 return MM_ERROR_SOUND_INTERNAL;
739 #define PA_BUS_NAME "org.pulseaudio.Server"
740 #define PA_STREAM_MANAGER_OBJECT_PATH "/org/pulseaudio/StreamManager"
741 #define PA_STREAM_MANAGER_INTERFACE "org.pulseaudio.StreamManager"
742 #define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST "GetStreamList"
743 int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
745 int ret = MM_ERROR_NONE;
746 GVariant *result = NULL;
747 GVariant *child = NULL;
748 GDBusConnection *conn = NULL;
752 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
754 LOGE("g_bus_get_sync() error (%s)", err->message);
756 ret = MM_ERROR_SOUND_INTERNAL;
759 result = g_dbus_connection_call_sync(conn,
761 PA_STREAM_MANAGER_OBJECT_PATH,
762 PA_STREAM_MANAGER_INTERFACE,
763 PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST,
765 G_VARIANT_TYPE("(vv)"),
766 G_DBUS_CALL_FLAGS_NONE,
770 if (!result && err) {
771 debug_error("g_dbus_connection_call_sync() error (%s)", err->message);
772 ret = MM_ERROR_SOUND_INTERNAL;
775 GVariant *item = NULL;
776 child = g_variant_get_child_value(result, 0);
777 item = g_variant_get_variant(child);
780 g_variant_iter_init(&iter, item);
781 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
782 debug_log("name : %s", name);
783 stream_list->stream_types[i++] = strdup(name);
785 g_variant_unref(item);
786 g_variant_unref(child);
788 child = g_variant_get_child_value(result, 1);
789 item = g_variant_get_variant(child);
792 g_variant_iter_init(&iter, item);
793 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
794 debug_log("priority : %d", priority);
795 stream_list->priorities[i++] = priority;
797 g_variant_unref(item);
798 g_variant_unref(child);
800 g_variant_unref(result);
802 g_object_unref(conn);
807 int MMSoundMgrDbusInit(void)
811 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
812 if (!introspection_data) {
813 debug_error("g_dbus_node_info_new_for_xml() failed...");
814 return MM_ERROR_SOUND_INTERNAL;
817 if (_mm_sound_mgr_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_SOUND_SERVER, &sound_server_owner_id) != MM_ERROR_NONE) {
818 debug_error("dbus own name for sound-server error\n");
819 return MM_ERROR_SOUND_INTERNAL;
824 return MM_ERROR_NONE;
827 void MMSoundMgrDbusFini(void)
831 _mm_sound_mgr_dbus_unown_name(sound_server_owner_id);
832 g_dbus_node_info_unref(introspection_data);