Merge branch 'tizen' into tizen_5.5
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-proximity.c
index 8ab7689..55a75e4 100644 (file)
@@ -84,17 +84,19 @@ int bt_set_proximity_property(bluetooth_device_address_t *device_address,
 
        device_path = _bt_get_device_object_path(address);
 
-       if (device_path == NULL) {
+       if (device_path == NULL)
                return BLUETOOTH_ERROR_NOT_CONNECTED;
-       } else {
+       else
                BT_INFO("device_path is created[%s]", device_path);
-       }
 
        value_str = _bt_convert_alert_level_to_string(alert_level);
-       property_str =_bt_convert_property_to_string(property);
+       property_str = _bt_convert_property_to_string(property);
 
-       if (value_str == NULL || property_str == NULL)
+       if (value_str == NULL || property_str == NULL) {
+               g_free(property_str);
+               g_free(value_str);
                return BLUETOOTH_ERROR_INTERNAL;
+       }
 
        proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
                                                        NULL, BT_BLUEZ_NAME,
@@ -147,11 +149,10 @@ int bt_get_proximity_property(bluetooth_device_address_t *device_address,
 
        device_path = _bt_get_device_object_path(address);
 
-       if (device_path == NULL) {
+       if (device_path == NULL)
                return BLUETOOTH_ERROR_NOT_CONNECTED;
-       } else {
+       else
                BT_INFO("device_path is created[%s]", device_path);
-       }
 
        property_str = _bt_convert_property_to_string(property);
 
@@ -197,7 +198,6 @@ int bt_get_proximity_property(bluetooth_device_address_t *device_address,
        g_variant_unref(value);
        g_object_unref(proxy);
        g_free(property_str);
-       g_free(value_str);
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -224,11 +224,10 @@ int bt_get_proximity_supported_services(bluetooth_device_address_t *device_addre
 
        device_path = _bt_get_device_object_path(address);
 
-       if (device_path == NULL) {
+       if (device_path == NULL)
                return BLUETOOTH_ERROR_NOT_CONNECTED;
-       } else {
+       else
                BT_INFO("device_path is created[%s]", device_path);
-       }
 
        proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
                                                        NULL, BT_BLUEZ_NAME,
@@ -294,3 +293,89 @@ int bt_get_proximity_supported_services(bluetooth_device_address_t *device_addre
 
        return BLUETOOTH_ERROR_NONE;
 }
+
+int bt_register_proximity_reporter()
+{
+       GDBusProxy *proxy;
+
+       GDBusConnection *conn;
+       char *adapter_path = NULL;
+       GError *error = NULL;
+       GVariant *result = NULL;
+
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       adapter_path = _bt_get_adapter_path();
+       if (adapter_path == NULL) {
+               BT_ERR("Could not get adapter path\n");
+               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+       }
+
+       BT_INFO("Adapter path %s", adapter_path);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                                       NULL, BT_BLUEZ_NAME, adapter_path,
+                                       BT_PROXIMITY_REPORTER_INTERFACE, NULL, NULL);
+
+       g_free(adapter_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       result = g_dbus_proxy_call_sync(proxy, "RegisterProximity",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       if (result == NULL) {
+               if (error != NULL) {
+                       BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+                       g_error_free(error);
+               }
+               g_object_unref(proxy);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       g_object_unref(proxy);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int bt_unregister_proximity_reporter()
+{
+       GDBusProxy *proxy;
+
+       GDBusConnection *conn;
+       char *adapter_path = NULL;
+       GError *error = NULL;
+       GVariant *result = NULL;
+
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       adapter_path = _bt_get_adapter_path();
+       if (adapter_path == NULL) {
+               BT_ERR("Could not get adapter path\n");
+               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+       }
+
+       BT_INFO("Adapter path %s", adapter_path);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                                       NULL, BT_BLUEZ_NAME, adapter_path,
+                                       BT_PROXIMITY_REPORTER_INTERFACE, NULL, NULL);
+
+       g_free(adapter_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       result = g_dbus_proxy_call_sync(proxy, "UnregisterProximity",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       if (result == NULL) {
+               if (error != NULL) {
+                       BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+                       g_error_free(error);
+               }
+               g_object_unref(proxy);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       g_object_unref(proxy);
+
+       return BLUETOOTH_ERROR_NONE;
+}