bbd357acfedef8766db2e67018ed71399b2cf9f9
[platform/core/multimedia/libmm-sound.git] / common / mm_sound_dbus.c
1
2 #include <gio/gio.h>
3 #include <stdlib.h>
4
5 #include <mm_error.h>
6 #include <mm_debug.h>
7
8 #include "../include/mm_sound_dbus.h"
9 #include "../include/mm_sound_intf.h"
10
11 #define INTERFACE_DBUS                  "org.freedesktop.DBus.Properties"
12 #define SIGNAL_PROP_CHANGED             "PropertiesChanged"
13 #define METHOD_GET                      "Get"
14 #define METHOD_SET                      "Set"
15
16 struct callback_data {
17         mm_sound_dbus_callback user_cb;
18         void *user_data;
19         mm_sound_dbus_userdata_free free_func;
20 };
21
22 struct dbus_path {
23         char *bus_name;
24         char *object;
25         char *interface;
26 };
27
28 const struct dbus_path g_paths[AUDIO_PROVIDER_MAX] = {
29         [AUDIO_PROVIDER_SOUND_SERVER] = {
30                 .bus_name = "org.tizen.SoundServer",
31                 .object = "/org/tizen/SoundServer1",
32                 .interface ="org.tizen.SoundServer1"
33         },
34         [AUDIO_PROVIDER_FOCUS_SERVER] = {
35                 .bus_name = "org.tizen.FocusServer",
36                 .object = "/org/tizen/FocusServer1",
37                 .interface = "org.tizen.FocusServer1"
38         },
39         [AUDIO_PROVIDER_DEVICE_MANAGER] = {
40                 .bus_name = "org.pulseaudio.Server",
41                 .object = "/org/pulseaudio/DeviceManager",
42                 .interface = "org.pulseaudio.DeviceManager"
43         },
44         [AUDIO_PROVIDER_STREAM_MANAGER] = {
45                 .bus_name = "org.pulseaudio.Server",
46                 .object = "/org/pulseaudio/StreamManager",
47                 .interface = "org.pulseaudio.StreamManager"
48         },
49         [AUDIO_PROVIDER_AUDIO_CLIENT] = {
50                 .bus_name = "org.tizen.AudioClient",
51                 .object = "/org/tizen/AudioClient1",
52                 .interface = "org.tizen.AudioClient1"
53         }
54 };
55
56 const mm_sound_dbus_method_info_t g_methods[AUDIO_METHOD_MAX] = {
57         [AUDIO_METHOD_TEST] = {
58                 .name = "MethodTest1",
59         },
60         [AUDIO_METHOD_PLAY_FILE_START] = {
61                 .name = "PlayFileStart",
62         },
63         [AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO] = {
64                 .name = "PlayFileStartWithStreamInfo",
65         },
66         [AUDIO_METHOD_PLAY_FILE_STOP] = {
67                 .name = "PlayFileStop",
68         },
69         [AUDIO_METHOD_PLAY_DTMF] = {
70                 .name = "PlayDTMF",
71         },
72         [AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO] = {
73                 .name = "PlayDTMFWithStreamInfo",
74         },
75         [AUDIO_METHOD_CLEAR_FOCUS] = {
76                 .name = "ClearFocus",
77         },
78         [AUDIO_METHOD_SET_VOLUME_LEVEL] = {
79                 .name = "SetVolumeLevel",
80         },
81         [AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST] = {
82                 .name = "GetConnectedDeviceList",
83         },
84         [AUDIO_METHOD_IS_STREAM_ON_DEVICE] = {
85                 .name = "IsStreamOnDevice",
86         },
87         [AUDIO_METHOD_GET_UNIQUE_ID] = {
88                 .name = "GetUniqueId",
89         },
90         [AUDIO_METHOD_REGISTER_FOCUS] = {
91                 .name = "RegisterFocus",
92         },
93         [AUDIO_METHOD_UNREGISTER_FOCUS] = {
94                 .name = "UnregisterFocus",
95         },
96         [AUDIO_METHOD_SET_FOCUS_REACQUISITION] = {
97                 .name = "SetFocusReacquisition",
98         },
99         [AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE] = {
100                 .name = "GetAcquiredFocusStreamType",
101         },
102         [AUDIO_METHOD_ACQUIRE_FOCUS] = {
103                 .name = "AcquireFocus",
104         },
105         [AUDIO_METHOD_RELEASE_FOCUS] = {
106                 .name = "ReleaseFocus",
107         },
108         [AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS] = {
109                 .name = "UpdateFocusStatusByFocusId",
110         },
111         [AUDIO_METHOD_WATCH_FOCUS] = {
112                 .name = "WatchFocus",
113         },
114         [AUDIO_METHOD_UNWATCH_FOCUS] = {
115                 .name = "UnwatchFocus",
116         },
117         [AUDIO_METHOD_SET_FILTER] = {
118                 .name = "SetFilter",
119         },
120         [AUDIO_METHOD_UNSET_FILTER] = {
121                 .name = "UnsetFilter",
122         },
123         [AUDIO_METHOD_CONTROL_FILTER] = {
124                 .name = "ControlFilter",
125         },
126 };
127
128 const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
129         [AUDIO_EVENT_TEST] = {
130                 .name = "SignalTest1",
131         },
132         [AUDIO_EVENT_PLAY_FILE_END] = {
133                 .name = "PlayFileEnd",
134         },
135         [AUDIO_EVENT_VOLUME_CHANGED] = {
136                 .name = "VolumeChanged",
137         },
138         [AUDIO_EVENT_DEVICE_CONNECTED] = {
139                 .name = "DeviceConnected",
140         },
141         [AUDIO_EVENT_DEVICE_INFO_CHANGED] = {
142                 .name = "DeviceInfoChanged",
143         },
144         [AUDIO_EVENT_DEVICE_STATE_CHANGED] = {
145                 .name = "DeviceStateChanged",
146         },
147         [AUDIO_EVENT_FOCUS_CHANGED] = {
148                 .name = "FocusChanged",
149         },
150         [AUDIO_EVENT_FOCUS_WATCH] = {
151                 .name = "FocusWatch",
152         },
153         [AUDIO_EVENT_EMERGENT_EXIT] = {
154                 .name = "EmergentExit",
155         },
156         [AUDIO_EVENT_CLIENT_SUBSCRIBED] = {
157                 .name = "ClientSubscribed",
158         },
159         [AUDIO_EVENT_CLIENT_HANDLED] = {
160                 .name = "ClientSignalHandled",
161         }
162 };
163
164 /* Only For error types which is currently being used in server-side */
165 static const GDBusErrorEntry mm_sound_error_entries[] =
166 {
167         {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
168         {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
169         {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
170         {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
171         {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
172         {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
173         {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
174         {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
175         {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
176         {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
177         {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
178         {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
179         {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
180         {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
181         {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
182         {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
183         {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
184         {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
185         {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
186 };
187
188
189 /******************************************************************************************
190                 Wrapper Functions of GDbus
191 ******************************************************************************************/
192
193 static int _parse_error_msg(char *full_err_msg, char **err_name, char **err_msg)
194 {
195         char *save_p, *domain, *_err_name, *_err_msg;
196
197         if (!(domain = strtok_r(full_err_msg, ":", &save_p))) {
198                 debug_error("get domain failed");
199                 return -1;
200         }
201         if (!(_err_name = strtok_r(NULL, ":", &save_p))) {
202                 debug_error("get err name failed");
203                 return -1;
204         }
205         if (!(_err_msg = strtok_r(NULL, ":", &save_p))) {
206                 debug_error("get err msg failed");
207                 return -1;
208         }
209
210         *err_name = _err_name;
211         *err_msg = _err_msg;
212
213         return 0;
214 }
215
216 static int _convert_error_name(const char *err_name)
217 {
218         int i = 0;
219
220         for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
221                 if (!strcmp(mm_sound_error_entries[i].dbus_error_name, err_name)) {
222                         return mm_sound_error_entries[i].error_code;
223                 }
224         }
225
226         return MM_ERROR_COMMON_UNKNOWN;
227 }
228
229 static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
230                                                         const char* method, GVariant* args, GVariant** result)
231 {
232         int ret = MM_ERROR_NONE;
233         GError *err = NULL;
234         GVariant* dbus_reply = NULL;
235
236         if (!conn || !object || !intf || !method) {
237                 debug_error("Invalid Argument");
238                 if (!conn)
239                         debug_error("conn null");
240                 if (!object)
241                         debug_error("object null");
242                 if (!intf)
243                         debug_error("intf null");
244                 if (!method)
245                         debug_error("method null");
246                 return MM_ERROR_INVALID_ARGUMENT;
247         }
248
249         debug_log("Dbus call with obj'%s' intf'%s' method'%s'", object, intf, method);
250
251         dbus_reply = g_dbus_connection_call_sync(conn, bus_name, object , intf,
252                              method, args ,
253                              NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err );
254
255         if (!dbus_reply) {
256                 char *err_name = NULL, *err_msg = NULL;
257                 debug_error("Method Call '%s.%s' Failed, %s", intf, method, err->message);
258
259                 if (_parse_error_msg(err->message,  &err_name, &err_msg) < 0) {
260                         debug_error("failed to parse error message");
261                         g_error_free(err);
262                         return MM_ERROR_SOUND_INTERNAL;
263                 }
264                 ret = _convert_error_name(err_name);
265                 g_error_free(err);
266         } else {
267                 debug_log("Method Call '%s.%s' Success", intf, method);
268         }
269
270         *result = dbus_reply;
271
272         return ret;
273 }
274
275 #if 0
276 static int _dbus_set_property(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
277                                                         const char* prop, GVariant* args, GVariant** result)
278 {
279         int ret = MM_ERROR_NONE;
280
281         if (!conn || !object || !intf || !prop) {
282                 debug_error("Invalid Argument");
283                 return MM_ERROR_INVALID_ARGUMENT;
284         }
285
286         debug_log("Dbus set property with obj'%s' intf'%s' prop'%s'", object, intf, prop);
287
288         if ((ret = _dbus_method_call(conn, bus_name, object, INTERFACE_DBUS, METHOD_SET,
289                                                                 g_variant_new("(ssv)", intf, prop, args), result)) != MM_ERROR_NONE) {
290                 debug_error("Dbus call for set property failed");
291         }
292
293         return ret;
294 }
295
296 static int _dbus_get_property(GDBusConnection *conn, const char* bus_name, const char* object_name,
297                                                         const char* intf_name, const char* prop, GVariant** result)
298 {
299         int ret = MM_ERROR_NONE;
300
301         if (!conn || !object_name || !intf_name || !prop) {
302                 debug_error("Invalid Argument");
303                 return MM_ERROR_INVALID_ARGUMENT;
304         }
305
306         debug_log("Dbus get property with obj'%s' intf'%s' prop'%s'", object_name, intf_name, prop);
307
308         if ((ret = _dbus_method_call(conn,
309                                        bus_name, object_name, INTERFACE_DBUS, METHOD_GET,
310                                        g_variant_new("(ss)", intf_name, prop), result)) != MM_ERROR_NONE) {
311                 debug_error("Dbus call for get property failed");
312         }
313
314         return ret;
315 }
316 #endif
317
318 static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name, const char* intf_name,
319                                         const char* signal_name, GDBusSignalCallback signal_cb, guint *subscribe_id, void* userdata, GDestroyNotify freefunc)
320 {
321         guint subs_id = 0;
322
323         if (!conn || !object_name || !intf_name || !signal_name || !signal_cb) {
324                 debug_error("Invalid Argument");
325                 return MM_ERROR_INVALID_ARGUMENT;
326         }
327
328         debug_log("Dbus subscirbe signal with Obj'%s' Intf'%s' sig'%s'", object_name, intf_name, signal_name);
329
330         subs_id = g_dbus_connection_signal_subscribe(conn, NULL, intf_name, signal_name, object_name,
331                                                                                                 NULL, G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, freefunc);
332
333         if (!subs_id) {
334                 debug_error ("g_dbus_connection_signal_subscribe() failed ");
335                 return MM_ERROR_SOUND_INTERNAL;
336         }
337         if (subscribe_id)
338                 *subscribe_id = subs_id;
339
340         return MM_ERROR_NONE;
341 }
342
343 static void _dbus_unsubscribe_signal(GDBusConnection *conn, guint subs_id)
344 {
345         if (!conn || !subs_id) {
346                 debug_error("Invalid Argument");
347                 return;
348         }
349
350         g_dbus_connection_signal_unsubscribe(conn, subs_id);
351 }
352
353 static GDBusConnection* _dbus_get_connection(GBusType bustype)
354 {
355         static GDBusConnection *conn_system = NULL;
356         static GDBusConnection *conn_session = NULL;
357         GError *err = NULL;
358
359         if (bustype == G_BUS_TYPE_SYSTEM) {
360                 if (conn_system) {
361                         debug_log("Already connected to system bus");
362                 } else {
363                         debug_log("Get new connection on system bus");
364                         if (!(conn_system = g_bus_get_sync(bustype, NULL, &err))) {
365                                 debug_error ("g_dbus_get_sync() error (%s)", err->message);
366                                 g_error_free(err);
367                         }
368                 }
369                 return conn_system;
370         } else if (bustype == G_BUS_TYPE_SESSION) {
371                 if (conn_session) {
372                         debug_log("Already connected to session bus");
373                 } else {
374                         debug_log("Get new connection on session bus");
375                         if (!(conn_session = g_bus_get_sync(bustype, NULL, &err))) {
376                                 debug_error ("g_dbus_get_sync() error (%s)", err->message);
377                                 g_error_free(err);
378                         }
379                 }
380                 return conn_session;
381         } else {
382                 debug_error("Invalid bus type");
383                 return NULL;
384         }
385
386 }
387
388 #if 0
389 static void _dbus_disconnect(GDBusConnection* conn)
390 {
391         debug_fenter ();
392         g_object_unref(conn);
393         debug_fleave ();
394 }
395 #endif
396
397 /******************************************************************************************
398                 Simple Functions For Communicate with Sound-Server
399 ******************************************************************************************/
400
401 EXPORT_API
402 int mm_sound_dbus_method_call_to(audio_provider_t provider, audio_method_t method_type, GVariant *args, GVariant **result)
403 {
404         int ret = MM_ERROR_NONE;
405         GDBusConnection *conn = NULL;
406
407         if (method_type < 0 || method_type >= AUDIO_METHOD_MAX) {
408                 debug_error("Invalid method type : %d", method_type);
409                 return MM_ERROR_INVALID_ARGUMENT;
410         }
411         if (provider < 0 || provider >= AUDIO_PROVIDER_MAX) {
412                 debug_error("Invalid provider : %d", provider);
413                 return MM_ERROR_INVALID_ARGUMENT;
414         }
415
416         if (!(conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
417                 debug_error("Get Dbus Connection Error");
418                 return MM_ERROR_SOUND_INTERNAL;
419         }
420
421         if ((ret = _dbus_method_call(conn, g_paths[provider].bus_name,
422                                       g_paths[provider].object,
423                                       g_paths[provider].interface,
424                                       g_methods[method_type].name,
425                                       args, result)) != MM_ERROR_NONE) {
426                 debug_error("Dbus Call on Client Error");
427         }
428
429         return ret;
430 }
431
432 /* This callback only transform signal-callback to dbus non-related form (mm_sound_dbus_callback) */
433 static void _dbus_signal_callback(GDBusConnection  *connection,
434                                      const gchar      *sender_name,
435                                      const gchar      *object_path,
436                                      const gchar      *interface_name,
437                                      const gchar      *signal_name,
438                                      GVariant         *params,
439                                      gpointer          userdata)
440 {
441         struct callback_data *cb_data = (struct callback_data*) userdata;
442
443         debug_log("Signal(%s.%s) Received , Let's call Wrapper-Callback", interface_name, signal_name);
444
445         if (!strcmp(signal_name, g_events[AUDIO_EVENT_VOLUME_CHANGED].name)) {
446                 (cb_data->user_cb)(AUDIO_EVENT_VOLUME_CHANGED, params, cb_data->user_data);
447         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_CONNECTED].name)) {
448                 (cb_data->user_cb)(AUDIO_EVENT_DEVICE_CONNECTED, params, cb_data->user_data);
449         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_INFO_CHANGED].name)) {
450                 (cb_data->user_cb)(AUDIO_EVENT_DEVICE_INFO_CHANGED, params, cb_data->user_data);
451         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_STATE_CHANGED].name)) {
452                 (cb_data->user_cb)(AUDIO_EVENT_DEVICE_STATE_CHANGED, params, cb_data->user_data);
453         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_CHANGED].name)) {
454                 (cb_data->user_cb)(AUDIO_EVENT_FOCUS_CHANGED, params, cb_data->user_data);
455         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_WATCH].name)) {
456                 (cb_data->user_cb)(AUDIO_EVENT_FOCUS_WATCH, params, cb_data->user_data);
457         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_PLAY_FILE_END].name)) {
458                 (cb_data->user_cb)(AUDIO_EVENT_PLAY_FILE_END, params, cb_data->user_data);
459         } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_EMERGENT_EXIT].name)) {
460                 (cb_data->user_cb)(AUDIO_EVENT_EMERGENT_EXIT, params, cb_data->user_data);
461         }
462 }
463
464 static void callback_data_free_func(gpointer data)
465 {
466         struct callback_data *cb_data = (struct callback_data *) data;
467
468         if (cb_data->free_func)
469                 cb_data->free_func(cb_data->user_data);
470         g_free(cb_data);
471 }
472
473 EXPORT_API
474 int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t event, mm_sound_dbus_callback callback, void *userdata, mm_sound_dbus_userdata_free freefunc, unsigned *subs_id)
475 {
476         GDBusConnection *conn = NULL;
477         guint _subs_id = 0;
478         struct callback_data *cb_data = NULL;
479
480         if (!callback) {
481                 debug_error("Callback is Null");
482                 return MM_ERROR_INVALID_ARGUMENT;
483         }
484
485         if (event < 0 || event >= AUDIO_EVENT_MAX) {
486                 debug_error("Wrong event Type : %d", event);
487                 return MM_ERROR_INVALID_ARGUMENT;
488         }
489
490         if (provider < 0 || provider >= AUDIO_PROVIDER_MAX) {
491                 debug_error("Invalid provider : %d", provider);
492                 return MM_ERROR_INVALID_ARGUMENT;
493         }
494
495         if (!(conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
496                 debug_error("Get Dbus Connection Error");
497                 return MM_ERROR_SOUND_INTERNAL;
498         }
499
500         if (!(cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)))) {
501                 debug_error("Allocate for callback data failed");
502                 return MM_ERROR_SOUND_INTERNAL;
503         }
504
505         cb_data->user_cb = callback;
506         cb_data->user_data = userdata;
507         cb_data->free_func = freefunc;
508
509         if (_dbus_subscribe_signal(conn, g_paths[provider].object, g_paths[provider].interface, g_events[event].name,
510                                                         _dbus_signal_callback, &_subs_id, cb_data, callback_data_free_func) != MM_ERROR_NONE) {
511                 debug_error("Dbus Subscribe on Client Error");
512                 goto fail;
513         }
514         if (subs_id)
515                 *subs_id = (unsigned int)_subs_id;
516
517         return MM_ERROR_NONE;
518
519 fail:
520         free(cb_data);
521         return MM_ERROR_SOUND_INTERNAL;
522 }
523
524 EXPORT_API
525 int mm_sound_dbus_signal_unsubscribe(unsigned int subs_id)
526 {
527         GDBusConnection *conn = NULL;
528
529         if (!(conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
530                 debug_error("Get Dbus Connection Error");
531                 return MM_ERROR_SOUND_INTERNAL;
532         }
533
534         _dbus_unsubscribe_signal(conn, (guint) subs_id);
535
536         return MM_ERROR_NONE;
537 }
538
539 EXPORT_API
540 int mm_sound_dbus_emit_signal(audio_provider_t provider, audio_event_t event, GVariant *param)
541 {
542         GDBusConnection *conn;
543         GError *err = NULL;
544         gboolean dbus_ret;
545
546         if (event < 0 || event >= AUDIO_EVENT_MAX) {
547                 debug_error ("emit signal failed, invalid argument, event_type(%d)", event);
548                 return MM_ERROR_INVALID_ARGUMENT;
549         }
550
551         if (!(conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
552                 debug_error("Get Dbus Connection Error");
553                 return MM_ERROR_SOUND_INTERNAL;
554         }
555
556         dbus_ret = g_dbus_connection_emit_signal (conn,
557                                                   NULL, g_paths[provider].object,
558                                                   g_paths[provider].interface, g_events[event].name,
559                                                   param, &err);
560         if (!dbus_ret) {
561                 debug_error ("g_dbus_connection_emit_signal() error (%s)", err->message);
562                 g_error_free(err);
563                 return MM_ERROR_SOUND_INTERNAL;
564         }
565         g_dbus_connection_flush_sync(conn, NULL, NULL);
566
567         debug_msg ("emit signal for [%s]  success", g_events[event].name);
568         return MM_ERROR_NONE;
569 }
570
571 EXPORT_API
572 int mm_sound_dbus_get_event_name(audio_event_t event, const char **event_name)
573 {
574         if (!event_name) {
575                 debug_error("Invalid Parameter, event_name NULL");
576                 return MM_ERROR_INVALID_ARGUMENT;
577         }
578         if (event < 0 || event >= AUDIO_EVENT_MAX) {
579                 debug_error("invalid event : %d", event);
580                 return MM_ERROR_INVALID_ARGUMENT;
581         }
582
583         *event_name = g_events[event].name;
584         return MM_ERROR_NONE;
585 }
586
587 EXPORT_API
588 int mm_sound_dbus_get_method_name(audio_method_t method, const char **method_name)
589 {
590         if (!method_name) {
591                 debug_error("Invalid Parameter, method_name NULL");
592                 return MM_ERROR_INVALID_ARGUMENT;
593         }
594         if (method < 0 || method >= AUDIO_METHOD_MAX) {
595                 debug_error("invalid method : %d", method);
596                 return MM_ERROR_INVALID_ARGUMENT;
597         }
598
599         *method_name = g_methods[method].name;
600         return MM_ERROR_NONE;
601 }