#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");
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;
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");
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;
_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);
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)),
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 };
_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);
}
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);
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;
_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,
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");
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;
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");
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);
-}