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='session_type' direction='in'/>"
43 " <arg type='i' name='session_option' direction='in'/>"
44 " <arg type='i' name='client_pid' direction='in'/>"
45 " <arg type='b' name='enable_session' direction='in'/>"
46 " <arg type='s' name='stream_type' direction='in'/>"
47 " <arg type='i' name='stream_index' direction='in'/>"
48 " <arg type='i' name='handle' direction='out'/>"
50 " <method name='PlayFileStartWithStreamInfo'>"
51 " <arg type='s' name='filename' direction='in'/>"
52 " <arg type='i' name='repeat' direction='in'/>"
53 " <arg type='i' name='volume' direction='in'/>"
54 " <arg type='i' name='client_pid' direction='in'/>"
55 " <arg type='s' name='stream_type' direction='in'/>"
56 " <arg type='i' name='stream_index' direction='in'/>"
57 " <arg type='i' name='handle' direction='out'/>"
59 " <method name='PlayFileStop'>"
60 " <arg type='i' name='handle' direction='in'/>"
62 #ifdef FOCUS_INTEGRATION
63 " <method name='ClearFocus'>"
64 " <arg type='i' name='pid' direction='in'/>"
67 " <method name='PlayDTMF'>"
68 " <arg type='i' name='tone' direction='in'/>"
69 " <arg type='i' name='repeat' direction='in'/>"
70 " <arg type='i' name='volume' direction='in'/>"
71 " <arg type='i' name='vol_config' direction='in'/>"
72 " <arg type='i' name='session_type' direction='in'/>"
73 " <arg type='i' name='session_option' direction='in'/>"
74 " <arg type='i' name='client_pid' direction='in'/>"
75 " <arg type='b' name='enable_session' direction='in'/>"
76 " <arg type='s' name='stream_type' direction='in'/>"
77 " <arg type='i' name='stream_index' direction='in'/>"
78 " <arg type='i' name='handle' direction='out'/>"
80 " <method name='PlayDTMFWithStreamInfo'>"
81 " <arg type='i' name='tone' direction='in'/>"
82 " <arg type='i' name='repeat' direction='in'/>"
83 " <arg type='i' name='volume' direction='in'/>"
84 " <arg type='i' name='client_pid' direction='in'/>"
85 " <arg type='s' name='stream_type' direction='in'/>"
86 " <arg type='i' name='stream_index' direction='in'/>"
87 " <arg type='i' name='handle' direction='out'/>"
89 " <method name='GetConnectedDeviceList'>"
90 " <arg type='i' name='device_mask' direction='in'/>"
91 " <arg type='a(iiiis)' name='device_list' direction='out'/>"
95 static GDBusConnection* conn_g;
97 static void handle_method_play_file_start(GDBusMethodInvocation* invocation);
98 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation);
99 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation);
100 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation);
101 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation);
102 #ifdef FOCUS_INTEGRATION
103 static void handle_method_clear_focus(GDBusMethodInvocation* invocation);
105 static void handle_method_test(GDBusMethodInvocation* invocation);
106 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation);
108 /* Currently , Just using method's name and handler */
109 /* TODO : generate introspection xml automatically, with these value include argument and reply */
110 /* TODO : argument check with these information */
111 /* TODO : divide object and interface with features (ex. play, path, device) */
112 static mm_sound_dbus_method_intf_t methods[AUDIO_METHOD_MAX] = {
113 [AUDIO_METHOD_TEST] = {
115 .name = "MethodTest1",
117 .handler = handle_method_test
119 [AUDIO_METHOD_PLAY_FILE_START] = {
121 .name = "PlayFileStart",
123 .handler = handle_method_play_file_start
125 [AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO] = {
127 .name = "PlayFileStartWithStreamInfo",
129 .handler = handle_method_play_file_start_with_stream_info
131 [AUDIO_METHOD_PLAY_FILE_STOP] = {
133 .name = "PlayFileStop",
135 .handler = handle_method_play_file_stop
137 #ifdef FOCUS_INTEGRATION
138 [AUDIO_METHOD_CLEAR_FOCUS] = {
140 .name = "ClearFocus",
142 .handler = handle_method_clear_focus
145 [AUDIO_METHOD_PLAY_DTMF] = {
149 .handler = handle_method_play_dtmf
151 [AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO] = {
153 .name = "PlayDTMFWithStreamInfo",
155 .handler = handle_method_play_dtmf_with_stream_info
157 [AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST] = {
159 .name = "GetConnectedDeviceList",
161 .handler = handle_method_get_connected_device_list
165 static GDBusNodeInfo *introspection_data = NULL;
166 guint sound_server_owner_id ;
169 For pass error code with 'g_dbus_method_invocation_return_error'
170 We have to use some glib features like GError, GQuark
172 /* Only For error types which is currently being used in server-side */
173 static const GDBusErrorEntry mm_sound_error_entries[] =
175 {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
176 {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
177 {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
178 {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
179 {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
180 {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
181 {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
182 {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
183 {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
184 {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
185 {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
186 {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
187 {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
188 {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
189 {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
190 {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
191 {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
192 {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
193 {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
196 static const char* _convert_error_code(int err_code)
200 for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
201 if (err_code == mm_sound_error_entries[i].error_code) {
202 return mm_sound_error_entries[i].dbus_error_name;
206 return "org.tizen.multimedia.common.Unknown";
209 static int mm_sound_mgr_ipc_dbus_send_signal(audio_event_t event, GVariant *parameter)
211 if(mm_sound_dbus_emit_signal(AUDIO_PROVIDER_SOUND_SERVER, event, parameter) != MM_ERROR_NONE) {
212 debug_error("Sound Server Emit signal failed");
213 return MM_ERROR_SOUND_INTERNAL;
215 return MM_ERROR_NONE;
218 static int _get_sender_pid(GDBusMethodInvocation* invocation)
223 GDBusConnection * connection = NULL;
226 connection = g_dbus_method_invocation_get_connection(invocation);
227 sender = g_dbus_method_invocation_get_sender(invocation);
229 debug_error("connection = %p, sender = %s", connection, sender);
231 value = g_dbus_connection_call_sync(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
232 "org.freedesktop.DBus", "GetConnectionUnixProcessID",
233 g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
235 g_variant_get(value, "(u)", &pid);
236 debug_msg("Sender PID = [%d]", pid);
237 g_variant_unref(value);
239 debug_error("err code = %d, err msg = %s", err->code, err->message);
244 static void _method_call_return_value(GDBusMethodInvocation *invocation, GVariant *params)
246 const char *method_name;
247 method_name = g_dbus_method_invocation_get_method_name(invocation);
248 debug_msg("Method Call '%s' success", method_name);
249 g_dbus_method_invocation_return_value(invocation, params);
251 static void _method_call_return_error(GDBusMethodInvocation *invocation, int ret)
253 const char *err_name, *method_name;
254 err_name = _convert_error_code(ret);
255 method_name = g_dbus_method_invocation_get_method_name(invocation);
256 debug_error("Method Call '%s' failed, err '%s(%X)'", method_name, err_name, ret);
257 g_dbus_method_invocation_return_dbus_error(invocation, err_name, "failed");
260 static void handle_method_test(GDBusMethodInvocation* invocation)
262 int ret = MM_ERROR_NONE;
263 int val = 0, val2 = 0;
264 GVariant *params = NULL;
268 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
269 debug_error("Parameter for Method is NULL");
270 ret = MM_ERROR_SOUND_INTERNAL;
274 g_variant_get(params, "(ii)", &val, &val2);
275 debug_log("Got value : %d , %d", val, val2);
277 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_TEST, g_variant_new("(i)", val+val2))) != MM_ERROR_NONE) {
278 debug_error("signal send error : %X", ret);
280 debug_error("signal send success");
284 if (ret == MM_ERROR_NONE) {
285 _method_call_return_value(invocation, g_variant_new("(i)", val * val2));
287 ret = MM_ERROR_INVALID_ARGUMENT;
288 _method_call_return_error(invocation, ret);
294 static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
296 gchar* filename = NULL;
297 gchar *stream_type = NULL;
298 gint32 ret = MM_ERROR_NONE, slotid = 0;
299 gint32 tone = 0, repeat = 0, volume = 0, vol_config = 0;
300 gint32 session_type = 0, session_option = 0, pid = 0, stream_index = 0;
301 gboolean enable_session = 0;
302 GVariant *params = NULL;
306 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
307 debug_error("Parameter for Method is NULL");
308 ret = MM_ERROR_SOUND_INTERNAL;
312 g_variant_get(params, "(siiiiiiibsi)", &filename, &tone, &repeat, &volume,
313 &vol_config, &session_type, &session_option, &pid, &enable_session, &stream_type, &stream_index);
315 debug_error("filename null");
316 ret = MM_ERROR_SOUND_INTERNAL;
319 ret = _MMSoundMgrIpcPlayFile(filename, tone, repeat, volume, vol_config,
320 session_type, session_option, _get_sender_pid(invocation), enable_session, &slotid, stream_type, stream_index);
324 if (ret == MM_ERROR_NONE) {
325 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
327 _method_call_return_error(invocation, ret);
336 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation)
338 gchar* filename = NULL;
339 gchar *stream_type = NULL;
340 gint32 ret = MM_ERROR_NONE, slotid = 0;
341 gint32 repeat = 0, volume = 0, pid = 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, "(siiisi)", &filename, &repeat, &volume, &pid, &stream_type, &stream_index);
354 debug_error("filename null");
355 ret = MM_ERROR_SOUND_INTERNAL;
358 ret = _MMSoundMgrIpcPlayFileWithStreamInfo(filename, repeat, volume, _get_sender_pid(invocation),
359 &slotid, stream_type, stream_index);
362 if (ret == MM_ERROR_NONE) {
363 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
365 _method_call_return_error(invocation, ret);
374 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation)
376 int ret = MM_ERROR_NONE, slotid = 0;
377 int tone = 0, repeat = 0, volume = 0, vol_config = 0, session_type = 0, session_option = 0, pid = 0, stream_index = 0;
378 gchar* stream_type = NULL;
379 gboolean enable_session = 0;
380 GVariant *params = NULL;
384 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
385 debug_error("Parameter for Method is NULL");
386 ret = MM_ERROR_SOUND_INTERNAL;
390 g_variant_get(params, "(iiiiiiibsi)", &tone, &repeat, &volume,
391 &vol_config, &session_type, &session_option, &pid, &enable_session, &stream_type, &stream_index);
392 debug_error("volume - %d", volume);
393 ret = _MMSoundMgrIpcPlayDTMF(tone, repeat, volume, vol_config,
394 session_type, session_option, _get_sender_pid(invocation), enable_session, &slotid, stream_type, stream_index);
397 if (ret == MM_ERROR_NONE) {
398 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
400 _method_call_return_error(invocation, ret);
408 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation)
410 int ret = MM_ERROR_NONE, slotid = 0;
411 int tone = 0, repeat = 0, volume = 0, pid = 0, stream_index = 0;
412 char* stream_type = NULL;
413 GVariant *params = NULL;
417 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
418 debug_error("Parameter for Method is NULL");
419 ret = MM_ERROR_SOUND_INTERNAL;
423 g_variant_get(params, "(iiiisi)", &tone, &repeat, &volume, &pid, &stream_type, &stream_index);
424 ret = _MMSoundMgrIpcPlayDTMFWithStreamInfo(tone, repeat, volume, _get_sender_pid(invocation), &slotid, stream_type, stream_index);
427 if (ret == MM_ERROR_NONE) {
428 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
430 _method_call_return_error(invocation, ret);
436 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation)
438 int ret = MM_ERROR_NONE;
440 GVariant *params = NULL;
444 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
445 debug_error("Parameter for Method is NULL");
446 ret = MM_ERROR_SOUND_INTERNAL;
450 g_variant_get(params, "(i)", &handle);
451 ret = _MMSoundMgrIpcStop(handle);
454 if (ret == MM_ERROR_NONE) {
455 _method_call_return_value(invocation, g_variant_new("()"));
457 _method_call_return_error(invocation, ret);
463 #ifdef FOCUS_INTEGRATION
464 static void handle_method_clear_focus(GDBusMethodInvocation* invocation)
466 int ret = MM_ERROR_NONE;
468 GVariant *params = NULL;
472 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
473 debug_error("Parameter for Method is NULL");
474 ret = MM_ERROR_SOUND_INTERNAL;
478 g_variant_get(params, "(i)", &pid);
479 ret = _MMSoundMgrIpcClearFocus(pid);
482 if (ret == MM_ERROR_NONE) {
483 _method_call_return_value(invocation, g_variant_new("()"));
485 _method_call_return_error(invocation, ret);
492 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation)
494 int ret = MM_ERROR_NONE;
495 GVariant *params = NULL;
496 GVariantBuilder reply_builder;
498 int devices_num = 0, device_idx = 0;
499 mm_sound_device_t *device_list = NULL, *device_entry = NULL;
501 if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
502 debug_error("Parameter for Method is NULL");
503 ret = MM_ERROR_SOUND_INTERNAL;
507 g_variant_get(params, "(i)", &mask_flags);
508 debug_log("Get device list with device_flag %X", mask_flags);
509 if ((ret = __mm_sound_mgr_ipc_get_current_connected_device_list(mask_flags, &device_list, &devices_num))==MM_ERROR_NONE) {
510 g_variant_builder_init(&reply_builder, G_VARIANT_TYPE("(a(iiiis))"));
511 g_variant_builder_open(&reply_builder, G_VARIANT_TYPE("a(iiiis)"));
512 for (device_idx = 0; device_idx < devices_num; device_idx++) {
513 device_entry = &device_list[device_idx];
514 // 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);
515 g_variant_builder_add(&reply_builder, "(iiiis)", device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
517 g_variant_builder_close(&reply_builder);
521 if (ret == MM_ERROR_NONE) {
522 _method_call_return_value(invocation, g_variant_builder_end(&reply_builder));
523 debug_log("Reply Sent");
525 _method_call_return_error(invocation, ret);
529 static void handle_method_call(GDBusConnection *connection,
531 const gchar *object_path,
532 const gchar *interface_name,
533 const gchar *method_name,
534 GVariant *parameters,
535 GDBusMethodInvocation *invocation,
541 debug_error("Parameter Null");
544 debug_log("Method Call, obj : %s, intf : %s, method : %s", object_path, interface_name, method_name);
546 for (method_idx = 0; method_idx < AUDIO_METHOD_MAX; method_idx++) {
547 if (!g_strcmp0(method_name, methods[method_idx].info.name)) {
548 methods[method_idx].handler(invocation);
554 static GVariant* handle_get_property(GDBusConnection *connection,
556 const gchar *object_path,
557 const gchar *interface_name,
558 const gchar *property_name,
562 debug_log("Get Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
566 static gboolean handle_set_property(GDBusConnection *connection,
568 const gchar *object_path,
569 const gchar *interface_name,
570 const gchar *property_name,
575 debug_log("Set Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
579 static const GDBusInterfaceVTable interface_vtable =
586 static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
589 debug_log("Bus Acquired (%s)", name);
592 reg_id = g_dbus_connection_register_object(connection,
594 introspection_data->interfaces[0],
600 debug_error("Register object(%s) failed", OBJECT_SOUND_SERVER);
606 static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
608 debug_log("Name Acquired (%s)", name);
611 static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
613 debug_log("Name Lost (%s)", name);
616 static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_name, guint* owner_id)
620 debug_log("Own name (%s) for sound-server", wellknown_name);
622 oid = g_bus_own_name(bus_type, wellknown_name, G_BUS_NAME_OWNER_FLAGS_NONE,
623 on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
625 debug_error("Dbus own name failed");
626 return MM_ERROR_SOUND_INTERNAL;
631 debug_log("OwnerID (%d) for sound-server", *owner_id);
633 return MM_ERROR_NONE;
636 static void _mm_sound_mgr_dbus_unown_name(guint oid)
638 debug_log("Unown name for Sound-Server [%d]", oid);
640 g_bus_unown_name(oid);
644 int __mm_sound_mgr_ipc_dbus_notify_device_connected(mm_sound_device_t *device, gboolean is_connected)
646 int ret = MM_ERROR_NONE;
647 GVariantBuilder builder;
648 GVariant* param = NULL;
650 debug_log("Send device connected signal");
652 g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)b)"));
653 g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
654 g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
655 g_variant_builder_close(&builder);
656 g_variant_builder_add(&builder, "b", is_connected);
657 param = g_variant_builder_end(&builder);
659 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_DEVICE_CONNECTED, param))!= MM_ERROR_NONE) {
660 debug_error("Send device connected signal failed");
663 debug_error("Build variant for dbus param failed");
669 int __mm_sound_mgr_ipc_dbus_notify_device_info_changed(mm_sound_device_t *device, int changed_device_info_type)
671 int ret = MM_ERROR_NONE;
672 GVariantBuilder builder;
673 GVariant* param = NULL;
675 debug_log("Send device info changed signal");
677 g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)i)"));
678 g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
679 g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
680 g_variant_builder_close(&builder);
681 g_variant_builder_add(&builder, "i", changed_device_info_type);
682 param = g_variant_builder_end(&builder);
684 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_DEVICE_INFO_CHANGED, param)) != MM_ERROR_NONE) {
685 debug_error("Send device info changed signal failed");
688 debug_error("Build variant for dbus param failed");
694 int __mm_sound_mgr_ipc_dbus_notify_volume_changed(unsigned int vol_type, unsigned int value)
696 int ret = MM_ERROR_NONE;
697 GVariant* param = NULL;
699 debug_log("Send Signal volume changed signal");
701 param = g_variant_new("(uu)", vol_type, value);
703 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_VOLUME_CHANGED, param)) != MM_ERROR_NONE) {
704 debug_error("Send device connected signal failed");
707 debug_error("Build variant for dbus param failed");
713 int __mm_sound_mgr_ipc_dbus_notify_play_file_end(int handle)
715 int ret = MM_ERROR_NONE;
716 GVariant* param = NULL;
718 debug_log("Send play file ended signal");
720 param = g_variant_new("(i)", handle);
722 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(AUDIO_EVENT_PLAY_FILE_END, param)) != MM_ERROR_NONE) {
723 debug_error("Send play file end for '%d' failed", handle);
726 debug_error("Build variant for dbus param failed");
732 int __mm_sound_mgr_ipc_dbus_notify_active_device_changed(int device_in, int device_out)
734 return MM_ERROR_SOUND_INTERNAL;
737 int __mm_sound_mgr_ipc_dbus_notify_available_device_changed(int device_in, int device_out, int available)
739 return MM_ERROR_SOUND_INTERNAL;
742 #define PA_BUS_NAME "org.pulseaudio.Server"
743 #define PA_STREAM_MANAGER_OBJECT_PATH "/org/pulseaudio/StreamManager"
744 #define PA_STREAM_MANAGER_INTERFACE "org.pulseaudio.StreamManager"
745 #define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST "GetStreamList"
746 int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
748 int ret = MM_ERROR_NONE;
749 GVariant *result = NULL;
750 GVariant *child = NULL;
751 GDBusConnection *conn = NULL;
755 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
757 LOGE("g_bus_get_sync() error (%s)", err->message);
759 ret = MM_ERROR_SOUND_INTERNAL;
762 result = g_dbus_connection_call_sync(conn,
764 PA_STREAM_MANAGER_OBJECT_PATH,
765 PA_STREAM_MANAGER_INTERFACE,
766 PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST,
768 G_VARIANT_TYPE("(vv)"),
769 G_DBUS_CALL_FLAGS_NONE,
773 if (!result && err) {
774 debug_error("g_dbus_connection_call_sync() error (%s)", err->message);
775 ret = MM_ERROR_SOUND_INTERNAL;
778 GVariant *item = NULL;
779 child = g_variant_get_child_value(result, 0);
780 item = g_variant_get_variant(child);
783 g_variant_iter_init(&iter, item);
784 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
785 debug_log("name : %s", name);
786 stream_list->stream_types[i++] = strdup(name);
788 g_variant_unref(item);
789 g_variant_unref(child);
791 child = g_variant_get_child_value(result, 1);
792 item = g_variant_get_variant(child);
795 g_variant_iter_init(&iter, item);
796 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
797 debug_log("priority : %d", priority);
798 stream_list->priorities[i++] = priority;
800 g_variant_unref(item);
801 g_variant_unref(child);
803 g_variant_unref(result);
805 g_object_unref(conn);
810 int MMSoundMgrDbusInit(void)
814 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
815 if (!introspection_data) {
816 debug_error("g_dbus_node_info_new_for_xml() failed...");
817 return MM_ERROR_SOUND_INTERNAL;
820 if (_mm_sound_mgr_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_SOUND_SERVER, &sound_server_owner_id) != MM_ERROR_NONE) {
821 debug_error("dbus own name for sound-server error\n");
822 return MM_ERROR_SOUND_INTERNAL;
827 return MM_ERROR_NONE;
830 void MMSoundMgrDbusFini(void)
834 _mm_sound_mgr_dbus_unown_name(sound_server_owner_id);
835 g_dbus_node_info_unref(introspection_data);