Add bt-driver-insmod.service trigger logic
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-proximity.c
index f78e301..dadf5e4 100644 (file)
@@ -30,9 +30,7 @@
 #include "bt-service-device.h"
 #include "bt-service-proximity.h"
 
-GSList *reporter_list = NULL;
-
-static char *_bt_convert_alert_level_to_string(int value)
+char *_bt_convert_alert_level_to_string(int value)
 {
        if (value == BT_PXP_ALERT_MILD)
                return g_strdup("mild");
@@ -42,7 +40,7 @@ static char *_bt_convert_alert_level_to_string(int value)
                return g_strdup("none");
 }
 
-static int _bt_convert_string_to_alert_level(const char *str)
+int _bt_convert_string_to_alert_level(const char *str)
 {
        if (g_strcmp0("high", str) == 0)
                return BT_PXP_ALERT_HIGH;
@@ -52,19 +50,7 @@ static int _bt_convert_string_to_alert_level(const char *str)
        return BT_PXP_ALERT_NONE;
 }
 
-static int _bt_convert_string_to_signal_level(const char *str)
-{
-       if (g_strcmp0("good", str) == 0)
-               return BT_PXP_SIGNAL_GOOD;
-       else if (g_strcmp0("regular", str) == 0)
-               return BT_PXP_SIGNAL_REGULAR;
-       else if (g_strcmp0("weak", str) == 0)
-               return BT_PXP_SIGNAL_WEAK;
-
-       return BT_PXP_SIGNAL_NONE;
-}
-
-static char *_bt_convert_property_to_string(int value)
+char *_bt_convert_property_to_string(int value)
 {
        if (value == BT_PXP_PROPERTY_LLS)
                return g_strdup("LinkLossAlertLevel");
@@ -76,20 +62,7 @@ static char *_bt_convert_property_to_string(int value)
        return NULL;
 }
 
-static char *_bt_proximity_reporter_find_from_list(const char *reporter_name)
-{
-       GSList *l;
-       char *reporter = NULL;
-
-       for (l = reporter_list; l != NULL; l = g_slist_next(l)) {
-               reporter = l->data;
-               if (reporter && g_strcmp0(reporter, reporter_name) == 0)
-                       return reporter;
-       }
-       return NULL;
-}
-
-int _bt_proximity_monitor_set_property(bluetooth_device_address_t *device_address,
+int bt_set_proximity_property(bluetooth_device_address_t *device_address,
                unsigned int property, int alert_level)
 {
        GDBusProxy *proxy;
@@ -110,9 +83,11 @@ int _bt_proximity_monitor_set_property(bluetooth_device_address_t *device_addres
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        device_path = _bt_get_device_object_path(address);
-       retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
 
-       BT_INFO("device_path is created[%s]", device_path);
+       if (device_path == NULL)
+               return BLUETOOTH_ERROR_NOT_CONNECTED;
+       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);
@@ -128,12 +103,7 @@ int _bt_proximity_monitor_set_property(bluetooth_device_address_t *device_addres
                                                        device_path, BT_PROPERTIES_INTERFACE,  NULL, NULL);
 
        g_free(device_path);
-
-       if (proxy == NULL) {
-               g_free(property_str);
-               g_free(value_str);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        ret = g_dbus_proxy_call_sync(proxy, "Set",
                                g_variant_new("(ssv)", BT_PROXIMITY_MONITOR_INTERFACE,  property_str, g_variant_new("s", value_str)),
@@ -156,8 +126,8 @@ int _bt_proximity_monitor_set_property(bluetooth_device_address_t *device_addres
        return BLUETOOTH_ERROR_NONE;
 }
 
-int _bt_proximity_monitor_get_property(bluetooth_device_address_t *device_address,
-               unsigned int property, int *level)
+int bt_get_proximity_property(bluetooth_device_address_t *device_address,
+               unsigned int property, int *alert_level)
 {
        GDBusProxy *proxy;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
@@ -178,9 +148,11 @@ int _bt_proximity_monitor_get_property(bluetooth_device_address_t *device_addres
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        device_path = _bt_get_device_object_path(address);
-       retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
 
-       BT_INFO("device_path is created[%s]", device_path);
+       if (device_path == NULL)
+               return BLUETOOTH_ERROR_NOT_CONNECTED;
+       else
+               BT_INFO("device_path is created[%s]", device_path);
 
        property_str = _bt_convert_property_to_string(property);
 
@@ -219,96 +191,19 @@ int _bt_proximity_monitor_get_property(bluetooth_device_address_t *device_addres
        }
 
        value_str = (char *)g_variant_get_string(tmp_value, NULL);
-       if (value_str) {
-               if (property != BT_PXP_PROPERTY_TX_POWER)
-                       *level = _bt_convert_string_to_alert_level(value_str);
-               else
-                       *level = _bt_convert_string_to_signal_level(value_str);
-       }
-
-       g_variant_unref(tmp_value);
-       g_variant_unref(value);
-       g_object_unref(proxy);
-       g_free(property_str);
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_proximity_reporter_get_property(bluetooth_device_address_t *device_address,
-               unsigned int property, int *level)
-{
-       GDBusProxy *proxy;
-       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       GDBusConnection *conn;
-       char *device_path = NULL;
-       GError *error = NULL;
-       GVariant *result = NULL;
-       GVariant *tmp_value;
-       GVariant *value;
-       char *value_str = NULL;
-       char *property_str = NULL;
-
-       BT_CHECK_PARAMETER(device_address, return);
-
-       conn = _bt_gdbus_get_system_gconn();
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       _bt_convert_addr_type_to_string(address, device_address->addr);
-
-       device_path = _bt_get_device_object_path(address);
-       retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
-
-       BT_INFO("device_path is created[%s]", device_path);
-
-       property_str = _bt_convert_property_to_string(property);
-
-       if (property_str == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                                       NULL, BT_BLUEZ_NAME,
-                                                       device_path, BT_PROPERTIES_INTERFACE,  NULL, NULL);
-
-       g_free(device_path);
-       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       result = g_dbus_proxy_call_sync(proxy, "GetAll",
-                       g_variant_new("(s)", BT_PROXIMITY_REPORTER_INTERFACE),
-                       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_variant_get(result , "(@a{sv})", &value);
-       g_variant_unref(result);
-
-       tmp_value = g_variant_lookup_value(value, property_str, G_VARIANT_TYPE_STRING);
-       if (tmp_value == NULL) {
-               g_object_unref(proxy);
-               g_variant_unref(value);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       value_str = (char *)g_variant_get_string(tmp_value, NULL);
        if (value_str)
-               *level = _bt_convert_string_to_alert_level(value_str);
+               *alert_level = _bt_convert_string_to_alert_level(value_str);
 
        g_variant_unref(tmp_value);
        g_variant_unref(value);
        g_object_unref(proxy);
        g_free(property_str);
+       g_free(value_str);
 
        return BLUETOOTH_ERROR_NONE;
 }
 
-int _bt_proximity_monitor_get_supported_services(bluetooth_device_address_t *device_address,
+int bt_get_proximity_supported_services(bluetooth_device_address_t *device_address,
                unsigned int *supported_services)
 {
        GDBusProxy *proxy;
@@ -329,9 +224,11 @@ int _bt_proximity_monitor_get_supported_services(bluetooth_device_address_t *dev
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        device_path = _bt_get_device_object_path(address);
-       retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
 
-       BT_INFO("device_path is created[%s]", device_path);
+       if (device_path == NULL)
+               return BLUETOOTH_ERROR_NOT_CONNECTED;
+       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,
@@ -398,22 +295,18 @@ int _bt_proximity_monitor_get_supported_services(bluetooth_device_address_t *dev
        return BLUETOOTH_ERROR_NONE;
 }
 
-int _bt_proximity_reporter_register(const char *sender)
+int bt_register_proximity_reporter()
 {
        GDBusProxy *proxy;
 
        GDBusConnection *conn;
        char *adapter_path = NULL;
-       char *reporter = NULL;
        GError *error = NULL;
        GVariant *result = NULL;
 
        conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       if (_bt_proximity_reporter_find_from_list(sender))
-               return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
-
        adapter_path = _bt_get_adapter_path();
        if (adapter_path == NULL) {
                BT_ERR("Could not get adapter path\n");
@@ -440,15 +333,12 @@ int _bt_proximity_reporter_register(const char *sender)
                g_object_unref(proxy);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       reporter = g_strdup(sender);
-       reporter_list = g_slist_append(reporter_list, reporter);
-
        g_object_unref(proxy);
 
        return BLUETOOTH_ERROR_NONE;
 }
 
-int _bt_proximity_reporter_unregister(const char *sender)
+int bt_unregister_proximity_reporter()
 {
        GDBusProxy *proxy;
 
@@ -456,15 +346,10 @@ int _bt_proximity_reporter_unregister(const char *sender)
        char *adapter_path = NULL;
        GError *error = NULL;
        GVariant *result = NULL;
-       char *reporter = NULL;
 
        conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       reporter = _bt_proximity_reporter_find_from_list(sender);
-       if (!reporter)
-               return BLUETOOTH_ERROR_NOT_INITIALIZED;
-
        adapter_path = _bt_get_adapter_path();
        if (adapter_path == NULL) {
                BT_ERR("Could not get adapter path\n");
@@ -491,18 +376,7 @@ int _bt_proximity_reporter_unregister(const char *sender)
                g_object_unref(proxy);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       reporter_list = g_slist_remove(reporter_list, reporter);
-       g_free(reporter);
-
        g_object_unref(proxy);
 
        return BLUETOOTH_ERROR_NONE;
 }
-
-void _bt_proximity_reporter_stop_by_terminated_process(const char *terminated_name)
-{
-       if (!_bt_proximity_reporter_find_from_list(terminated_name))
-               return;
-       BT_ERR("Stop Proximity Reporter by terminated process(%s).", terminated_name);
-       _bt_proximity_reporter_unregister(terminated_name);
-}