Adds checking dbus error messages
[platform/core/multimedia/libmm-sound.git] / common / mm_sound_dbus.c
index 72c6b34..010b9e8 100644 (file)
@@ -8,11 +8,6 @@
 #include "../include/mm_sound_dbus.h"
 #include "../include/mm_sound_intf.h"
 
-#define INTERFACE_DBUS                 "org.freedesktop.DBus.Properties"
-#define SIGNAL_PROP_CHANGED             "PropertiesChanged"
-#define METHOD_GET                     "Get"
-#define METHOD_SET                     "Set"
-
 struct callback_data {
        mm_sound_dbus_callback user_cb;
        void *user_data;
@@ -25,11 +20,11 @@ struct dbus_path {
        char *interface;
 };
 
-const struct dbus_path g_paths[AUDIO_PROVIDER_MAX] = {
+static const struct dbus_path g_paths[AUDIO_PROVIDER_MAX] = {
        [AUDIO_PROVIDER_SOUND_SERVER] = {
                .bus_name = "org.tizen.SoundServer",
                .object = "/org/tizen/SoundServer1",
-               .interface ="org.tizen.SoundServer1"
+               .interface = "org.tizen.SoundServer1"
        },
        [AUDIO_PROVIDER_FOCUS_SERVER] = {
                .bus_name = "org.tizen.FocusServer",
@@ -50,51 +45,41 @@ const struct dbus_path g_paths[AUDIO_PROVIDER_MAX] = {
                .bus_name = "org.tizen.AudioClient",
                .object = "/org/tizen/AudioClient1",
                .interface = "org.tizen.AudioClient1"
+       },
+       [AUDIO_PROVIDER_SOUND_PLAYER] = {
+               .bus_name = "org.pulseaudio.Server",
+               .object = "/org/pulseaudio/SoundPlayer",
+               .interface = "org.pulseaudio.SoundPlayer"
        }
 };
 
-const mm_sound_dbus_method_info_t g_methods[AUDIO_METHOD_MAX] = {
+static const mm_sound_dbus_method_info_t g_methods[AUDIO_METHOD_MAX] = {
        [AUDIO_METHOD_TEST] = {
                .name = "MethodTest1",
        },
-       [AUDIO_METHOD_PLAY_FILE_START] = {
-               .name = "PlayFileStart",
-       },
-       [AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO] = {
-               .name = "PlayFileStartWithStreamInfo",
-       },
-       [AUDIO_METHOD_PLAY_FILE_STOP] = {
-               .name = "PlayFileStop",
+       [AUDIO_METHOD_SOUND_PLAY] = {
+               .name = "SoundPlay",
        },
-       [AUDIO_METHOD_PLAY_DTMF] = {
-               .name = "PlayDTMF",
+       [AUDIO_METHOD_SOUND_STOP] = {
+               .name = "SoundStop",
        },
        [AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO] = {
                .name = "PlayDTMFWithStreamInfo",
        },
-       [AUDIO_METHOD_CLEAR_FOCUS] = {
-               .name = "ClearFocus",
-       },
        [AUDIO_METHOD_SET_VOLUME_LEVEL] = {
                .name = "SetVolumeLevel",
        },
+       [AUDIO_METHOD_SET_MUTE] = {
+               .name = "SetVolumeMute",
+       },
        [AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST] = {
                .name = "GetConnectedDeviceList",
        },
-       [AUDIO_METHOD_GET_UNIQUE_ID] = {
-               .name = "GetUniqueId",
-       },
-       [AUDIO_METHOD_REGISTER_FOCUS] = {
-               .name = "RegisterFocus",
-       },
-       [AUDIO_METHOD_UNREGISTER_FOCUS] = {
-               .name = "UnregisterFocus",
+       [AUDIO_METHOD_GET_DEVICE_BY_ID] = {
+               .name = "GetDeviceById",
        },
-       [AUDIO_METHOD_SET_FOCUS_REACQUISITION] = {
-               .name = "SetFocusReacquisition",
-       },
-       [AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE] = {
-               .name = "GetAcquiredFocusStreamType",
+       [AUDIO_METHOD_IS_STREAM_ON_DEVICE] = {
+               .name = "IsStreamOnDevice",
        },
        [AUDIO_METHOD_ACQUIRE_FOCUS] = {
                .name = "AcquireFocus",
@@ -102,20 +87,26 @@ const mm_sound_dbus_method_info_t g_methods[AUDIO_METHOD_MAX] = {
        [AUDIO_METHOD_RELEASE_FOCUS] = {
                .name = "ReleaseFocus",
        },
-       [AUDIO_METHOD_WATCH_FOCUS] = {
-               .name = "WatchFocus",
+       [AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS] = {
+               .name = "UpdateFocusStatusByFocusId",
+       },
+       [AUDIO_METHOD_SET_FILTER] = {
+               .name = "SetFilter",
+       },
+       [AUDIO_METHOD_UNSET_FILTER] = {
+               .name = "UnsetFilter",
        },
-       [AUDIO_METHOD_UNWATCH_FOCUS] = {
-               .name = "UnwatchFocus",
+       [AUDIO_METHOD_CONTROL_FILTER] = {
+               .name = "ControlFilter",
        },
 };
 
-const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
+static const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
        [AUDIO_EVENT_TEST] = {
                .name = "SignalTest1",
        },
-       [AUDIO_EVENT_PLAY_FILE_END] = {
-               .name = "PlayFileEnd",
+       [AUDIO_EVENT_SOUND_PLAY_EOS] = {
+               .name = "EOS",
        },
        [AUDIO_EVENT_VOLUME_CHANGED] = {
                .name = "VolumeChanged",
@@ -129,26 +120,28 @@ const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
        [AUDIO_EVENT_DEVICE_STATE_CHANGED] = {
                .name = "DeviceStateChanged",
        },
+       [AUDIO_EVENT_DEVICE_RUNNING_CHANGED] = {
+               .name = "DeviceRunningChanged",
+       },
        [AUDIO_EVENT_FOCUS_CHANGED] = {
                .name = "FocusChanged",
        },
        [AUDIO_EVENT_FOCUS_WATCH] = {
                .name = "FocusWatch",
        },
-       [AUDIO_EVENT_EMERGENT_EXIT] = {
-               .name = "EmergentExit",
-       },
        [AUDIO_EVENT_CLIENT_SUBSCRIBED] = {
                .name = "ClientSubscribed",
        },
        [AUDIO_EVENT_CLIENT_HANDLED] = {
                .name = "ClientSignalHandled",
+       },
+       [AUDIO_EVENT_DUCKING_STATE_CHANGED] = {
+               .name = "DuckingStateChanged",
        }
 };
 
 /* Only For error types which is currently being used in server-side */
-static const GDBusErrorEntry mm_sound_error_entries[] =
-{
+static const GDBusErrorEntry mm_sound_error_entries[] = {
        {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
        {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
        {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
@@ -168,6 +161,7 @@ static const GDBusErrorEntry mm_sound_error_entries[] =
        {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
        {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
        {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
+       {MM_ERROR_SOUND_PERMISSION_DENIED, "org.freedesktop.DBus.Error.AccessDenied"},
 };
 
 
@@ -175,48 +169,27 @@ static const GDBusErrorEntry mm_sound_error_entries[] =
                Wrapper Functions of GDbus
 ******************************************************************************************/
 
-static int _parse_error_msg(char *full_err_msg, char **err_name, char **err_msg)
+static int _convert_error_name(const char *err_msg)
 {
-       char *save_p, *domain, *_err_name, *_err_msg;
-
-       if (!(domain = strtok_r(full_err_msg, ":", &save_p))) {
-               debug_error("get domain failed");
-               return -1;
-       }
-       if (!(_err_name = strtok_r(NULL, ":", &save_p))) {
-               debug_error("get err name failed");
-               return -1;
-       }
-       if (!(_err_msg = strtok_r(NULL, ":", &save_p))) {
-               debug_error("get err msg failed");
-               return -1;
-       }
-
-       *err_name = _err_name;
-       *err_msg = _err_msg;
-
-       return 0;
-}
+       int i;
 
-static int _convert_error_name(const char *err_name)
-{
-       int i = 0;
+       if (!err_msg)
+               return MM_ERROR_SOUND_INTERNAL;
 
        for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
-               if (!strcmp(mm_sound_error_entries[i].dbus_error_name, err_name)) {
+               if (strstr(err_msg, mm_sound_error_entries[i].dbus_error_name))
                        return mm_sound_error_entries[i].error_code;
-               }
        }
 
        return MM_ERROR_COMMON_UNKNOWN;
 }
 
-static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
-                                                       const char* method, GVariant* args, GVariant** result)
+static int _dbus_method_call(GDBusConnection *conn, const char *bus_name, const char *object, const char *intf,
+                                                       const char *method, GVariant *args, GVariant **result)
 {
        int ret = MM_ERROR_NONE;
        GError *err = NULL;
-       GVariantdbus_reply = NULL;
+       GVariant *dbus_reply = NULL;
 
        if (!conn || !object || !intf || !method) {
                debug_error("Invalid Argument");
@@ -228,79 +201,36 @@ static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const
                        debug_error("intf null");
                if (!method)
                        debug_error("method null");
+               g_variant_unref(args);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
        debug_log("Dbus call with obj'%s' intf'%s' method'%s'", object, intf, method);
 
        dbus_reply = g_dbus_connection_call_sync(conn, bus_name, object , intf,
-                            method, args ,
-                            NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err );
+                                                                                       method, args ,
+                                                                                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
 
-       if (!dbus_reply) {
-               char *err_name = NULL, *err_msg = NULL;
-               debug_log("Method Call '%s.%s' Failed, %s", intf, method, err->message);
+       if (!dbus_reply || err) {
+               debug_error("Method Call '%s.%s' Failed, %s", intf, method, err ? err->message : NULL);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               if (err)
+                       ret = _convert_error_name(err->message);
 
-               if (_parse_error_msg(err->message,  &err_name, &err_msg) < 0) {
-                       debug_error("failed to parse error message");
-                       g_error_free(err);
-                       return MM_ERROR_SOUND_INTERNAL;
-               }
-               ret = _convert_error_name(err_name);
                g_error_free(err);
+       } else {
+               debug_log("Method Call '%s.%s' Success", intf, method);
        }
 
-       debug_log("Method Call '%s.%s' Success", intf, method);
-       *result = dbus_reply;
-
-       return ret;
-}
-
-#if 0
-static int _dbus_set_property(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
-                                                       const char* prop, GVariant* args, GVariant** result)
-{
-       int ret = MM_ERROR_NONE;
-
-       if (!conn || !object || !intf || !prop) {
-               debug_error("Invalid Argument");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       debug_log("Dbus set property with obj'%s' intf'%s' prop'%s'", object, intf, prop);
-
-       if ((ret = _dbus_method_call(conn, bus_name, object, INTERFACE_DBUS, METHOD_SET,
-                                                               g_variant_new("(ssv)", intf, prop, args), result)) != MM_ERROR_NONE) {
-               debug_error("Dbus call for set property failed");
-       }
-
-       return ret;
-}
-
-static int _dbus_get_property(GDBusConnection *conn, const char* bus_name, const char* object_name,
-                                                       const char* intf_name, const char* prop, GVariant** result)
-{
-       int ret = MM_ERROR_NONE;
-
-       if (!conn || !object_name || !intf_name || !prop) {
-               debug_error("Invalid Argument");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       debug_log("Dbus get property with obj'%s' intf'%s' prop'%s'", object_name, intf_name, prop);
-
-       if ((ret = _dbus_method_call(conn,
-                                      bus_name, object_name, INTERFACE_DBUS, METHOD_GET,
-                                      g_variant_new("(ss)", intf_name, prop), result)) != MM_ERROR_NONE) {
-               debug_error("Dbus call for get property failed");
-       }
+       if (result)
+               *result = dbus_reply;
 
        return ret;
 }
-#endif
 
-static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name, const char* intf_name,
-                                       const char* signal_name, GDBusSignalCallback signal_cb, guint *subscribe_id, void* userdata, GDestroyNotify freefunc)
+static int _dbus_subscribe_signal(GDBusConnection *conn, const char *object_name, const char *intf_name,
+                                                               const char *signal_name, GDBusSignalCallback signal_cb, guint *subscribe_id,
+                                                               void *userdata, GDestroyNotify freefunc)
 {
        guint subs_id = 0;
 
@@ -311,11 +241,11 @@ static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name
 
        debug_log("Dbus subscirbe signal with Obj'%s' Intf'%s' sig'%s'", object_name, intf_name, signal_name);
 
-       subs_id = g_dbus_connection_signal_subscribe(conn, NULL, intf_name, signal_name, object_name, \
-                        NULL , G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, NULL );
+       subs_id = g_dbus_connection_signal_subscribe(conn, NULL, intf_name, signal_name, object_name,
+                                                                                               NULL, G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, freefunc);
 
        if (!subs_id) {
-               debug_error ("g_dbus_connection_signal_subscribe() failed ");
+               debug_error("g_dbus_connection_signal_subscribe() failed ");
                return MM_ERROR_SOUND_INTERNAL;
        }
        if (subscribe_id)
@@ -334,7 +264,7 @@ static void _dbus_unsubscribe_signal(GDBusConnection *conn, guint subs_id)
        g_dbus_connection_signal_unsubscribe(conn, subs_id);
 }
 
-static GDBusConnection* _dbus_get_connection(GBusType bustype)
+static GDBusConnection * _dbus_get_connection(GBusType bustype)
 {
        static GDBusConnection *conn_system = NULL;
        static GDBusConnection *conn_session = NULL;
@@ -342,42 +272,51 @@ static GDBusConnection* _dbus_get_connection(GBusType bustype)
 
        if (bustype == G_BUS_TYPE_SYSTEM) {
                if (conn_system) {
+#ifndef TIZEN_TV
                        debug_log("Already connected to system bus");
+#endif
                } else {
+#ifndef TIZEN_TV
                        debug_log("Get new connection on system bus");
-                       if (!(conn_system = g_bus_get_sync(bustype, NULL, &err))) {
-                               debug_error ("g_dbus_get_sync() error (%s)", err->message);
+#endif
+                       conn_system = g_bus_get_sync(bustype, NULL, &err);
+                       if (!conn_system || err) {
+#ifndef TIZEN_TV
+                               debug_error("g_dbus_get_sync() error (%s)", err ? err->message : NULL);
+#endif
                                g_error_free(err);
+                               return NULL;
                        }
                }
                return conn_system;
        } else if (bustype == G_BUS_TYPE_SESSION) {
                if (conn_session) {
+#ifndef TIZEN_TV
                        debug_log("Already connected to session bus");
+#endif
                } else {
+#ifndef TIZEN_TV
                        debug_log("Get new connection on session bus");
-                       if (!(conn_session = g_bus_get_sync(bustype, NULL, &err))) {
-                               debug_error ("g_dbus_get_sync() error (%s)", err->message);
+#endif
+                       conn_session = g_bus_get_sync(bustype, NULL, &err);
+                       if (!conn_session || err) {
+#ifndef TIZEN_TV
+                               debug_error("g_dbus_get_sync() error (%s)", err ? err->message : NULL);
+#endif
                                g_error_free(err);
+                               return NULL;
                        }
                }
                return conn_session;
        } else {
+#ifndef TIZEN_TV
                debug_error("Invalid bus type");
+#endif
                return NULL;
        }
 
 }
 
-#if 0
-static void _dbus_disconnect(GDBusConnection* conn)
-{
-       debug_fenter ();
-       g_object_unref(conn);
-       debug_fleave ();
-}
-#endif
-
 /******************************************************************************************
                Simple Functions For Communicate with Sound-Server
 ******************************************************************************************/
@@ -388,25 +327,28 @@ int mm_sound_dbus_method_call_to(audio_provider_t provider, audio_method_t metho
        int ret = MM_ERROR_NONE;
        GDBusConnection *conn = NULL;
 
-       if (method_type < 0 || method_type >= AUDIO_METHOD_MAX) {
+       if (method_type >= AUDIO_METHOD_MAX) {
                debug_error("Invalid method type : %d", method_type);
+               g_variant_unref(args);
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (provider < 0 || provider >= AUDIO_PROVIDER_MAX) {
+       if (provider >= AUDIO_PROVIDER_MAX) {
                debug_error("Invalid provider : %d", provider);
+               g_variant_unref(args);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
        if (!(conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
                debug_error("Get Dbus Connection Error");
+               g_variant_unref(args);
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       if((ret = _dbus_method_call(conn, g_paths[provider].bus_name,
-                                     g_paths[provider].object,
-                                     g_paths[provider].interface,
-                                     g_methods[method_type].name,
-                                     args, result)) != MM_ERROR_NONE) {
+       if ((ret = _dbus_method_call(conn, g_paths[provider].bus_name,
+                                                               g_paths[provider].object,
+                                                               g_paths[provider].interface,
+                                                               g_methods[method_type].name,
+                                                               args, result)) != MM_ERROR_NONE) {
                debug_error("Dbus Call on Client Error");
        }
 
@@ -414,40 +356,41 @@ int mm_sound_dbus_method_call_to(audio_provider_t provider, audio_method_t metho
 }
 
 /* This callback only transform signal-callback to dbus non-related form (mm_sound_dbus_callback) */
-static void _dbus_signal_callback(GDBusConnection  *connection,
-                                     const gchar      *sender_name,
-                                     const gchar      *object_path,
-                                     const gchar      *interface_name,
-                                     const gchar      *signal_name,
-                                     GVariant         *params,
-                                     gpointer          userdata)
+static void _dbus_signal_callback(GDBusConnection *connection,
+                                                               const gchar *sender_name,
+                                                               const gchar *object_path,
+                                                               const gchar *interface_name,
+                                                               const gchar *signal_name,
+                                                               GVariant *params,
+                                                               gpointer userdata)
 {
-       struct callback_data *cb_data = (struct callback_data*) userdata;
+       struct callback_data *cb_data = (struct callback_data *)userdata;
 
-       debug_log("Signal(%s.%s) Received , Let's call Wrapper-Callback", interface_name, signal_name);
+       debug_log("Signal(%s.%s) Received, Let's call Wrapper-Callback", interface_name, signal_name);
 
-       if (!strcmp(signal_name, g_events[AUDIO_EVENT_VOLUME_CHANGED].name)) {
+       if (!strcmp(signal_name, g_events[AUDIO_EVENT_VOLUME_CHANGED].name))
                (cb_data->user_cb)(AUDIO_EVENT_VOLUME_CHANGED, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_CONNECTED].name)) {
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_CONNECTED].name))
                (cb_data->user_cb)(AUDIO_EVENT_DEVICE_CONNECTED, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_INFO_CHANGED].name)) {
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_INFO_CHANGED].name))
                (cb_data->user_cb)(AUDIO_EVENT_DEVICE_INFO_CHANGED, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_STATE_CHANGED].name)) {
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_STATE_CHANGED].name))
                (cb_data->user_cb)(AUDIO_EVENT_DEVICE_STATE_CHANGED, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_CHANGED].name)) {
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_CHANGED].name))
                (cb_data->user_cb)(AUDIO_EVENT_FOCUS_CHANGED, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_WATCH].name)) {
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_WATCH].name))
                (cb_data->user_cb)(AUDIO_EVENT_FOCUS_WATCH, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_PLAY_FILE_END].name)) {
-               (cb_data->user_cb)(AUDIO_EVENT_PLAY_FILE_END, params, cb_data->user_data);
-       } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_EMERGENT_EXIT].name)) {
-               (cb_data->user_cb)(AUDIO_EVENT_EMERGENT_EXIT, params, cb_data->user_data);
-       }
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_SOUND_PLAY_EOS].name))
+               (cb_data->user_cb)(AUDIO_EVENT_SOUND_PLAY_EOS, params, cb_data->user_data);
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_RUNNING_CHANGED].name))
+               (cb_data->user_cb)(AUDIO_EVENT_DEVICE_RUNNING_CHANGED, params, cb_data->user_data);
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DUCKING_STATE_CHANGED].name))
+               (cb_data->user_cb)(AUDIO_EVENT_DUCKING_STATE_CHANGED, params, cb_data->user_data);
 }
 
 static void callback_data_free_func(gpointer data)
 {
-       struct callback_data *cb_data = (struct callback_data *) data;
+       struct callback_data *cb_data = (struct callback_data *)data;
 
        if (cb_data->free_func)
                cb_data->free_func(cb_data->user_data);
@@ -455,7 +398,8 @@ static void callback_data_free_func(gpointer data)
 }
 
 EXPORT_API
-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)
+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)
 {
        GDBusConnection *conn = NULL;
        guint _subs_id = 0;
@@ -466,12 +410,12 @@ int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t e
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       if (event < 0 || event >= AUDIO_EVENT_MAX) {
+       if (event >= AUDIO_EVENT_MAX) {
                debug_error("Wrong event Type : %d", event);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       if (provider < 0 || provider >= AUDIO_PROVIDER_MAX) {
+       if (provider >= AUDIO_PROVIDER_MAX) {
                debug_error("Invalid provider : %d", provider);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -481,7 +425,7 @@ int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t e
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       if (!(cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)))) {
+       if (!(cb_data = (struct callback_data*)g_try_malloc0(sizeof(struct callback_data)))) {
                debug_error("Allocate for callback data failed");
                return MM_ERROR_SOUND_INTERNAL;
        }
@@ -490,7 +434,7 @@ int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t e
        cb_data->user_data = userdata;
        cb_data->free_func = freefunc;
 
-       if(_dbus_subscribe_signal(conn, g_paths[provider].object, g_paths[provider].interface, g_events[event].name,
+       if (_dbus_subscribe_signal(conn, g_paths[provider].object, g_paths[provider].interface, g_events[event].name,
                                                        _dbus_signal_callback, &_subs_id, cb_data, callback_data_free_func) != MM_ERROR_NONE) {
                debug_error("Dbus Subscribe on Client Error");
                goto fail;
@@ -501,7 +445,7 @@ int mm_sound_dbus_signal_subscribe_to(audio_provider_t provider, audio_event_t e
        return MM_ERROR_NONE;
 
 fail:
-       free(cb_data);
+       g_free(cb_data);
        return MM_ERROR_SOUND_INTERNAL;
 }
 
@@ -515,7 +459,7 @@ int mm_sound_dbus_signal_unsubscribe(unsigned int subs_id)
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       _dbus_unsubscribe_signal(conn, (guint) subs_id);
+       _dbus_unsubscribe_signal(conn, (guint)subs_id);
 
        return MM_ERROR_NONE;
 }
@@ -527,28 +471,36 @@ int mm_sound_dbus_emit_signal(audio_provider_t provider, audio_event_t event, GV
        GError *err = NULL;
        gboolean dbus_ret;
 
-       if (event < 0 || event >= AUDIO_EVENT_MAX) {
-               debug_error ("emit signal failed, invalid argument, event_type(%d)", event);
+       if (event >= AUDIO_EVENT_MAX) {
+#ifndef TIZEN_TV
+               debug_error("emit signal failed, invalid argument, event_type(%d)", event);
+#endif
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
        if (!(conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+#ifndef TIZEN_TV
                debug_error("Get Dbus Connection Error");
+#endif
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       dbus_ret = g_dbus_connection_emit_signal (conn,
+       dbus_ret = g_dbus_connection_emit_signal(conn,
                                                  NULL, g_paths[provider].object,
                                                  g_paths[provider].interface, g_events[event].name,
                                                  param, &err);
-       if (!dbus_ret) {
-               debug_error ("g_dbus_connection_emit_signal() error (%s)", err->message);
+       if (!dbus_ret || err) {
+#ifndef TIZEN_TV
+               debug_error("g_dbus_connection_emit_signal() error (%s)", err ? err->message : NULL);
+#endif
                g_error_free(err);
                return MM_ERROR_SOUND_INTERNAL;
        }
        g_dbus_connection_flush_sync(conn, NULL, NULL);
 
-       debug_msg ("emit signal for [%s]  success", g_events[event].name);
+#ifndef TIZEN_TV
+       debug_msg("emit signal for [%s] success", g_events[event].name);
+#endif
        return MM_ERROR_NONE;
 }
 
@@ -559,7 +511,7 @@ int mm_sound_dbus_get_event_name(audio_event_t event, const char **event_name)
                debug_error("Invalid Parameter, event_name NULL");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (event < 0 || event >= AUDIO_EVENT_MAX) {
+       if (event >= AUDIO_EVENT_MAX) {
                debug_error("invalid event : %d", event);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -575,7 +527,7 @@ int mm_sound_dbus_get_method_name(audio_method_t method, const char **method_nam
                debug_error("Invalid Parameter, method_name NULL");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (method < 0 || method >= AUDIO_METHOD_MAX) {
+       if (method >= AUDIO_METHOD_MAX) {
                debug_error("invalid method : %d", method);
                return MM_ERROR_INVALID_ARGUMENT;
        }