When compare address, ignoring the case of the characters
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-avrcp.c
index c4e6e0d..cd6c898 100644 (file)
@@ -56,7 +56,6 @@ static bt_player_settinngs_t player_status[] = {
        { STATUS_INVALID, "" }
 };
 
-static GDBusConnection *bt_gdbus_conn = NULL;
 static guint avrcp_reg_id = 0;
 
 /* Introspection data exposed from bt-service */
@@ -247,6 +246,7 @@ static GDBusNodeInfo *__bt_avrcp_create_method_node_info
 int _bt_register_media_player(void)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        gchar *adapter_path;
        gboolean shuffle_status;
        gchar *path;
@@ -263,17 +263,15 @@ int _bt_register_media_player(void)
        player_settings.position = 0;
        shuffle_status = FALSE;
 
-       if (bt_gdbus_conn == NULL) {
-               bt_gdbus_conn = _bt_get_system_gconn();
-               retv_if(bt_gdbus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-       }
+       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,
@@ -289,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(bt_gdbus_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);
@@ -348,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;
        }
@@ -358,6 +361,7 @@ 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;
@@ -365,15 +369,21 @@ int _bt_unregister_media_player(void)
        gchar *path;
        int result = BLUETOOTH_ERROR_NONE;
 
-       retv_if(bt_gdbus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
        adapter_path = _bt_get_adapter_path();
        if (adapter_path == NULL) {
                result = BLUETOOTH_ERROR_INTERNAL;
                goto FAIL;
        }
 
-       proxy =  g_dbus_proxy_new_sync(bt_gdbus_conn,
+       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);
@@ -413,11 +423,6 @@ int _bt_unregister_media_player(void)
 FAIL:
        __bt_avrcp_unregister_object_path();
 
-       if (bt_gdbus_conn) {
-               g_object_unref(bt_gdbus_conn);
-               bt_gdbus_conn = NULL;
-       }
-
        BT_DBG("-");
        return result;
 }
@@ -426,7 +431,7 @@ 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;
@@ -435,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}"));
@@ -469,7 +474,7 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
        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})",
@@ -494,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");
@@ -521,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");
@@ -530,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");
@@ -539,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");
@@ -573,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");