[PXP Reporter]: Add base code for register/unregister 14/94214/4
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Thu, 27 Oct 2016 12:43:30 +0000 (18:13 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 9 Nov 2016 08:25:25 +0000 (13:55 +0530)
1) Added base code for registering and unregistering
   proximity services.

Change-Id: I974a6858a2f5f68f6d6438522238284097bac3a4
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
bt-api/bt-event-handler.c
bt-api/bt-proximity.c
bt-service/bt-request-handler.c
bt-service/bt-service-event-receiver.c
bt-service/bt-service-event-sender.c
bt-service/bt-service-proximity.c
bt-service/include/bt-service-common.h
bt-service/include/bt-service-proximity.h
include/bluetooth-api.h
include/bt-internal-types.h

index f143dce..993eea4 100644 (file)
@@ -1150,6 +1150,24 @@ void __bt_device_event_filter(GDBusConnection *connection,
 
                _bt_common_event_cb(BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED,
                                result, &params, event_info->cb, event_info->user_data);
+       } else if (strcasecmp(signal_name, BT_PXP_PROPERTY_CHANGED) == 0) {
+               const char *address = NULL;
+               bluetooth_device_address_t dev_address = { {0} };
+               int role, type, level;
+               bt_pxp_property_changed_params_t params;
+
+               BT_DBG("BT_PXP_PROPERTY_CHANGED");
+
+               g_variant_get(parameters, "(isiii)", &result, &address, &role, &type, &level);
+
+               _bt_convert_addr_string_to_type(dev_address.addr, address);
+               memcpy(&params.device_address, &dev_address, BLUETOOTH_ADDRESS_LENGTH);
+               params.role = role;
+               params.service_type = type;
+               params.alert_lvl = level;
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+                               result, &params, event_info->cb, event_info->user_data);
        }
 }
 
index 5e1f71e..6832e3f 100644 (file)
@@ -108,3 +108,39 @@ BT_EXPORT_API int bluetooth_get_proximity_supported_services(const bluetooth_dev
 
        return result;
 }
+
+BT_EXPORT_API int bluetooth_register_proximity_reporter()
+{
+       int result = BLUETOOTH_ERROR_INTERNAL;
+
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       BT_DBG("");
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_REGISTER_REPORTER,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_unregister_proximity_reporter()
+{
+       int result = BLUETOOTH_ERROR_INTERNAL;
+
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       BT_DBG("");
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_UNREGISTER_REPORTER,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
index 35f2ad6..e7336e4 100644 (file)
@@ -2154,6 +2154,14 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       case BT_PXP_REGISTER_REPORTER: {
+               result = bt_register_proximity_reporter();
+               break;
+       }
+       case BT_PXP_UNREGISTER_REPORTER: {
+               result = bt_unregister_proximity_reporter();
+               break;
+       }
        default:
                result = BLUETOOTH_ERROR_INTERNAL;
                break;
@@ -2863,6 +2871,8 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_PXP_SET_PROPERTY:
        case BT_PXP_GET_PROPERTY:
        case BT_PXP_GET_SUPPORTED_SERIVCES:
+       case BT_PXP_REGISTER_REPORTER:
+       case BT_PXP_UNREGISTER_REPORTER:
        ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
                                BT_PRIVILEGE_PLATFORM);
 
index 2058084..ff416f5 100644 (file)
@@ -39,6 +39,7 @@
 #include "bt-service-headset-connection.h"
 #include "bt-service-avrcp-controller.h"
 #include "bt-service-hid.h"
+#include "bt-service-proximity.h"
 
 #include "bt-service-opp-client.h"
 
@@ -1280,6 +1281,70 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path)
        BT_DBG("-");
 }
 
+int get_alert_level_enum(const char *alert)
+{
+       int lvl = -1;
+
+       if (strcmp(alert, "none") == 0)
+               lvl = BT_PXP_ALERT_NONE;
+       else if (strcmp(alert, "mild") == 0)
+               lvl = BT_PXP_ALERT_MILD;
+       else if (strcmp(alert, "high") == 0)
+               lvl = BT_PXP_ALERT_HIGH;
+
+       return lvl;
+}
+
+static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       int service_type;
+       int alert_lvl;
+       GVariantIter value_iter;
+       char *property = NULL;
+       char *address;
+       GVariant *val = NULL;
+       GVariant *child = NULL;
+       GVariant *param = NULL;
+       g_variant_iter_init(&value_iter, msg);
+
+       BT_DBG("+");
+       while ((child = g_variant_iter_next_value(&value_iter))) {
+               g_variant_get(child, "{sv}", &property, &val);
+               BT_INFO("Property %s", property);
+
+               if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
+                       (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
+                       char *alert_str = NULL;
+
+                       address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+                       _bt_convert_device_path_to_address(path, address);
+
+                       if (strcasecmp(property, "LinkLossAlertLevel") == 0)
+                               service_type = BT_PXP_PROPERTY_LLS;
+                       else
+                               service_type = BT_PXP_PROPERTY_IAS;
+
+                       g_variant_get(val, "s", &alert_str);
+                       alert_lvl = get_alert_level_enum(alert_str);
+
+                       param = g_variant_new("(isiii)", result, address,
+                                                               role, service_type, alert_lvl);
+
+                       /* Send event to application */
+                       _bt_send_event(BT_DEVICE_EVENT,
+                                       BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+                                       param);
+                       g_free(address);
+                       g_free(alert_str);
+               }
+               g_free(property);
+               g_variant_unref(child);
+               g_variant_unref(val);
+       }
+       BT_DBG("-");
+}
+
 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
 {
        char *interface_name = NULL;
@@ -1309,6 +1374,10 @@ void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
        } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
                __bt_gatt_char_property_changed_event(val,
                                        object_path);
+       } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
+               BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
+               _bt_handle_pxp_property_changed_event(val,
+                                       object_path, BT_PXP_REPORTER_ROLE);
        }
        g_variant_unref(val);
 }
index a9a94a6..19df7fd 100644 (file)
@@ -423,6 +423,8 @@ int _bt_send_event(int event_type, int event, GVariant *param)
                break;
        case BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND:
                signal = BT_IBEACON_DEVICE_FOUND;
+       case BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED:
+               signal = BT_PXP_PROPERTY_CHANGED;
                break;
        default:
                BT_ERR("Unknown event");
index 8ab7689..6ed4b6b 100644 (file)
@@ -294,3 +294,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;
+}
index 27bd7e3..2753d13 100644 (file)
@@ -176,6 +176,7 @@ extern "C" {
 #define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
 #define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource"
 #define BT_PROXIMITY_MONITOR_INTERFACE "org.bluez.ProximityMonitor1"
+#define BT_PROXIMITY_REPORTER_INTERFACE "org.bluez.ProximityReporter1"
 
 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
 
index 50e123a..6746532 100644 (file)
@@ -40,6 +40,11 @@ typedef enum {
        BT_PXP_PROPERTY_TX_POWER = 0x04
 } bt_proximity_alert_property_t;
 
+typedef enum {
+        BT_PXP_REPORTER_ROLE = 0x00,
+        BT_PXP_MONITOR_ROLE = 0x01,
+} bt_proximity_role_t;
+
 int bt_set_proximity_property(bluetooth_device_address_t *device_address,
                unsigned int property, int value);
 
@@ -49,6 +54,10 @@ int bt_get_proximity_property(bluetooth_device_address_t *device_address,
 int bt_get_proximity_supported_services(bluetooth_device_address_t *device_address,
                unsigned int *supported_services);
 
+int bt_register_proximity_reporter();
+
+int bt_unregister_proximity_reporter();
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 80e38d3..20cfd24 100644 (file)
@@ -696,6 +696,7 @@ typedef enum {
        BLUETOOTH_EVENT_IPSP_DISCONNECTED, /**< IPSP Disconnected event */
        BLUETOOTH_EVENT_IPSP_INTERFACE_INFO, /** IPSP BT Interface Info after connection */
        BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED,  /** LE data length values changed */
+       BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED, /** Proximity property changed */
 } bluetooth_event_type_t;
 
  /**
@@ -1654,6 +1655,15 @@ typedef struct {
        guint16 max_rx_time;
 } bt_le_data_length_params_t;
 
+/**
+ * Structure for proximity property change params
+ */
+typedef struct {
+       bluetooth_device_address_t device_address;
+       int role;
+       int service_type;
+       int alert_lvl;
+} bt_pxp_property_changed_params_t;
 
  /**
  * @brief DPM BT allowance state
@@ -6973,6 +6983,39 @@ int bluetooth_get_proximity_property(const bluetooth_device_address_t *device_ad
  */
 int bluetooth_get_proximity_supported_services(const bluetooth_device_address_t *device_address,
                                                        int *services_supported);
+
+/**
+ * @fn int bluetooth_register__proximity_reporter();
+ *
+ * @brief Register all proximity related services in BlueZ.
+ *
+ * This function is a synchronous call.
+ *
+ * @return   BLUETOOTH_ERROR_NONE - Success \n
+ *           BLUETOOTH_ERROR_NOT_FOUND - Cannot find the proxy\n
+ *
+ * @exception  None
+ *
+ * @remark     None
+ */
+int bluetooth_register_proximity_reporter();
+
+/**
+ * @fn int bluetooth_unregister__proximity_reporter();
+ *
+ * @brief Unregister all proximity related services in BlueZ.
+ *
+ * This function is a synchronous call.
+ *
+ * @return   BLUETOOTH_ERROR_NONE - Success \n
+ *           BLUETOOTH_ERROR_NOT_FOUND - Cannot find the proxy\n
+ *
+ * @exception  None
+ *
+ * @remark     None
+ */
+int bluetooth_unregister_proximity_reporter();
+
 /**
  * @}
  */
index d01eb3e..878a19d 100644 (file)
@@ -357,6 +357,8 @@ typedef enum {
        BT_PXP_SET_PROPERTY = BT_FUNC_PXP_BASE,
        BT_PXP_GET_PROPERTY,
        BT_PXP_GET_SUPPORTED_SERIVCES,
+       BT_PXP_REGISTER_REPORTER,
+       BT_PXP_UNREGISTER_REPORTER,
 } bt_function_t;
 
 typedef struct {
@@ -521,6 +523,7 @@ typedef struct {
 #define BT_IPSP_DISCONNECTED "IpspDisconnected"
 #define BT_LE_DATA_LENGTH_CHANGED "LEDataLengthChanged"
 #define BT_IBEACON_DEVICE_FOUND "iBeaconDeviceFound"
+#define BT_PXP_PROPERTY_CHANGED "PxpValueChanged"
 
 #ifdef __cplusplus
 }