Add the sender name in signal subscribe function
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-avrcp.c
old mode 100755 (executable)
new mode 100644 (file)
index 61dfd1b..cd6c898
@@ -19,9 +19,7 @@
 #include <glib.h>
 #include <dlog.h>
 #include <string.h>
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
 #include <syspopup_caller.h>
-#endif
 #include <dbus/dbus.h>
 
 #include "bluetooth-api.h"
@@ -58,9 +56,7 @@ static bt_player_settinngs_t player_status[] = {
        { STATUS_INVALID, "" }
 };
 
-GDBusConnection *bt_gdbus_conn = NULL;
 static guint avrcp_reg_id = 0;
-static GDBusProxy *service_gproxy = NULL;
 
 /* Introspection data exposed from bt-service */
 static const gchar bt_avrcp_bluez_introspection_xml[] =
@@ -247,59 +243,13 @@ static GDBusNodeInfo *__bt_avrcp_create_method_node_info
        return node_info;
 }
 
-static GDBusProxy *__bt_avrcp_gdbus_init_service_proxy(void)
-{
-       BT_DBG("+");
-       GDBusProxy *proxy;
-       GError *err = NULL;
-       char *adapter_path;
-
-       if (bt_gdbus_conn == NULL)
-               bt_gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-
-       if (!bt_gdbus_conn) {
-               if (err) {
-                       BT_ERR("Unable to connect to gdbus: %s", err->message);
-                       g_clear_error(&err);
-               }
-               return NULL;
-       }
-
-       adapter_path = _bt_get_adapter_path();
-       retv_if(adapter_path == NULL, NULL);
-
-       proxy =  g_dbus_proxy_new_sync(bt_gdbus_conn,
-                       G_DBUS_PROXY_FLAGS_NONE, NULL,
-                       BT_BLUEZ_NAME, adapter_path,
-                       BT_MEDIA_INTERFACE, NULL, &err);
-       g_free(adapter_path);
-
-       if (!proxy) {
-               BT_ERR("Unable to create proxy");
-               if (err) {
-                       BT_ERR("Error: %s", err->message);
-                       g_clear_error(&err);
-               }
-               return NULL;
-       }
-
-       BT_DBG("-");;
-       return proxy;
-}
-
-static GDBusProxy *__bt_avrcp_gdbus_get_service_proxy(void)
-{
-       return (service_gproxy) ? service_gproxy :
-                       __bt_avrcp_gdbus_init_service_proxy();
-}
-
 int _bt_register_media_player(void)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        gchar *adapter_path;
        gboolean shuffle_status;
        gchar *path;
-       GDBusConnection *conn;
        GDBusNodeInfo *node_info;
        GDBusProxy *proxy;
        GVariantBuilder *builder;
@@ -313,16 +263,15 @@ int _bt_register_media_player(void)
        player_settings.position = 0;
        shuffle_status = FALSE;
 
-       conn = _bt_get_system_gconn();
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-       bt_gdbus_conn = conn;
+       g_conn = _bt_gdbus_get_system_gconn();
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        node_info = __bt_avrcp_create_method_node_info(
                                bt_avrcp_bluez_introspection_xml);
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
-       avrcp_reg_id = g_dbus_connection_register_object(bt_gdbus_conn,
+       avrcp_reg_id = g_dbus_connection_register_object(g_conn,
                                        BT_MEDIA_OBJECT_PATH,
                                        node_info->interfaces[0],
                                        &method_table,
@@ -338,7 +287,7 @@ int _bt_register_media_player(void)
        adapter_path = _bt_get_adapter_path();
        retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       proxy =  g_dbus_proxy_new_sync(conn,
+       proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        BT_BLUEZ_NAME, adapter_path,
                        BT_MEDIA_INTERFACE, NULL, &error);
@@ -397,8 +346,13 @@ int _bt_register_media_player(void)
 
 static void __bt_avrcp_unregister_object_path(void)
 {
+       GDBusConnection *g_conn;
+
+       g_conn = _bt_gdbus_get_system_gconn();
+       ret_if(g_conn == NULL);
+
        if (avrcp_reg_id > 0) {
-               g_dbus_connection_unregister_object(bt_gdbus_conn,
+               g_dbus_connection_unregister_object(g_conn,
                                                        avrcp_reg_id);
                avrcp_reg_id = 0;
        }
@@ -407,18 +361,43 @@ static void __bt_avrcp_unregister_object_path(void)
 int _bt_unregister_media_player(void)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *proxy;
+       gchar *adapter_path;
        GVariant *ret;
        GError *error = NULL;
-       GDBusConnection *conn;
        gchar *path;
+       int result = BLUETOOTH_ERROR_NONE;
 
-       conn = bt_gdbus_conn;
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       adapter_path = _bt_get_adapter_path();
+       if (adapter_path == NULL) {
+               result = BLUETOOTH_ERROR_INTERNAL;
+               goto FAIL;
+       }
 
-       proxy = __bt_avrcp_gdbus_get_service_proxy();
-       if (proxy == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
+       g_conn = _bt_gdbus_get_system_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("g_conn is NULL");
+               g_free(adapter_path);
+               result = BLUETOOTH_ERROR_INTERNAL;
+               goto FAIL;
+       }
+
+       proxy =  g_dbus_proxy_new_sync(g_conn,
+                       G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       BT_BLUEZ_NAME, adapter_path,
+                       BT_MEDIA_INTERFACE, NULL, &error);
+       g_free(adapter_path);
+
+       if (proxy == NULL) {
+               BT_ERR("Unable to create proxy");
+               if (error) {
+                       BT_ERR("Error: %s", error->message);
+                       g_clear_error(&error);
+               }
+               result = BLUETOOTH_ERROR_INTERNAL;
+               goto FAIL;
+       }
 
        path = g_strdup(BT_MEDIA_OBJECT_PATH);
        BT_DBG("path is [%s]", path);
@@ -428,6 +407,7 @@ int _bt_unregister_media_player(void)
                        G_DBUS_CALL_FLAGS_NONE, -1,
                        NULL, &error);
        g_free(path);
+       g_object_unref(proxy);
 
        if (ret == NULL) {
                BT_ERR("UnregisterPlayer failed");
@@ -436,24 +416,22 @@ int _bt_unregister_media_player(void)
                                        error->code, error->message);
                        g_clear_error(&error);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               result = BLUETOOTH_ERROR_INTERNAL;
        }
+       g_variant_unref(ret);
 
+FAIL:
        __bt_avrcp_unregister_object_path();
 
-       g_variant_unref(ret);
-       g_object_unref(bt_gdbus_conn);
-       bt_gdbus_conn = NULL;
-
        BT_DBG("-");
-       return BLUETOOTH_ERROR_NONE;
+       return result;
 }
 
 int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
 {
        BT_DBG("+");
        char *interface = BT_MEDIA_PLAYER_INTERFACE;
-       GDBusConnection *conn;
+       GDBusConnection *g_conn;
        GError *error = NULL;
        GVariantBuilder *builder = NULL;
        GVariantBuilder *inner_builder = NULL;
@@ -462,8 +440,8 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
 
        retv_if(meta_data == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = bt_gdbus_conn;
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       g_conn = _bt_gdbus_get_system_gconn();;
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
@@ -491,12 +469,12 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
                "xesam:trackNumber", g_variant_new_int32(meta_data->number));
 
        g_variant_builder_add(inner_builder, "{sv}",
-               "mpris:lenght", g_variant_new_int64(meta_data->duration));
+               "mpris:length", g_variant_new_int64(meta_data->duration));
 
        g_variant_builder_add(builder, "{sv}",
                "Metadata", g_variant_new("a{sv}", inner_builder));
 
-       ret = g_dbus_connection_emit_signal(conn, NULL, BT_MEDIA_OBJECT_PATH,
+       ret = g_dbus_connection_emit_signal(g_conn, NULL, BT_MEDIA_OBJECT_PATH,
                                DBUS_INTERFACE_PROPERTIES,
                                "PropertiesChanged",
                                g_variant_new("(sa{sv})",
@@ -521,20 +499,20 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
 int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties)
 {
        BT_DBG("+");
-       GDBusConnection *conn;
+       GDBusConnection *g_conn;
        int value;
        media_metadata_attributes_t meta_data;
        gboolean shuffle;
        GVariantBuilder *builder = NULL;
        GVariant *children[1];
 
-       conn = bt_gdbus_conn;
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       g_conn = _bt_gdbus_get_system_gconn();;
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        switch (type) {
        case REPEAT:
                value = properties->repeat;
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "LoopStatus",
                                g_variant_new_string(loopstatus_settings[value].property))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -548,7 +526,7 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                else
                        shuffle = TRUE;
 
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "Shuffle",
                                g_variant_new_boolean(shuffle))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -557,7 +535,7 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                break;
        case STATUS:
                value = properties->status;
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "PlaybackStatus",
                                g_variant_new_string(player_status[value].property))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -566,7 +544,7 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                break;
        case POSITION:
                value = properties->position;
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "Position",
                                g_variant_new_uint32(value))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -600,9 +578,9 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                                "xesam:trackNumber", g_variant_new_int32(meta_data.number));
 
                g_variant_builder_add(builder, "{sv}",
-                               "mpris:lenght", g_variant_new_int64(meta_data.duration));
+                               "mpris:length", g_variant_new_int64(meta_data.duration));
 
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "Metadata",
                                g_variant_new("a{sv}", builder))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");