apply focus for playing tone/wav
[platform/core/multimedia/libmm-sound.git] / server / mm_sound_mgr_ipc_dbus.c
1
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7
8 #include <mm_types.h>
9 #include <mm_error.h>
10 #include <mm_debug.h>
11
12 #include <gio/gio.h>
13 #include <glib.h>
14
15 #ifdef USE_SECURITY
16 #include <security-server.h>
17 #define COOKIE_SIZE 20
18 #endif
19
20 #include "include/mm_sound_mgr_ipc_dbus.h"
21 #include "include/mm_sound_mgr_ipc.h"
22
23
24 #define BUS_NAME_SOUND_SERVER "org.tizen.SoundServer"
25 #define OBJECT_SOUND_SERVER "/org/tizen/SoundServer1"
26 #define INTERFACE_SOUND_SERVER "org.tizen.SoundServer1"
27
28 /* workaround for AF volume gain tuning */
29 #define PROC_DBUS_OBJECT        "/Org/Tizen/ResourceD/Process"
30 #define PROC_DBUS_INTERFACE     "org.tizen.resourced.process"
31 #define PROC_DBUS_METHOD        "ProcExclude"
32
33 #define OBJECT_ASM "/org/tizen/asm"
34 #define INTERFACE_ASM "org.tizen.asm"
35
36 /* Introspection data for the service we are exporting */
37   static const gchar introspection_xml[] =
38   "<node>"
39   "  <interface name='org.tizen.SoundServer1'>"
40   "    <method name='MethodTest1'>"
41   "      <arg type='i' name='num1' direction='in'/>"
42   "      <arg type='i' name='num2' direction='in'/>"
43   "      <arg type='i' name='multiple' direction='out'/>"
44   "    </method>"
45   "    <method name='GetBTA2DPStatus'>"
46   "      <arg type='b' name='is_bt_on' direction='out'/>"
47   "      <arg type='s' name='bt_name' direction='out'/>"
48   "    </method>"
49   "    <method name='PlayFileStart'>"
50   "      <arg type='s' name='filename' direction='in'/>"
51   "      <arg type='i' name='tone' direction='in'/>"
52   "      <arg type='i' name='repeat' direction='in'/>"
53   "      <arg type='i' name='volume' direction='in'/>"
54   "      <arg type='i' name='vol_config' direction='in'/>"
55   "      <arg type='i' name='priority' direction='in'/>"
56   "      <arg type='i' name='session_type' direction='in'/>"
57   "      <arg type='i' name='session_option' direction='in'/>"
58   "      <arg type='i' name='client_pid' direction='in'/>"
59   "      <arg type='i' name='handle_route' direction='in'/>"
60   "      <arg type='b' name='enable_session' direction='in'/>"
61   "      <arg type='s' name='stream_type' direction='in'/>"
62   "      <arg type='i' name='stream_index' direction='in'/>"
63   "      <arg type='i' name='handle' direction='out'/>"
64   "    </method>"
65   "        <method name='PlayFileStartWithStreamInfo'>"
66   "          <arg type='s' name='filename' direction='in'/>"
67   "          <arg type='i' name='repeat' direction='in'/>"
68   "          <arg type='i' name='volume' direction='in'/>"
69   "          <arg type='i' name='priority' direction='in'/>"
70   "          <arg type='i' name='client_pid' direction='in'/>"
71   "          <arg type='i' name='handle_route' direction='in'/>"
72   "          <arg type='s' name='stream_type' direction='in'/>"
73   "          <arg type='i' name='stream_index' direction='in'/>"
74   "          <arg type='i' name='handle' direction='out'/>"
75   "        </method>"
76   "    <method name='PlayFileStop'>"
77   "      <arg type='i' name='handle' direction='in'/>"
78   "    </method>"
79   "    <method name='ClearFocus'>"
80   "      <arg type='i' name='pid' direction='in'/>"
81   "    </method>"
82   "    <method name='PlayDTMF'>"
83   "      <arg type='i' name='tone' direction='in'/>"
84   "      <arg type='i' name='repeat' direction='in'/>"
85   "      <arg type='i' name='volume' direction='in'/>"
86   "      <arg type='i' name='vol_config' direction='in'/>"
87   "      <arg type='i' name='session_type' direction='in'/>"
88   "      <arg type='i' name='session_option' direction='in'/>"
89   "      <arg type='i' name='client_pid' direction='in'/>"
90   "      <arg type='b' name='enable_session' direction='in'/>"
91   "          <arg type='s' name='stream_type' direction='in'/>"
92   "          <arg type='i' name='stream_index' direction='in'/>"
93   "      <arg type='i' name='handle' direction='out'/>"
94   "    </method>"
95   "        <method name='PlayDTMFWithStreamInfo'>"
96   "          <arg type='i' name='tone' direction='in'/>"
97   "          <arg type='i' name='repeat' direction='in'/>"
98   "          <arg type='i' name='volume' direction='in'/>"
99   "          <arg type='i' name='client_pid' direction='in'/>"
100   "          <arg type='s' name='stream_type' direction='in'/>"
101   "          <arg type='i' name='stream_index' direction='in'/>"
102   "          <arg type='i' name='handle' direction='out'/>"
103   "        </method>"
104   "    <method name='SetPathForActiveDevice'>"
105   "    </method>"
106   "    <method name='GetConnectedDeviceList'>"
107   "      <arg type='i' name='device_mask' direction='in'/>"
108   "      <arg type='a(iiiis)' name='device_list' direction='out'/>"
109   "    </method>"
110   "    <method name='GetAudioPath'>"
111   "      <arg type='i' name='device_in' direction='out'/>"
112   "      <arg type='i' name='device_out' direction='out'/>"
113   "    </method>"
114   "    <method name='ASMRegisterSound'>"
115 #ifdef SUPPORT_CONTAINER
116 #ifdef USE_SECURITY
117   "      <arg name='container' type='ay' direction='in'/>"
118 #else
119   "      <arg name='container' type='s' direction='in'/>"
120 #endif
121 #endif
122   "      <arg name='rcv_pid' type='i' direction='in'/>"
123   "      <arg name='rcv_handle' type='i' direction='in'/>"
124   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
125   "      <arg name='rcv_request_id' type='i' direction='in'/>"
126   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
127   "      <arg name='rcv_resource' type='i' direction='in'/>"
128   "      <arg name='snd_pid' type='i' direction='out'/>"
129   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
130   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
131   "      <arg name='snd_request_id' type='i' direction='out'/>"
132   "      <arg name='snd_sound_command' type='i' direction='out'/>"
133   "      <arg name='snd_sound_state' type='i' direction='out'/>"
134   "    </method>"
135   "    <method name='ASMUnregisterSound'>"
136   "      <arg name='rcv_pid' type='i' direction='in'/>"
137   "      <arg name='rcv_handle' type='i' direction='in'/>"
138   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
139   "      <arg name='rcv_request_id' type='i' direction='in'/>"
140   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
141   "      <arg name='rcv_resource' type='i' direction='in'/>"
142   "    </method>"
143   "    <method name='ASMRegisterWatcher'>"
144 #ifdef SUPPORT_CONTAINER
145 #ifdef USE_SECURITY
146   "      <arg name='container' type='ay' direction='in'/>"
147 #else
148   "      <arg name='container' type='s' direction='in'/>"
149 #endif
150 #endif
151   "      <arg name='rcv_pid' type='i' direction='in'/>"
152   "      <arg name='rcv_handle' type='i' direction='in'/>"
153   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
154   "      <arg name='rcv_request_id' type='i' direction='in'/>"
155   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
156   "      <arg name='rcv_resource' type='i' direction='in'/>"
157   "      <arg name='snd_pid' type='i' direction='out'/>"
158   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
159   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
160   "      <arg name='snd_request_id' type='i' direction='out'/>"
161   "      <arg name='snd_sound_command' type='i' direction='out'/>"
162   "      <arg name='snd_sound_state' type='i' direction='out'/>"
163   "    </method>"
164   "    <method name='ASMUnregisterWatcher'>"
165   "      <arg name='rcv_pid' type='i' direction='in'/>"
166   "      <arg name='rcv_handle' type='i' direction='in'/>"
167   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
168   "      <arg name='rcv_request_id' type='i' direction='in'/>"
169   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
170   "      <arg name='rcv_resource' type='i' direction='in'/>"
171   "    </method>"
172   "    <method name='ASMGetMyState'>"
173   "      <arg name='rcv_pid' type='i' direction='in'/>"
174   "      <arg name='rcv_handle' type='i' direction='in'/>"
175   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
176   "      <arg name='rcv_request_id' type='i' direction='in'/>"
177   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
178   "      <arg name='rcv_resource' type='i' direction='in'/>"
179   "      <arg name='snd_pid' type='i' direction='out'/>"
180   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
181   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
182   "      <arg name='snd_request_id' type='i' direction='out'/>"
183   "      <arg name='snd_sound_state' type='i' direction='out'/>"
184   "    </method>"
185   "    <method name='ASMGetState'>"
186   "      <arg name='rcv_pid' type='i' direction='in'/>"
187   "      <arg name='rcv_handle' type='i' direction='in'/>"
188   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
189   "      <arg name='rcv_request_id' type='i' direction='in'/>"
190   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
191   "      <arg name='rcv_resource' type='i' direction='in'/>"
192   "      <arg name='snd_pid' type='i' direction='out'/>"
193   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
194   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
195   "      <arg name='snd_request_id' type='i' direction='out'/>"
196   "      <arg name='snd_sound_state' type='i' direction='out'/>"
197   "    </method>"
198   "    <method name='ASMSetState'>"
199   "      <arg name='rcv_pid' type='i' direction='in'/>"
200   "      <arg name='rcv_handle' type='i' direction='in'/>"
201   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
202   "      <arg name='rcv_request_id' type='i' direction='in'/>"
203   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
204   "      <arg name='rcv_resource' type='i' direction='in'/>"
205   "      <arg name='snd_pid' type='i' direction='out'/>"
206   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
207   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
208   "      <arg name='snd_request_id' type='i' direction='out'/>"
209   "      <arg name='snd_sound_command' type='i' direction='out'/>"
210   "      <arg name='snd_sound_state' type='i' direction='out'/>"
211   "      <arg name='snd_error_code' type='i' direction='out'/>"
212   "    </method>"
213   "    <method name='ASMSetSubsession'>"
214   "      <arg name='rcv_pid' type='i' direction='in'/>"
215   "      <arg name='rcv_handle' type='i' direction='in'/>"
216   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
217   "      <arg name='rcv_request_id' type='i' direction='in'/>"
218   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
219   "      <arg name='rcv_resource' type='i' direction='in'/>"
220   "      <arg name='snd_pid' type='i' direction='out'/>"
221   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
222   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
223   "      <arg name='snd_request_id' type='i' direction='out'/>"
224   "    </method>"
225   "    <method name='ASMGetSubsession'>"
226   "      <arg name='rcv_pid' type='i' direction='in'/>"
227   "      <arg name='rcv_handle' type='i' direction='in'/>"
228   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
229   "      <arg name='rcv_request_id' type='i' direction='in'/>"
230   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
231   "      <arg name='rcv_resource' type='i' direction='in'/>"
232   "      <arg name='snd_pid' type='i' direction='out'/>"
233   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
234   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
235   "      <arg name='snd_request_id' type='i' direction='out'/>"
236   "      <arg name='snd_sound_command' type='i' direction='out'/>"
237   "    </method>"
238   "    <method name='ASMSetSubevent'>"
239   "      <arg name='rcv_pid' type='i' direction='in'/>"
240   "      <arg name='rcv_handle' type='i' direction='in'/>"
241   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
242   "      <arg name='rcv_request_id' type='i' direction='in'/>"
243   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
244   "      <arg name='rcv_resource' type='i' direction='in'/>"
245   "      <arg name='snd_pid' type='i' direction='out'/>"
246   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
247   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
248   "      <arg name='snd_request_id' type='i' direction='out'/>"
249   "      <arg name='snd_sound_command' type='i' direction='out'/>"
250   "      <arg name='snd_sound_state' type='i' direction='out'/>"
251   "    </method>"
252   "    <method name='ASMGetSubevent'>"
253   "      <arg name='rcv_pid' type='i' direction='in'/>"
254   "      <arg name='rcv_handle' type='i' direction='in'/>"
255   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
256   "      <arg name='rcv_request_id' type='i' direction='in'/>"
257   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
258   "      <arg name='rcv_resource' type='i' direction='in'/>"
259   "      <arg name='snd_pid' type='i' direction='out'/>"
260   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
261   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
262   "      <arg name='snd_request_id' type='i' direction='out'/>"
263   "      <arg name='snd_sound_command' type='i' direction='out'/>"
264   "    </method>"
265   "    <method name='ASMSetSessionOption'>"
266   "      <arg name='rcv_pid' type='i' direction='in'/>"
267   "      <arg name='rcv_handle' type='i' direction='in'/>"
268   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
269   "      <arg name='rcv_request_id' type='i' direction='in'/>"
270   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
271   "      <arg name='rcv_resource' type='i' direction='in'/>"
272   "      <arg name='snd_pid' type='i' direction='out'/>"
273   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
274   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
275   "      <arg name='snd_request_id' type='i' direction='out'/>"
276   "      <arg name='snd_sound_command' type='i' direction='out'/>"
277   "      <arg name='snd_sound_state' type='i' direction='out'/>"
278   "    </method>"
279   "    <method name='ASMGetSessionOption'>"
280   "      <arg name='rcv_pid' type='i' direction='in'/>"
281   "      <arg name='rcv_handle' type='i' direction='in'/>"
282   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
283   "      <arg name='rcv_request_id' type='i' direction='in'/>"
284   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
285   "      <arg name='rcv_resource' type='i' direction='in'/>"
286   "      <arg name='snd_pid' type='i' direction='out'/>"
287   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
288   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
289   "      <arg name='snd_request_id' type='i' direction='out'/>"
290   "      <arg name='snd_sound_command' type='i' direction='out'/>"
291   "      <arg name='snd_option_flag' type='i' direction='out'/>"
292   "    </method>"
293   "    <method name='ASMResetResumeTag'>"
294   "      <arg name='rcv_pid' type='i' direction='in'/>"
295   "      <arg name='rcv_handle' type='i' direction='in'/>"
296   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
297   "      <arg name='rcv_request_id' type='i' direction='in'/>"
298   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
299   "      <arg name='rcv_resource' type='i' direction='in'/>"
300   "      <arg name='snd_pid' type='i' direction='out'/>"
301   "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
302   "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
303   "      <arg name='snd_request_id' type='i' direction='out'/>"
304   "      <arg name='snd_sound_command' type='i' direction='out'/>"
305   "      <arg name='snd_sound_state' type='i' direction='out'/>"
306   "    </method>"
307   "    <method name='ASMDump'>"
308   "      <arg name='rcv_pid' type='i' direction='in'/>"
309   "      <arg name='rcv_handle' type='i' direction='in'/>"
310   "      <arg name='rcv_sound_event' type='i' direction='in'/>"
311   "      <arg name='rcv_request_id' type='i' direction='in'/>"
312   "      <arg name='rcv_sound_state' type='i' direction='in'/>"
313   "      <arg name='rcv_resource' type='i' direction='in'/>"
314   "    </method>"
315   "  </interface>"
316   "</node>";
317 GDBusConnection* conn_g;
318
319 typedef void (*dbus_method_handler)(GDBusMethodInvocation *invocation);
320 typedef int (*dbus_signal_sender)(GDBusConnection *conn, GVariant *parameter);
321
322 struct mm_sound_dbus_method{
323         struct mm_sound_dbus_method_info info;
324         dbus_method_handler handler;
325 };
326
327 struct mm_sound_dbus_signal{
328         struct mm_sound_dbus_signal_info info;
329         dbus_signal_sender sender;
330 };
331
332 static void handle_method_play_file_start(GDBusMethodInvocation* invocation);
333 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation);
334 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation);
335 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation);
336 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation);
337 static void handle_method_clear_focus(GDBusMethodInvocation* invocation);
338 static void handle_method_get_bt_a2dp_status(GDBusMethodInvocation* invocation);
339 static void handle_method_test(GDBusMethodInvocation* invocation);
340 static void handle_method_set_sound_path_for_active_device(GDBusMethodInvocation* invocation);
341 static void handle_method_get_audio_path(GDBusMethodInvocation* invocation);
342 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation);
343
344 static void handle_method_asm_register_sound(GDBusMethodInvocation* invocation);
345 static void handle_method_asm_unregister_sound(GDBusMethodInvocation* invocation);
346 static void handle_method_asm_register_watcher(GDBusMethodInvocation* invocation);
347 static void handle_method_asm_unregister_watcher(GDBusMethodInvocation* invocation);
348 static void handle_method_asm_get_mystate(GDBusMethodInvocation* invocation);
349 static void handle_method_asm_get_state(GDBusMethodInvocation* invocation);
350 static void handle_method_asm_set_state(GDBusMethodInvocation* invocation);
351 static void handle_method_asm_set_subsession(GDBusMethodInvocation* invocation);
352 static void handle_method_asm_get_subsession(GDBusMethodInvocation* invocation);
353 static void handle_method_asm_set_subevent(GDBusMethodInvocation* invocation);
354 static void handle_method_asm_get_subevent(GDBusMethodInvocation* invocation);
355 static void handle_method_asm_set_session_option(GDBusMethodInvocation* invocation);
356 static void handle_method_asm_get_session_option(GDBusMethodInvocation* invocation);
357 static void handle_method_asm_reset_resume_tag(GDBusMethodInvocation* invocation);
358 static void handle_method_asm_dump(GDBusMethodInvocation* invocation);
359
360 /* Currently , Just using method's name and handler */
361 /* TODO : generate introspection xml automatically, with these value include argument and reply */
362 /* TODO : argument check with these information */
363 /* TODO : divide object and interface with features (ex. play, path, device, focus, asm) */
364 struct mm_sound_dbus_method methods[METHOD_CALL_MAX] = {
365         [METHOD_CALL_TEST] = {
366                 .info = {
367                         .name = "MethodTest1",
368                 },
369                 .handler = handle_method_test
370         },
371         [METHOD_CALL_PLAY_FILE_START] = {
372                 .info = {
373                         .name = "PlayFileStart",
374                 },
375                 .handler = handle_method_play_file_start
376         },
377         [METHOD_CALL_PLAY_FILE_START_WITH_STREAM_INFO] = {
378                 .info = {
379                         .name = "PlayFileStartWithStreamInfo",
380                 },
381                 .handler = handle_method_play_file_start_with_stream_info
382         },
383         [METHOD_CALL_PLAY_FILE_STOP] = {
384                 .info = {
385                         .name = "PlayFileStop",
386                 },
387                 .handler = handle_method_play_file_stop
388         },
389         [METHOD_CALL_CLEAR_FOCUS] = {
390                 .info = {
391                         .name = "ClearFocus",
392                 },
393                 .handler = handle_method_clear_focus
394         },
395         [METHOD_CALL_PLAY_DTMF] = {
396                 .info = {
397                         .name = "PlayDTMF",
398                 },
399                 .handler = handle_method_play_dtmf
400         },
401         [METHOD_CALL_PLAY_DTMF_WITH_STREAM_INFO] = {
402                 .info = {
403                         .name = "PlayDTMFWithStreamInfo",
404                 },
405                 .handler = handle_method_play_dtmf_with_stream_info
406         },
407         [METHOD_CALL_GET_BT_A2DP_STATUS] = {
408                 .info = {
409                         .name = "GetBTA2DPStatus",
410                 },
411                 .handler = handle_method_get_bt_a2dp_status
412         },
413         [METHOD_CALL_SET_PATH_FOR_ACTIVE_DEVICE] = {
414                 .info = {
415                         .name = "SetPathForActiveDevice",
416                 },
417                 .handler = handle_method_set_sound_path_for_active_device
418         },
419         [METHOD_CALL_GET_AUDIO_PATH] = {
420                 .info = {
421                         .name = "GetAudioPath",
422                 },
423                 .handler = handle_method_get_audio_path
424         },
425         [METHOD_CALL_GET_CONNECTED_DEVICE_LIST] = {
426                 .info = {
427                         .name = "GetConnectedDeviceList",
428                 },
429                 .handler = handle_method_get_connected_device_list
430         },
431         [METHOD_CALL_ASM_REGISTER_SOUND] = {
432                 .info = {
433                         .name = "ASMRegisterSound",
434                 },
435                 .handler = handle_method_asm_register_sound
436         },
437         [METHOD_CALL_ASM_UNREGISTER_SOUND] = {
438                 .info = {
439                         .name = "ASMUnregisterSound",
440                 },
441                 .handler = handle_method_asm_unregister_sound
442         },
443         [METHOD_CALL_ASM_REGISTER_WATCHER] = {
444                 .info = {
445                         .name = "ASMRegisterWatcher",
446                 },
447                 .handler = handle_method_asm_register_watcher
448         },
449         [METHOD_CALL_ASM_UNREGISTER_WATCHER] = {
450                 .info = {
451                         .name = "ASMUnregisterWatcher",
452                 },
453                 .handler = handle_method_asm_unregister_watcher
454         },
455         [METHOD_CALL_ASM_GET_MYSTATE] = {
456                 .info = {
457                         .name = "ASMGetMyState",
458                 },
459                 .handler = handle_method_asm_get_mystate
460         },
461         [METHOD_CALL_ASM_GET_STATE] = {
462                 .info = {
463                         .name = "ASMGetState",
464                 },
465                 .handler = handle_method_asm_get_state
466         },
467         [METHOD_CALL_ASM_SET_STATE] = {
468                 .info = {
469                         .name = "ASMSetState",
470                 },
471                 .handler = handle_method_asm_set_state
472         },
473         [METHOD_CALL_ASM_SET_SUBSESSION] = {
474                 .info = {
475                         .name = "ASMSetSubsession",
476                 },
477                 .handler = handle_method_asm_set_subsession
478         },
479         [METHOD_CALL_ASM_GET_SUBSESSION] = {
480                 .info = {
481                         .name = "ASMGetSubsession",
482                 },
483                 .handler = handle_method_asm_get_subsession
484         },
485         [METHOD_CALL_ASM_SET_SUBEVENT] = {
486                 .info = {
487                         .name = "ASMSetSubevent",
488                 },
489                 .handler = handle_method_asm_set_subevent
490         },
491         [METHOD_CALL_ASM_GET_SUBEVENT] = {
492                 .info = {
493                         .name = "ASMGetSubevent",
494                 },
495                 .handler = handle_method_asm_get_subevent
496         },
497         [METHOD_CALL_ASM_SET_SESSION_OPTION] = {
498                 .info = {
499                         .name = "ASMSetSessionOption",
500                 },
501                 .handler = handle_method_asm_set_session_option
502         },
503         [METHOD_CALL_ASM_GET_SESSION_OPTION] = {
504                 .info = {
505                         .name = "ASMGetSessionOption",
506                 },
507                 .handler = handle_method_asm_get_session_option
508         },
509         [METHOD_CALL_ASM_RESET_RESUME_TAG] = {
510                 .info = {
511                         .name = "ASMResetResumeTag",
512                 },
513                 .handler = handle_method_asm_reset_resume_tag
514         },
515         [METHOD_CALL_ASM_DUMP] = {
516                 .info = {
517                         .name = "ASMDump",
518                 },
519                 .handler = handle_method_asm_dump
520         },
521 };
522
523 struct mm_sound_dbus_signal signals[SIGNAL_MAX] = {
524         [SIGNAL_TEST] = {
525                 .info = {
526                         .name = "SignalTest1",
527                 },
528         },
529         [SIGNAL_PLAY_FILE_END] = {
530                 .info = {
531                         .name = "PlayFileEnd",
532                 },
533         },
534         [SIGNAL_VOLUME_CHANGED] = {
535                 .info = {
536                         .name = "VolumeChanged",
537                 },
538         },
539         [SIGNAL_DEVICE_CONNECTED] = {
540                 .info = {
541                         .name = "DeviceConnected",
542                 },
543         },
544         [SIGNAL_DEVICE_INFO_CHANGED] = {
545                 .info = {
546                         .name = "DeviceInfoChanged",
547                 },
548         },
549 };
550
551
552
553 static GDBusNodeInfo *introspection_data = NULL;
554 guint sound_server_owner_id ;
555
556 /*
557         For pass error code with 'g_dbus_method_invocation_return_error'
558         We have to use some glib features like GError, GQuark
559 */
560 /* Only For error types which is currently being used in server-side */
561 static const GDBusErrorEntry mm_sound_error_entries[] =
562 {
563         {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
564         {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
565         {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
566         {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
567         {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
568         {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
569         {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
570         {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
571         {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
572         {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
573         {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
574         {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
575         {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
576         {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
577         {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
578         {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
579         {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
580         {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
581         {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
582 };
583
584 static const char* _convert_error_code(int err_code)
585 {
586         int i = 0;
587
588         for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
589                 if (err_code == mm_sound_error_entries[i].error_code) {
590                         return mm_sound_error_entries[i].dbus_error_name;
591                 }
592         }
593
594         return "org.tizen.multimedia.common.Unknown";
595 }
596
597 static int mm_sound_mgr_ipc_dbus_send_signal(int signal_type, GVariant *parameter)
598 {
599         int ret = MM_ERROR_NONE;
600         GDBusConnection *conn = NULL;
601         GError* err = NULL;
602         gboolean emit_success = FALSE;
603
604         if (signal_type < 0 || signal_type >= SIGNAL_MAX || !parameter) {
605                 debug_error("Invalid Argument");
606                 return MM_ERROR_SOUND_INTERNAL;
607         }
608
609         debug_log("Signal Emit : %s", signals[signal_type].info.name);
610
611         if (!conn_g) {
612                 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
613                 if (!conn && err) {
614                         debug_error ("g_bus_get_sync() error (%s) ", err->message);
615                         g_error_free (err);
616                         return MM_ERROR_SOUND_INTERNAL;
617                 }
618                 conn_g = conn;
619         }
620 /*
621         if (!g_variant_is_of_type(parameter, G_VARIANT_TYPE(signals[signal_type].info.argument))) {
622                 debug_error("Invalid Signal Parameter");
623                 return MM_ERROR_INVALID_ARGUMENT;
624         }
625         */
626
627         emit_success = g_dbus_connection_emit_signal(conn_g, NULL, OBJECT_SOUND_SERVER, INTERFACE_SOUND_SERVER,
628                                                                                                 signals[signal_type].info.name, parameter, &err);
629         if (!emit_success && err) {
630                 debug_error("Emit signal (%s) failed, (%s)", signals[signal_type].info.name, err->message);
631                 g_error_free(err);
632                 return MM_ERROR_SOUND_INTERNAL;
633         }
634
635         return ret;
636 }
637
638 static int _get_sender_pid(GDBusMethodInvocation* invocation)
639 {
640         GVariant* value;
641         guint pid;
642         const gchar* sender;
643         GDBusConnection * connection = NULL;
644         GError* err = NULL;
645
646         connection = g_dbus_method_invocation_get_connection(invocation);
647         sender = g_dbus_method_invocation_get_sender(invocation);
648
649         debug_error ("connection = %p, sender = %s", connection, sender);
650
651         value = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
652                                                                                 "org.freedesktop.DBus", "GetConnectionUnixProcessID",
653                                                                                 g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
654         if (value) {
655                 g_variant_get(value, "(u)", &pid);
656                 debug_error ("Sender PID = [%d]", pid);
657         } else {
658                 debug_error ("err code = %d, err msg = %s", err->code, err->message);
659         }
660         return pid;
661 }
662
663 static void _method_call_return_value(GDBusMethodInvocation *invocation, GVariant *params)
664 {
665         const char *method_name;
666         method_name = g_dbus_method_invocation_get_method_name(invocation);
667         debug_error("Method Call '%s' success", method_name);
668         g_dbus_method_invocation_return_value(invocation, params);
669 }
670 static void _method_call_return_error(GDBusMethodInvocation *invocation, int ret)
671 {
672         const char *err_name, *method_name;
673         err_name = _convert_error_code(ret);
674         method_name = g_dbus_method_invocation_get_method_name(invocation);
675         debug_error("Method Call '%s' failed, err '%s(%X)'", method_name, err_name, ret);
676         g_dbus_method_invocation_return_dbus_error(invocation, err_name, "failed");
677 }
678
679 static void handle_method_test(GDBusMethodInvocation* invocation)
680 {
681         int ret = MM_ERROR_NONE;
682         int val = 0, val2 = 0;
683         GVariant* params = NULL;
684
685         debug_fenter();
686
687         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
688                 debug_error("Parameter for Method is NULL");
689                 ret = MM_ERROR_SOUND_INTERNAL;
690                 goto send_reply;
691         }
692
693         g_variant_get(params, "(ii)", &val, &val2);
694         debug_log("Got value : %d , %d", val, val2);
695
696         if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_TEST, g_variant_new("(i)", val+val2))) != MM_ERROR_NONE) {
697                 debug_error("signal send error : %X", ret);
698         } else {
699                 debug_error("signal send success");
700         }
701
702 send_reply:
703         if (ret == MM_ERROR_NONE) {
704                 _method_call_return_value(invocation, g_variant_new("(i)", val * val2));
705         } else {
706                 ret = MM_ERROR_INVALID_ARGUMENT;
707                 _method_call_return_error(invocation,  ret);
708         }
709
710         debug_fleave();
711 }
712
713 static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
714 {
715         gchar* filename = NULL;
716         char *stream_type = NULL;
717         gint32 ret = MM_ERROR_NONE, slotid = 0;
718         gint32 tone = 0, repeat = 0, volume = 0, vol_config = 0, priority = 0;
719         gint32 session_type = 0, session_option = 0, pid = 0, handle_route =0, stream_index = 0;
720         gboolean enable_session = 0;
721         GVariant *params = NULL;
722
723         debug_fenter();
724
725         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
726                 debug_error("Parameter for Method is NULL");
727                 ret = MM_ERROR_SOUND_INTERNAL;
728                 goto send_reply;
729         }
730
731         g_variant_get(params, "(siiiiiiiiibsi)", &filename, &tone, &repeat, &volume,
732                       &vol_config, &priority, &session_type, &session_option, &pid, &handle_route, &enable_session, &stream_type, &stream_index);
733         if (!filename) {
734             debug_error("filename null");
735             ret = MM_ERROR_SOUND_INTERNAL;
736             goto send_reply;
737         }
738         ret = _MMSoundMgrIpcPlayFile(filename, tone, repeat, volume, vol_config, priority,
739                                 session_type, session_option, _get_sender_pid(invocation), handle_route, enable_session, &slotid, stream_type, stream_index);
740
741 send_reply:
742         if (ret == MM_ERROR_NONE) {
743                 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
744         } else {
745                 _method_call_return_error(invocation, ret);
746         }
747
748         debug_fleave();
749 }
750
751 static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation)
752 {
753         gchar* filename = NULL;
754         char *stream_type = NULL;
755         gint32 ret = MM_ERROR_NONE, slotid = 0;
756         gint32 repeat = 0, volume = 0, priority = 0, pid = 0, handle_route =0, stream_index = 0;
757         GVariant *params = NULL;
758
759         debug_fenter();
760
761         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
762                 debug_error("Parameter for Method is NULL");
763                 ret = MM_ERROR_SOUND_INTERNAL;
764                 goto send_reply;
765         }
766
767         g_variant_get(params, "(siiiiisi)", &filename, &repeat, &volume,
768                       &priority, &pid, &handle_route, &stream_type, &stream_index);
769         if (!filename) {
770             debug_error("filename null");
771             ret = MM_ERROR_SOUND_INTERNAL;
772             goto send_reply;
773         }
774         ret = _MMSoundMgrIpcPlayFileWithStreamInfo(filename, repeat, volume, priority,
775                                 _get_sender_pid(invocation), handle_route, &slotid, stream_type, stream_index);
776
777 send_reply:
778         if (ret == MM_ERROR_NONE) {
779                 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
780         } else {
781                 _method_call_return_error(invocation, ret);
782         }
783
784         debug_fleave();
785 }
786
787 static void handle_method_play_dtmf(GDBusMethodInvocation* invocation)
788 {
789         int ret = MM_ERROR_NONE, slotid = 0;
790         int tone = 0, repeat = 0, volume = 0, vol_config = 0, session_type = 0, session_option = 0, pid = 0, stream_index = 0;
791         char* stream_type = NULL;
792         gboolean enable_session = 0;
793         GVariant *params = NULL;
794
795         debug_fenter();
796
797         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
798                 debug_error("Parameter for Method is NULL");
799                 ret = MM_ERROR_SOUND_INTERNAL;
800                 goto send_reply;
801         }
802
803         g_variant_get(params, "(iiiiiiibsi)", &tone, &repeat, &volume,
804                       &vol_config, &session_type, &session_option, &pid, &enable_session, &stream_type, &stream_index);
805         debug_error("volume - %d", volume);
806         ret = _MMSoundMgrIpcPlayDTMF(tone, repeat, volume, vol_config,
807                                      session_type, session_option, _get_sender_pid(invocation), enable_session, &slotid, stream_type, stream_index);
808
809 send_reply:
810         if (ret == MM_ERROR_NONE) {
811                 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
812         } else {
813                 _method_call_return_error(invocation, ret);
814         }
815
816
817         debug_fleave();
818 }
819
820 static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation)
821 {
822         int ret = MM_ERROR_NONE, slotid = 0;
823         int tone = 0, repeat = 0, volume = 0, pid = 0, stream_index = 0;
824         char* stream_type = NULL;
825         GVariant *params = NULL;
826
827         debug_fenter();
828
829         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
830                 debug_error("Parameter for Method is NULL");
831                 ret = MM_ERROR_SOUND_INTERNAL;
832                 goto send_reply;
833         }
834
835         g_variant_get(params, "(iiiisi)", &tone, &repeat, &volume, &pid, &stream_type, &stream_index);
836         ret = _MMSoundMgrIpcPlayDTMFWithStreamInfo(tone, repeat, volume, _get_sender_pid(invocation), &slotid, stream_type, stream_index);
837
838 send_reply:
839         if (ret == MM_ERROR_NONE) {
840                 _method_call_return_value(invocation, g_variant_new("(i)", slotid));
841         } else {
842                 _method_call_return_error(invocation, ret);
843         }
844
845         debug_fleave();
846 }
847
848 static void handle_method_play_file_stop(GDBusMethodInvocation* invocation)
849 {
850         int ret = MM_ERROR_NONE;
851         int handle = 0;
852         GVariant *params = NULL;
853
854         debug_fenter();
855
856         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
857                 debug_error("Parameter for Method is NULL");
858                 ret = MM_ERROR_SOUND_INTERNAL;
859                 goto send_reply;
860         }
861
862         g_variant_get(params, "(i)", &handle);
863         ret = _MMSoundMgrIpcStop(handle);
864
865 send_reply:
866         if (ret == MM_ERROR_NONE) {
867                 _method_call_return_value(invocation, g_variant_new("()"));
868         } else {
869                 _method_call_return_error(invocation, ret);
870         }
871
872         debug_fleave();
873 }
874
875 static void handle_method_clear_focus(GDBusMethodInvocation* invocation)
876 {
877         int ret = MM_ERROR_NONE;
878         int pid = 0;
879         GVariant *params = NULL;
880
881         debug_fenter();
882
883         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
884                 debug_error("Parameter for Method is NULL");
885                 ret = MM_ERROR_SOUND_INTERNAL;
886                 goto send_reply;
887         }
888
889         g_variant_get(params, "(i)", &pid);
890         ret = _MMSoundMgrIpcClearFocus(pid);
891
892 send_reply:
893         if (ret == MM_ERROR_NONE) {
894                 _method_call_return_value(invocation, g_variant_new("()"));
895         } else {
896                 _method_call_return_error(invocation, ret);
897         }
898
899         debug_fleave();
900 }
901
902 static void handle_method_get_bt_a2dp_status(GDBusMethodInvocation* invocation)
903 {
904         int ret = MM_ERROR_NONE;
905         gboolean is_bt_on = FALSE;
906         gchar* bt_name = NULL;
907
908         debug_fenter();
909
910 //      ret = MMSoundMgrPulseHandleIsBtA2DPOnReq(&is_bt_on, &bt_name);
911
912 send_reply:
913         if (ret == MM_ERROR_NONE) {
914                 _method_call_return_value(invocation, g_variant_new("(bs)", is_bt_on, bt_name));
915         } else {
916                 _method_call_return_error(invocation, ret);
917         }
918
919         if (bt_name)
920                 g_free(bt_name);
921
922         debug_fleave();
923 }
924
925 static void handle_method_set_sound_path_for_active_device( GDBusMethodInvocation* invocation)
926 {
927         int ret = MM_ERROR_NONE;
928         int device_in = 0, device_out = 0;
929         GVariant *params = NULL;
930
931         debug_fenter();
932
933         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
934                 debug_error("Parameter for Method is NULL");
935                 ret = MM_ERROR_SOUND_INTERNAL;
936                 goto send_reply;
937         }
938
939         g_variant_get(params, "(ii)", &device_in, &device_out);
940         ret = __mm_sound_mgr_ipc_set_sound_path_for_active_device(device_in, device_out);
941
942 send_reply:
943         if (ret == MM_ERROR_NONE) {
944                 _method_call_return_value(invocation, g_variant_new("()"));
945         } else {
946                 _method_call_return_error(invocation, ret);
947         }
948
949         debug_fleave();
950 }
951
952 static void handle_method_get_audio_path(GDBusMethodInvocation* invocation)
953 {
954         int ret = MM_ERROR_NONE;
955         int device_in = 0, device_out = 0;
956
957         debug_fenter();
958
959         ret = __mm_sound_mgr_ipc_get_audio_path(&device_in, &device_out);
960
961 send_reply:
962         if (ret == MM_ERROR_NONE) {
963                 _method_call_return_value(invocation, g_variant_new("(ii)", device_in, device_out));
964         } else {
965                 _method_call_return_error(invocation, ret);
966         }
967
968         debug_fleave();
969 }
970
971 static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation)
972 {
973         int ret = MM_ERROR_NONE;
974         GVariant *params = NULL, *reply_v = NULL;
975         GVariantBuilder reply_builder;
976         int mask_flags = 0;
977         int devices_num = 0, device_idx = 0;
978         mm_sound_device_t *device_list = NULL, *device_entry = NULL;
979
980         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
981                 debug_error("Parameter for Method is NULL");
982                 ret = MM_ERROR_SOUND_INTERNAL;
983                 goto send_reply;
984         }
985
986         g_variant_get(params, "(i)", &mask_flags);
987         debug_log("Get device list with device_flag %X", mask_flags);
988         if ((ret = __mm_sound_mgr_ipc_get_current_connected_device_list(mask_flags, &device_list, &devices_num))==MM_ERROR_NONE) {
989                 g_variant_builder_init(&reply_builder, G_VARIANT_TYPE("(a(iiiis))"));
990                 g_variant_builder_open(&reply_builder, G_VARIANT_TYPE("a(iiiis)"));
991                 for (device_idx = 0; device_idx < devices_num; device_idx++) {
992                         device_entry = &device_list[device_idx];
993 //                      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);
994                         g_variant_builder_add(&reply_builder, "(iiiis)", device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
995                 }
996                 g_variant_builder_close(&reply_builder);
997         }
998
999 send_reply:
1000         if (ret == MM_ERROR_NONE) {
1001                 _method_call_return_value(invocation, g_variant_builder_end(&reply_builder));
1002                 debug_log("Reply Sent");
1003         } else {
1004                 _method_call_return_error(invocation, ret);
1005         }
1006 }
1007
1008 /*********************** ASM METHODS ****************************/
1009
1010 #ifdef SUPPORT_CONTAINER
1011 #ifdef USE_SECURITY
1012 static char* _get_container_from_cookie(GVariant* cookie_data)
1013 {
1014         char* container = NULL;
1015         int cookie_len = 0;
1016         char* cookie = NULL;
1017         int ret = 0;
1018
1019         cookie_len = g_variant_get_size(cookie_data);
1020         if (cookie_len != COOKIE_SIZE) {
1021                 debug_error ("cookie_len = [%d]", cookie_len);
1022                 return NULL;
1023         }
1024
1025         ret = security_server_get_zone_by_cookie(g_variant_get_data(cookie_data), &container);
1026         if (ret == SECURITY_SERVER_API_SUCCESS) {
1027                 debug_error ("success!!!! zone = [%s]", container);
1028         } else {
1029                 debug_error ("failed!!!! ret = [%d]", ret);
1030         }
1031
1032         return container;
1033 }
1034 #endif /* USE_SECURITY */
1035 #endif /* SUPPORT_CONTAINER */
1036
1037 // TODO : Too many arguments..
1038 static void handle_method_asm_register_sound(GDBusMethodInvocation* invocation)
1039 {
1040         int ret = MM_ERROR_NONE;
1041         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1042         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
1043         GVariant *params = NULL;
1044 #ifdef SUPPORT_CONTAINER
1045         int container_pid = -1;
1046         char* container = NULL;
1047 #ifdef USE_SECURITY
1048         GVariant* cookie_data;
1049 #endif /* USE_SECURITY */
1050 #endif /* SUPPORT_CONTAINER */
1051
1052         debug_fenter();
1053
1054         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1055                 debug_error("Parameter for Method is NULL");
1056                 ret = MM_ERROR_SOUND_INTERNAL;
1057                 goto send_reply;
1058         }
1059
1060 #ifdef SUPPORT_CONTAINER
1061 #ifdef USE_SECURITY
1062         g_variant_get(params, "(@ayiiiiii)", &cookie_data, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1063         container = _get_container_from_cookie(cookie_data);
1064         ret = __mm_sound_mgr_ipc_asm_register_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1065                                         container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1066         if (container)
1067                 free(container);
1068 #else /* USE_SECURITY */
1069         g_variant_get(params, "(siiiiii)", &container, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1070         ret = __mm_sound_mgr_ipc_asm_register_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1071                                         container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1072 #endif /* USE_SECURITY */
1073 #else /* SUPPORT_CONTAINER */
1074         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1075         ret = __mm_sound_mgr_ipc_asm_register_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1076                                         &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1077 #endif /* SUPPORT_CONTAINER */
1078
1079 send_reply:
1080         if (ret == MM_ERROR_NONE) {
1081                 _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1082                                                                     request_id_r, sound_command_r, sound_state_r));
1083         } else {
1084                 _method_call_return_error(invocation, ret);
1085         }
1086
1087         debug_fleave();
1088 }
1089
1090 static void handle_method_asm_unregister_sound(GDBusMethodInvocation* invocation)
1091 {
1092         int ret = MM_ERROR_NONE;
1093         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1094         GVariant *params = NULL;
1095
1096         debug_fenter();
1097
1098         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1099                 debug_error("Parameter for Method is NULL");
1100                 ret = MM_ERROR_SOUND_INTERNAL;
1101                 goto send_reply;
1102         }
1103
1104         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1105         ret = __mm_sound_mgr_ipc_asm_unregister_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource);
1106
1107 send_reply:
1108         if (ret == MM_ERROR_NONE) {
1109                 _method_call_return_value(invocation, g_variant_new("()"));
1110         } else {
1111                 _method_call_return_error(invocation, ret);
1112         }
1113
1114         debug_fleave();
1115 }
1116
1117 static void handle_method_asm_register_watcher(GDBusMethodInvocation* invocation)
1118 {
1119         int ret = MM_ERROR_NONE;
1120         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1121         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
1122         GVariant *params = NULL;
1123 #ifdef SUPPORT_CONTAINER
1124         int container_pid = -1;
1125         char* container = NULL;
1126 #ifdef USE_SECURITY
1127         GVariant* cookie_data;
1128 #endif /* USE_SECURITY */
1129 #endif /* SUPPORT_CONTAINER */
1130
1131         debug_fenter();
1132
1133         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1134                 debug_error("Parameter for Method is NULL");
1135                 ret = MM_ERROR_SOUND_INTERNAL;
1136                 goto send_reply;
1137         }
1138
1139 #ifdef SUPPORT_CONTAINER
1140 #ifdef USE_SECURITY
1141         g_variant_get(params, "(@ayiiiiii)", &cookie_data, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1142         container = _get_container_from_cookie(cookie_data);
1143         ret = __mm_sound_mgr_ipc_asm_register_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1144                                                 container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1145         if (container)
1146                 free(container);
1147 #else /* USE_SECURITY */
1148         g_variant_get(params, "(siiiiii)", &container, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1149         ret = __mm_sound_mgr_ipc_asm_register_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1150                                         container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1151 #endif /* USE_SECURITY */
1152 #else /* SUPPORT_CONTAINER */
1153         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1154         ret = __mm_sound_mgr_ipc_asm_register_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1155                         &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1156 #endif /* SUPPORT_CONTAINER */
1157
1158 send_reply:
1159         if (ret == MM_ERROR_NONE) {
1160                 _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1161                                                                     request_id_r, sound_command_r, sound_state_r));
1162         } else {
1163                 _method_call_return_error(invocation, ret);
1164         }
1165
1166         debug_fleave();
1167 }
1168
1169 static void handle_method_asm_unregister_watcher(GDBusMethodInvocation* invocation)
1170 {
1171         int ret = MM_ERROR_NONE;
1172         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1173         GVariant *params = NULL;
1174
1175         debug_fenter();
1176
1177         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1178                 debug_error("Parameter for Method is NULL");
1179                 ret = MM_ERROR_SOUND_INTERNAL;
1180                 goto send_reply;
1181         }
1182
1183         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1184         ret = __mm_sound_mgr_ipc_asm_unregister_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource);
1185
1186 send_reply:
1187         if (ret == MM_ERROR_NONE) {
1188                 _method_call_return_value(invocation, g_variant_new("()"));
1189         } else {
1190                 _method_call_return_error(invocation, ret);
1191         }
1192
1193         debug_fleave();
1194 }
1195
1196 static void handle_method_asm_get_mystate(GDBusMethodInvocation* invocation)
1197 {
1198         int ret = MM_ERROR_NONE;
1199         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1200         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
1201         GVariant *params = NULL;
1202
1203         debug_fenter();
1204
1205         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1206                 debug_error("Parameter for Method is NULL");
1207                 ret = MM_ERROR_SOUND_INTERNAL;
1208                 goto send_reply;
1209         }
1210
1211         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1212         ret = __mm_sound_mgr_ipc_asm_get_mystate(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1213                                                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_state_r);
1214
1215 send_reply:
1216         if (ret == MM_ERROR_NONE) {
1217                 _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1218                                                                     request_id_r, sound_state_r));
1219         } else {
1220                 _method_call_return_error(invocation, ret);
1221         }
1222
1223         debug_fleave();
1224 }
1225
1226 static void handle_method_asm_set_state(GDBusMethodInvocation* invocation)
1227 {
1228         int ret = MM_ERROR_NONE;
1229         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1230         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0, error_code_r = 0;
1231         GVariant *params = NULL;
1232
1233         debug_fenter();
1234
1235         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1236                 debug_error("Parameter for Method is NULL");
1237                 ret = MM_ERROR_SOUND_INTERNAL;
1238                 goto send_reply;
1239         }
1240
1241         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1242         ret = __mm_sound_mgr_ipc_asm_set_state(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1243                                                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r, &error_code_r);
1244
1245 send_reply:
1246         if (ret == MM_ERROR_NONE) {
1247                 _method_call_return_value(invocation, g_variant_new("(iiiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1248                                                                     request_id_r, sound_command_r, sound_state_r, error_code_r));
1249         } else {
1250                 _method_call_return_error(invocation, ret);
1251         }
1252
1253         debug_fleave();
1254 }
1255
1256 static void handle_method_asm_get_state(GDBusMethodInvocation* invocation)
1257 {
1258         int ret = MM_ERROR_NONE;
1259         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1260         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
1261         GVariant *params = NULL;
1262
1263         debug_fenter();
1264
1265         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1266                 debug_error("Parameter for Method is NULL");
1267                 ret = MM_ERROR_SOUND_INTERNAL;
1268                 goto send_reply;
1269         }
1270
1271         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1272         ret = __mm_sound_mgr_ipc_asm_get_state(pid, handle, sound_event, request_id, sound_state, resource,
1273                                                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_state_r);
1274
1275 send_reply:
1276         if (ret == MM_ERROR_NONE) {
1277                 _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1278                                                                     request_id_r, sound_state_r));
1279         } else {
1280                 _method_call_return_error(invocation, ret);
1281         }
1282
1283         debug_fleave();
1284 }
1285
1286 static void handle_method_asm_set_subsession(GDBusMethodInvocation* invocation)
1287 {
1288         int ret = MM_ERROR_NONE;
1289         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1290         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0;
1291         GVariant *params = NULL;
1292
1293         debug_fenter();
1294
1295         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1296                 debug_error("Parameter for Method is NULL");
1297                 ret = MM_ERROR_SOUND_INTERNAL;
1298                 goto send_reply;
1299         }
1300
1301         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1302         ret = __mm_sound_mgr_ipc_asm_set_subsession(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1303                                                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r);
1304
1305 send_reply:
1306         if (ret == MM_ERROR_NONE) {
1307                 _method_call_return_value(invocation, g_variant_new("(iiii)", pid_r, alloc_handle_r, cmd_handle_r,
1308                                                                     request_id_r));
1309         } else {
1310                 _method_call_return_error(invocation, ret);
1311         }
1312
1313         debug_fleave();
1314 }
1315
1316 static void handle_method_asm_get_subsession(GDBusMethodInvocation* invocation)
1317 {
1318         int ret = MM_ERROR_NONE;
1319         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1320         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0;
1321         GVariant *params = NULL;
1322
1323         debug_fenter();
1324
1325         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1326                 debug_error("Parameter for Method is NULL");
1327                 ret = MM_ERROR_SOUND_INTERNAL;
1328                 goto send_reply;
1329         }
1330
1331         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1332         ret = __mm_sound_mgr_ipc_asm_get_subsession(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1333                                                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r);
1334
1335 send_reply:
1336         if (ret == MM_ERROR_NONE) {
1337                 _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1338                                                                     request_id_r, sound_command_r));
1339         } else {
1340                 _method_call_return_error(invocation, ret);
1341         }
1342
1343         debug_fleave();
1344 }
1345
1346 static void handle_method_asm_set_subevent(GDBusMethodInvocation* invocation)
1347 {
1348         int ret = MM_ERROR_NONE;
1349         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1350         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
1351         GVariant *params = NULL;
1352
1353         debug_fenter();
1354
1355         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1356                 debug_error("Parameter for Method is NULL");
1357                 ret = MM_ERROR_SOUND_INTERNAL;
1358                 goto send_reply;
1359         }
1360
1361         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1362         ret = __mm_sound_mgr_ipc_asm_set_subevent(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1363                                                    &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1364
1365 send_reply:
1366         if (ret == MM_ERROR_NONE) {
1367                 _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1368                                                                  request_id_r, sound_command_r, sound_state_r));
1369         } else {
1370                 _method_call_return_error(invocation, ret);
1371         }
1372
1373         debug_fleave();
1374 }
1375
1376 static void handle_method_asm_get_subevent(GDBusMethodInvocation* invocation)
1377 {
1378         int ret = MM_ERROR_NONE;
1379         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1380         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0;
1381         GVariant *params = NULL;
1382
1383         debug_fenter();
1384
1385         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1386                 debug_error("Parameter for Method is NULL");
1387                 ret = MM_ERROR_SOUND_INTERNAL;
1388                 goto send_reply;
1389         }
1390
1391         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1392         ret = __mm_sound_mgr_ipc_asm_get_subevent(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1393                                                    &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r);
1394
1395 send_reply:
1396         if (ret == MM_ERROR_NONE) {
1397                 _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1398                                                                  request_id_r, sound_command_r ));
1399         } else {
1400                 _method_call_return_error(invocation, ret);
1401         }
1402
1403         debug_fleave();
1404 }
1405
1406 static void handle_method_asm_set_session_option(GDBusMethodInvocation* invocation)
1407 {
1408         int ret = MM_ERROR_NONE;
1409         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1410         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, error_code_r = 0;
1411         GVariant *params = NULL;
1412
1413         debug_fenter();
1414
1415         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1416                 debug_error("Parameter for Method is NULL");
1417                 ret = MM_ERROR_SOUND_INTERNAL;
1418                 goto send_reply;
1419         }
1420
1421         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1422         ret = __mm_sound_mgr_ipc_asm_set_session_option(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1423                                                 &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &error_code_r);
1424
1425 send_reply:
1426         if (ret == MM_ERROR_NONE) {
1427                 _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1428                                                               request_id_r, sound_command_r, error_code_r ));
1429         } else {
1430                 _method_call_return_error(invocation, ret);
1431         }
1432
1433         debug_fleave();
1434 }
1435
1436 static void handle_method_asm_get_session_option(GDBusMethodInvocation* invocation)
1437 {
1438         int ret = MM_ERROR_NONE;
1439         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1440         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, option_flag_r = 0;
1441         GVariant *params = NULL;
1442
1443         debug_fenter();
1444
1445         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1446                 debug_error("Parameter for Method is NULL");
1447                 ret = MM_ERROR_SOUND_INTERNAL;
1448                 goto send_reply;
1449         }
1450
1451         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1452         ret = __mm_sound_mgr_ipc_asm_get_session_option(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1453                                              &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &option_flag_r);
1454
1455 send_reply:
1456         if (ret == MM_ERROR_NONE) {
1457                 _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1458                                                            request_id_r, sound_command_r, option_flag_r ));
1459         } else {
1460                 _method_call_return_error(invocation, ret);
1461         }
1462
1463         debug_fleave();
1464 }
1465
1466 static void handle_method_asm_reset_resume_tag(GDBusMethodInvocation* invocation)
1467 {
1468         int ret = MM_ERROR_NONE;
1469         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1470         int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
1471         GVariant *params = NULL;
1472
1473         debug_fenter();
1474
1475         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1476                 debug_error("Parameter for Method is NULL");
1477                 ret = MM_ERROR_SOUND_INTERNAL;
1478                 goto send_reply;
1479         }
1480
1481         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1482         ret = __mm_sound_mgr_ipc_asm_reset_resume_tag(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
1483                                           &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
1484
1485 send_reply:
1486         if (ret == MM_ERROR_NONE) {
1487                 _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
1488                                                         request_id_r, sound_command_r, sound_state_r ));
1489         } else {
1490                 _method_call_return_error(invocation, ret);
1491         }
1492
1493         debug_fleave();
1494 }
1495
1496 static void handle_method_asm_dump(GDBusMethodInvocation* invocation)
1497 {
1498
1499         int ret = MM_ERROR_NONE;
1500         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
1501         GVariant *params = NULL;
1502
1503         debug_fenter();
1504
1505         if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
1506                 debug_error("Parameter for Method is NULL");
1507                 ret = MM_ERROR_SOUND_INTERNAL;
1508                 goto send_reply;
1509         }
1510
1511         g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
1512         ret = __mm_sound_mgr_ipc_asm_dump(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource);
1513
1514 send_reply:
1515         if (ret == MM_ERROR_NONE) {
1516                 _method_call_return_value(invocation, g_variant_new("()"));
1517         } else {
1518                 _method_call_return_error(invocation, ret);
1519         }
1520
1521         debug_fleave();
1522 }
1523
1524 /****************************************************************/
1525
1526
1527 static void handle_method_call(GDBusConnection *connection,
1528                                                         const gchar *sender,
1529                                                         const gchar *object_path,
1530                                                         const gchar *interface_name,
1531                                                         const gchar *method_name,
1532                                                         GVariant *parameters,
1533                                                         GDBusMethodInvocation *invocation,
1534                                                         gpointer userdata)
1535 {
1536         int method_idx = 0;
1537
1538         if (!parameters) {
1539                 debug_error("Parameter Null");
1540                 return;
1541         }
1542         debug_log("Method Call, obj : %s, intf : %s, method : %s", object_path, interface_name, method_name);
1543
1544         for (method_idx = 0; method_idx < METHOD_CALL_MAX; method_idx++) {
1545                 if (!g_strcmp0(method_name, methods[method_idx].info.name)) {
1546                         methods[method_idx].handler(invocation);
1547                 }
1548         }
1549 }
1550
1551
1552 static GVariant* handle_get_property(GDBusConnection *connection,
1553                                                                         const gchar *sender,
1554                                                                         const gchar *object_path,
1555                                                                         const gchar *interface_name,
1556                                                                         const gchar *property_name,
1557                                                                         GError **error,
1558                                                                         gpointer userdata)
1559 {
1560         debug_log("Get Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
1561         return NULL;
1562 }
1563
1564 static gboolean handle_set_property(GDBusConnection *connection,
1565                                                                         const gchar *sender,
1566                                                                         const gchar *object_path,
1567                                                                         const gchar *interface_name,
1568                                                                         const gchar *property_name,
1569                                                                         GVariant *value,
1570                                                                         GError **error,
1571                                                                         gpointer userdata)
1572 {
1573         debug_log("Set Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
1574         return TRUE;
1575 }
1576
1577 static const GDBusInterfaceVTable interface_vtable =
1578 {
1579         handle_method_call,
1580         handle_get_property,
1581         handle_set_property
1582 };
1583
1584 static void handle_signal_asm_emergent_exit(GVariant* params, gpointer user_data)
1585 {
1586         int ret = MM_ERROR_NONE;
1587         int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0;
1588
1589         debug_fenter();
1590
1591         if (!params) {
1592                 debug_error("Invalid Parameters");
1593                 return;
1594         }
1595
1596         g_variant_get(params, "(iiiii)", &pid, &handle, &sound_event, &request_id, &sound_state);
1597         ret = __mm_sound_mgr_ipc_asm_emergent_exit(pid, handle, sound_event, request_id, sound_state);
1598
1599         if (ret == MM_ERROR_NONE)
1600                 debug_error("ASM emergent exit, successfully handled");
1601         else
1602                 debug_error("ASM emergent exit, handle failed, ret : 0x%X", ret);
1603
1604         debug_fleave();
1605 }
1606
1607 static void handle_signal(GDBusConnection  *connection,
1608                                      const gchar      *sender_name,
1609                                      const gchar      *object_path,
1610                                      const gchar      *interface_name,
1611                                      const gchar      *signal_name,
1612                                      GVariant         *params,
1613                                      gpointer          user_data)
1614 {
1615         if (!object_path || !interface_name || !signal_name) {
1616                 debug_error("Invalid Parameters");
1617                 return;
1618         }
1619
1620         debug_log("Got Signal : Object '%s, Interface '%s', Signal '%s'", object_path, interface_name, signal_name);
1621
1622         if (!g_strcmp0(object_path, OBJECT_ASM)) {
1623                 if (!g_strcmp0(interface_name, INTERFACE_ASM) && !g_strcmp0(signal_name, "EmergentExit")) {
1624                         debug_log("handle signal '%s.%s'", interface_name, signal_name);
1625                         handle_signal_asm_emergent_exit(params, user_data);
1626                 } else {
1627                         debug_log("Unknown Signal '%s.%s'", interface_name, signal_name);
1628                 }
1629         } else {
1630                 debug_log("Unknown Object '%s'", object_path);
1631         }
1632 }
1633
1634
1635 static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
1636 {
1637         guint reg_id;
1638         guint subs_id;
1639         debug_log("Bus Acquired (%s)", name);
1640
1641         conn_g = connection;
1642         reg_id = g_dbus_connection_register_object(connection,
1643                                           OBJECT_SOUND_SERVER,
1644                                           introspection_data->interfaces[0],
1645                                           &interface_vtable,
1646                                           NULL,
1647                                           NULL,
1648                                           NULL);
1649         if (!reg_id) {
1650                 debug_error("Register object(%s) failed", OBJECT_SOUND_SERVER);
1651                 return ;
1652         }
1653
1654         subs_id = g_dbus_connection_signal_subscribe(connection, NULL, INTERFACE_ASM, "EmergentExit", OBJECT_ASM, \
1655                          NULL, G_DBUS_SIGNAL_FLAGS_NONE, handle_signal, NULL, NULL );
1656
1657         if (!subs_id) {
1658                 debug_error ("g_dbus_connection_signal_subscribe() failed ");
1659                 return;
1660         }
1661 }
1662
1663 static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
1664 {
1665         debug_log("Name Acquired (%s)", name);
1666 }
1667
1668 static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
1669 {
1670         debug_log("Name Lost (%s)", name);
1671 }
1672
1673 static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_name, guint* owner_id)
1674 {
1675         guint oid;
1676
1677         debug_log("Own name (%s) for sound-server", wellknown_name);
1678
1679         oid = g_bus_own_name(bus_type, wellknown_name , G_BUS_NAME_OWNER_FLAGS_NONE,
1680                         on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
1681         if (oid <= 0) {
1682                 debug_error("Dbus own name failed");
1683                 return MM_ERROR_SOUND_INTERNAL;
1684         } else {
1685                 *owner_id = oid;
1686         }
1687
1688         return MM_ERROR_NONE;
1689 }
1690
1691 static void _mm_sound_mgr_dbus_unown_name(guint oid)
1692 {
1693         debug_log("Unown name for Sound-Server");
1694         if (oid > 0) {
1695                 g_bus_unown_name(oid);
1696         }
1697 }
1698
1699 /* not for mm-sound client */
1700 int mm_sound_mgr_ipc_dbus_send_signal_freeze (char* command, int pid)
1701 {
1702         GError *err = NULL;
1703         GDBusConnection *conn = NULL;
1704         gboolean ret;
1705
1706         if (command == NULL || pid <= 0) {
1707                 debug_error ("invalid arguments [%s][%d]", command, pid);
1708                 return -1;
1709         }
1710
1711         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
1712         if (!conn && err) {
1713                 debug_error ("g_bus_get_sync() error (%s) ", err->message);
1714                 g_error_free (err);
1715                 return -1;
1716         }
1717
1718         ret = g_dbus_connection_emit_signal (conn,
1719                                 NULL, PROC_DBUS_OBJECT, PROC_DBUS_INTERFACE, PROC_DBUS_METHOD,
1720                                 g_variant_new ("(si)", command, pid),
1721                                 &err);
1722         if (!ret && err) {
1723                 debug_error ("g_dbus_connection_emit_signal() error (%s) ", err->message);
1724                 goto error;
1725         }
1726
1727         ret = g_dbus_connection_flush_sync(conn, NULL, &err);
1728         if (!ret && err) {
1729                 debug_error ("g_dbus_connection_flush_sync() error (%s) ", err->message);
1730                 goto error;
1731         }
1732
1733         g_object_unref(conn);
1734         debug_msg ("sending [%s] for pid (%d) success", command, pid);
1735
1736         return 0;
1737
1738 error:
1739         g_error_free (err);
1740         g_object_unref(conn);
1741         return -1;
1742 }
1743
1744 int __mm_sound_mgr_ipc_dbus_notify_device_connected (mm_sound_device_t *device, gboolean is_connected)
1745 {
1746         int ret = MM_ERROR_NONE;
1747         GVariantBuilder builder;
1748         GVariant* param = NULL;
1749
1750         debug_log("Send Signal '%s'", signals[SIGNAL_DEVICE_CONNECTED]);
1751
1752         g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)b)"));
1753         g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
1754         g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
1755         g_variant_builder_close(&builder);
1756         g_variant_builder_add(&builder, "b", is_connected);
1757         param = g_variant_builder_end(&builder);
1758         if (param) {
1759                 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_DEVICE_CONNECTED, param))!= MM_ERROR_NONE) {
1760                         debug_error("Send device connected signal failed");
1761                 }
1762         } else {
1763                 debug_error("Build variant for dbus param failed");
1764         }
1765
1766         return ret;
1767 }
1768
1769 int __mm_sound_mgr_ipc_dbus_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type)
1770 {
1771         int ret = MM_ERROR_NONE;
1772         GVariantBuilder builder;
1773         GVariant* param = NULL;
1774
1775         debug_log("Send Signal '%s'", signals[SIGNAL_DEVICE_INFO_CHANGED]);
1776
1777         g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)i)"));
1778         g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
1779         g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
1780         g_variant_builder_close(&builder);
1781         g_variant_builder_add(&builder, "i", changed_device_info_type);
1782         param = g_variant_builder_end(&builder);
1783         if (param) {
1784                 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_DEVICE_INFO_CHANGED, param)) != MM_ERROR_NONE) {
1785                         debug_error("Send device info changed signal failed");
1786                 }
1787         } else {
1788                 debug_error("Build variant for dbus param failed");
1789         }
1790
1791         return ret;
1792 }
1793
1794 int __mm_sound_mgr_ipc_dbus_notify_volume_changed(unsigned int vol_type, unsigned int value)
1795 {
1796         int ret = MM_ERROR_NONE;
1797         GVariant* param = NULL;
1798
1799         debug_log("Send Signal '%s'", signals[SIGNAL_VOLUME_CHANGED]);
1800
1801         param = g_variant_new("(uu)", vol_type, value);
1802         if (param) {
1803                 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_VOLUME_CHANGED, param)) != MM_ERROR_NONE) {
1804                         debug_error("Send device connected signal failed");
1805                 }
1806         } else {
1807                 debug_error("Build variant for dbus param failed");
1808         }
1809
1810         return ret;
1811 }
1812
1813 int __mm_sound_mgr_ipc_dbus_notify_play_file_end(int handle)
1814 {
1815         int ret = MM_ERROR_NONE;
1816         GVariant* param = NULL;
1817
1818         debug_log("Send Signal '%s'", signals[SIGNAL_PLAY_FILE_END]);
1819
1820         param = g_variant_new("(i)", handle);
1821         if (param) {
1822                 if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_PLAY_FILE_END, param)) != MM_ERROR_NONE) {
1823                         debug_error("Send play file end for '%d' failed", handle);
1824                 }
1825         } else {
1826                 debug_error("Build variant for dbus param failed");
1827         }
1828
1829         return ret;
1830 }
1831
1832 int __mm_sound_mgr_ipc_dbus_notify_active_device_changed(int device_in, int device_out)
1833 {
1834         return MM_ERROR_SOUND_INTERNAL;
1835 }
1836
1837 int __mm_sound_mgr_ipc_dbus_notify_available_device_changed(int device_in, int device_out, int available)
1838 {
1839         return MM_ERROR_SOUND_INTERNAL;
1840 }
1841
1842 #define PA_BUS_NAME                                    "org.pulseaudio.Server"
1843 #define PA_STREAM_MANAGER_OBJECT_PATH                  "/org/pulseaudio/StreamManager"
1844 #define PA_STREAM_MANAGER_INTERFACE                    "org.pulseaudio.StreamManager"
1845 #define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST  "GetStreamList"
1846 int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
1847 {
1848         int ret = MM_ERROR_NONE;
1849         GVariant *result = NULL;
1850         GVariant *child = NULL;
1851         GDBusConnection *conn = NULL;
1852         GError *err = NULL;
1853         int i = 0;
1854
1855         g_type_init();
1856
1857         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
1858         if (!conn && err) {
1859                 LOGE("g_bus_get_sync() error (%s)", err->message);
1860                 g_error_free (err);
1861                 ret = MM_ERROR_SOUND_INTERNAL;
1862                 return ret;
1863         }
1864         result = g_dbus_connection_call_sync (conn,
1865                                                         PA_BUS_NAME,
1866                                                         PA_STREAM_MANAGER_OBJECT_PATH,
1867                                                         PA_STREAM_MANAGER_INTERFACE,
1868                                                         PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST,
1869                                                         NULL,
1870                                                         G_VARIANT_TYPE("(vv)"),
1871                                                         G_DBUS_CALL_FLAGS_NONE,
1872                                                         2000,
1873                                                         NULL,
1874                                                         &err);
1875         if (!result && err) {
1876                 debug_error("g_dbus_connection_call_sync() error (%s)", err->message);
1877                 ret = MM_ERROR_SOUND_INTERNAL;
1878         } else {
1879                 GVariantIter iter;
1880                 GVariant *item = NULL;
1881                 child = g_variant_get_child_value(result, 0);
1882                 item = g_variant_get_variant(child);
1883                 gchar *name;
1884                 i = 0;
1885                 g_variant_iter_init(&iter, item);
1886                 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
1887                         debug_log ("name : %s", name);
1888                         stream_list->stream_types[i++] = strdup(name);
1889                 }
1890                 g_variant_iter_free (&iter);
1891                 g_variant_unref (item);
1892                 g_variant_unref (child);
1893
1894                 child = g_variant_get_child_value(result, 1);
1895                 item = g_variant_get_variant(child);
1896                 gint32 priority;
1897                 i = 0;
1898                 g_variant_iter_init(&iter, item);
1899                 while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
1900                         debug_log ("priority : %d", priority);
1901                         stream_list->priorities[i++] = priority;
1902                 }
1903                 g_variant_iter_free (&iter);
1904                 g_variant_unref (item);
1905                 g_variant_unref (child);
1906
1907                 g_variant_unref(result);
1908         }
1909         g_object_unref(conn);
1910
1911         return ret;
1912 }
1913
1914 int MMSoundMgrDbusInit(void)
1915 {
1916         debug_enter();
1917
1918         introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1919         if (!introspection_data)
1920                 return MM_ERROR_SOUND_INTERNAL;
1921
1922         if (_mm_sound_mgr_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_SOUND_SERVER, &sound_server_owner_id) != MM_ERROR_NONE) {
1923                 debug_error ("dbus own name for sound-server error\n");
1924                 return MM_ERROR_SOUND_INTERNAL;
1925         }
1926
1927         debug_leave();
1928
1929         return MM_ERROR_NONE;
1930 }
1931
1932 void MMSoundMgrDbusFini(void)
1933 {
1934         debug_enter("\n");
1935
1936         _mm_sound_mgr_dbus_unown_name(sound_server_owner_id);
1937         g_dbus_node_info_unref (introspection_data);
1938
1939         debug_leave("\n");
1940 }
1941
1942
1943