- clean codes and remove redundant code as a function.
- separate the codes related to the user and device in
user-awareness-user.c into two files.
Change-Id: I8a3351edc2cd7a3cf9fc07470d8724ab209db5e8
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
SET(LIB_PKGCONFIG_DIR "${LIB_PATH}/pkgconfig")
SET(SRCS
+ src/user-awareness-device.c
src/user-awareness-service.c
src/user-awareness-monitors.c
src/user-awareness-users.c
*/
#define UA_SERVICE_DEFAULT "ua.service.default" /**< Default service name */
+/**
+ * @brief Event type for user event callback data structure.
+ * @since_tizen 5.5
+ */
+typedef enum {
+ UA_USER_EVENT_DEVICE_ADDED = 0, /**< Device added for a user */
+ UA_USER_EVENT_MAX /**< Event Max. */
+} ua_user_event_e;
+
/**
* @brief Callback data structure.
* @since_tizen 5.5
* @pre
* @post
*/
-void __ua_free_ua_monitor_t(gpointer data);
+void _ua_free_ua_monitor_t(gpointer data);
/**
* @brief Destroys a user handle.
* @pre
* @post
*/
-ua_dev_info_s* __ua_get_device_info_from_uam(uam_device_info_s *uam_info);
+ua_dev_info_s* _ua_get_device_info_from_uam(uam_device_info_s *uam_info);
/**
* @brief Sets data in user info. state callback.
extern "C" {
#endif
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @internal
+ * @brief Returns changed technology type for ua-manager.
+ * @since_tizen 5.5
+ *
+ * @param[in] ua_error Error code to be converted.
+ *
+ * @return #UA_MAC_TYPE_INVALID on failure, otherwise a positive error value
+ * @retval #UA_MAC_TYPE_NONE None
+ * @retval #UA_MAC_TYPE_BT BT MAC
+ * @retval #UA_MAC_TYPE_BLE BLE MAC
+ * @retval #UA_MAC_TYPE_WIFIWi-Fi station mode MAC
+ * @retval #UA_MAC_TYPE_P2P Wi-Fi P2P mode MAC
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+ua_mac_type_e _to_ua_mac_type(uam_tech_type_e tech_type);
+
/**
* @ingroup CAPI_NETWORK_UA_MODULE
* @internal
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <ua-api.h>
+#include <user-awareness.h>
+#include <user-awareness-log.h>
+#include <user-awareness-private.h>
+#include <user-awareness-util.h>
+
+extern GSList *ua_users_list;
+
+GSList *ua_devices_list;
+GSList *ua_devices_db_list;
+ua_callback_s user_callbacks[UA_USER_EVENT_MAX] = {{NULL, NULL},};
+
+static ua_dev_info_s *__ua_get_device_from_list(const char *device_id,
+ const char *mac, ua_mac_type_e type)
+{
+ GSList *l;
+ ua_dev_info_s *dev;
+
+ for (l = ua_devices_list; NULL != l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_s *)l->data;
+
+ if (type != dev->type)
+ continue;
+
+ if (device_id && !g_strcmp0(device_id, dev->device_id)) {
+ UA_INFO("Device found, device id[%s]", dev->device_id);
+ return dev;
+ }
+
+ if (mac && !g_strcmp0(mac, dev->mac)) {
+ UA_INFO("Device found, mac address[%s]", dev->mac);
+ return dev;
+ }
+ }
+
+ return NULL;
+}
+
+static void __ua_remove_device_info_from_list(uam_device_info_s *uam_info)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_dev_info_s *u;
+ ua_mac_type_e type;
+ ret_if(NULL == uam_info);
+
+ type = _to_ua_mac_type(uam_info->type);
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ u = (ua_dev_info_s *)l->data;
+
+ if (type != u->type)
+ continue;
+
+ if (g_strcmp0(uam_info->device_id, u->device_id))
+ continue;
+
+ if (u->create_by_app) {
+ UA_INFO("Device created by APP, do not remove");
+ u->isadded = false;
+ }
+
+ UA_INFO("Device found, device id[%s]", u->device_id);
+ ua_devices_list = g_slist_remove(ua_devices_list, u);
+ _ua_free_ua_device_info_t((gpointer)u);
+ break;
+ }
+
+ FUNC_EXIT;
+}
+
+static ua_dev_info_s* __ua_add_device_info_to_list(uam_device_info_s *uam_info)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *dev;
+ retv_if(NULL == uam_info, NULL);
+
+ dev = __ua_get_device_from_list(uam_info->device_id,
+ uam_info->mac, _to_ua_mac_type(uam_info->type));
+ if (dev) {
+ /* Update device info */
+ g_free(dev->mac);
+ dev->mac = g_strdup(uam_info->mac);
+
+ g_free(dev->ipv4);
+ dev->ipv4 = g_strdup(uam_info->ipv4_addr);
+
+ g_free(dev->device_id);
+ dev->device_id = g_strdup(uam_info->device_id);
+
+ dev->os = uam_info->operating_system;
+ dev->pairing_required = FALSE;
+ dev->discriminant= true;
+ dev->isadded = true;
+ return dev;
+ }
+
+ dev = _ua_get_device_info_from_uam(uam_info);
+ retv_if(NULL == dev, NULL);
+
+ /* Add device to list of devices */
+ ua_devices_list = g_slist_append(ua_devices_list, dev);
+
+ FUNC_EXIT;
+ return dev;
+}
+
+ua_dev_info_s* _ua_get_device_info_from_uam(uam_device_info_s *uam_info)
+{
+ ua_dev_info_s *dev = g_malloc0(sizeof(ua_dev_info_s));
+ if (!dev) {
+ UA_ERR("g_malloc0 failed");
+ return NULL;
+ }
+ dev->user = NULL;
+ dev->bssid = NULL;
+ dev->ipv6 = NULL;
+
+ dev->mac = g_strdup(uam_info->mac);
+ if (dev->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return NULL;
+ }
+
+ dev->ipv4 = g_strdup(uam_info->ipv4_addr);
+ if (dev->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return NULL;
+ }
+
+ dev->device_id = g_strdup(uam_info->device_id);
+ if (dev->device_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return NULL;
+ }
+
+ dev->type = _to_ua_mac_type(uam_info->type);
+ dev->pairing_required = FALSE;
+ dev->os = uam_info->operating_system;
+ dev->discriminant= uam_info->discriminant;
+ dev->isadded = true;
+ dev->handle = (ua_device_h)dev;
+
+ return dev;
+}
+
+void _ua_create_ua_ble_payload_s(ua_ble_payload_s **payload_handle)
+{
+ FUNC_ENTRY;
+ ua_ble_payload_s *payload = NULL;
+
+ ret_if(NULL == payload_handle);
+
+ payload = g_malloc0(sizeof(ua_ble_payload_s));
+ if (!payload) {
+ UA_ERR("g_malloc0 failed");
+ *payload_handle = NULL;
+ return;
+ }
+
+//TODO lk, set default value of these vars
+ payload->service_id = 0x00;
+ payload->device_icon = 0x00;
+ payload->purpose = 0x00;
+ payload->duid = NULL;
+ payload->bt_mac = NULL;
+
+ *payload_handle = payload;
+ FUNC_EXIT;
+}
+
+void _ua_free_ua_ble_payload_s(gpointer data)
+{
+ FUNC_ENTRY;
+ ua_ble_payload_s *payload = data;
+
+ ret_if(NULL == payload);
+
+ g_free(payload->duid);
+ g_free(payload->bt_mac);
+
+ g_free(payload);
+ FUNC_EXIT;
+}
+
+ua_ble_payload_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload)
+{
+ FUNC_ENTRY;
+ ua_ble_payload_s *payload = NULL;
+
+ retv_if(NULL == uam_payload, NULL);
+
+ payload = g_malloc0(sizeof(ua_ble_payload_s));
+ if (!payload) {
+ UA_ERR("g_malloc0 failed");
+ return NULL;
+ }
+
+ payload->service_id = uam_payload->service_id;
+ payload->device_icon = uam_payload->device_icon;
+ payload->purpose = uam_payload->purpose;
+
+ payload->duid = g_memdup(uam_payload->duid, UA_BLE_PAYLOAD_DUID_LEN + 1);
+ if (!payload->duid) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_ble_payload_s(payload);
+ return NULL;
+ }
+
+ payload->bt_mac = g_strdup(uam_payload->bt_mac);
+ if (!payload->bt_mac) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_ble_payload_s(payload);
+ return NULL;
+ }
+
+ FUNC_EXIT;
+ return payload;
+}
+
+void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, ua_ble_payload_s *payload)
+{
+ FUNC_ENTRY;
+ memset(uam_payload, 0, sizeof(uam_ble_payload_s));
+
+ ret_if(NULL == payload);
+
+ uam_payload->service_id = payload->service_id;
+ uam_payload->device_icon = payload->device_icon;
+ uam_payload->purpose = payload->purpose;
+
+ if (payload->duid)
+ memcpy(uam_payload->duid, payload->duid, UA_BLE_PAYLOAD_DUID_LEN + 1);
+
+ if (payload->bt_mac)
+ g_strlcpy(uam_payload->bt_mac, payload->bt_mac, UA_BT_MAC_MAX_LEN);
+
+ FUNC_EXIT;
+}
+
+ua_ble_payload_s* _ua_payload_clone(ua_ble_payload_s *org_payload)
+{
+ FUNC_ENTRY;
+ ua_ble_payload_s *payload = NULL;
+
+ retv_if(NULL == org_payload, NULL);
+
+ payload = g_malloc0(sizeof(ua_ble_payload_s));
+ if (!payload) {
+ UA_ERR("g_malloc0 failed");
+ return NULL;
+ }
+
+ payload->service_id = org_payload->service_id;
+ payload->device_icon = org_payload->device_icon;
+ payload->purpose = org_payload->purpose;
+
+ payload->duid = g_memdup(org_payload->duid, UA_BLE_PAYLOAD_DUID_LEN + 1);
+ if (!payload->duid && org_payload->duid) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_ble_payload_s(payload);
+ return NULL;
+ }
+
+ payload->bt_mac = g_strdup(org_payload->bt_mac);
+ if (!payload->bt_mac && org_payload->bt_mac) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_ble_payload_s(payload);
+ return NULL;
+ }
+
+ FUNC_EXIT;
+ return payload;
+}
+
+void _ua_free_ua_device_info_t(gpointer data)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = data;
+
+ ret_if(NULL == device);
+
+ g_free(device->mac);
+ g_free(device->bssid);
+ g_free(device->ipv4);
+ g_free(device->ipv6); // LCOV_EXCL_LINE
+ g_free(device->device_id);
+ _ua_free_ua_ble_payload_s(device->payload);
+
+ g_free(device);
+ FUNC_EXIT;
+}
+
+int _ua_is_device_exist(char *device_id, char *mac, ua_mac_type_e type,
+ gboolean *is_exist)
+{
+ GSList *l;
+ UA_VALIDATE_INPUT_PARAMETER(is_exist);
+ ua_dev_info_s *dev;
+ *is_exist = false;
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_s *)l->data;
+
+ if ((int)type == (int)dev->type) {
+ if (device_id && !g_strcmp0(device_id, dev->device_id)) {
+ /* LCOV_EXCL_START */
+ UA_INFO("Device found, device id[%s]", dev->device_id);
+ *is_exist = true;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (mac && !g_strcmp0(mac, dev->mac)) {
+ /* LCOV_EXCL_START */
+ UA_INFO("Device found, mac address[%s]", dev->mac);
+ *is_exist = true;
+ /* LCOV_EXCL_STOP */
+ }
+ }
+ }
+
+ return UA_ERROR_NONE;
+}
+
+void _ua_handle_device_added(int result, uam_device_info_s *uam_info)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *dev;
+ result = _ua_get_error_code(result);
+
+ if (UA_ERROR_NONE != result) {
+ dev = __ua_get_device_from_list(uam_info->device_id,
+ uam_info->mac, _to_ua_mac_type(uam_info->type));
+ ret_if(NULL == dev);
+ UA_ERR("Add device failed for Id:[%s] MAC type:[0x%4.4X]",
+ dev->device_id, dev->type);
+ } else {
+ dev = __ua_add_device_info_to_list(uam_info);
+ ret_if(NULL == dev);
+ }
+
+ if (user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback) {
+ ((ua_user_device_added_cb)user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback)(
+ result, dev, user_callbacks[UA_USER_EVENT_DEVICE_ADDED].user_data);
+ UA_INFO("Invoked device added callback");
+
+ /* Reset callback */
+ user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback = NULL;
+ user_callbacks[UA_USER_EVENT_DEVICE_ADDED].user_data = NULL;
+ }
+
+ FUNC_EXIT;
+}
+
+void _ua_handle_device_removed(int result, uam_device_info_s *uam_info)
+{
+ FUNC_ENTRY;
+
+ result = _ua_get_error_code(result);
+ ret_if(UA_ERROR_NONE != result);
+
+ __ua_remove_device_info_from_list(uam_info);
+
+ FUNC_EXIT;
+}
+
+int ua_device_create(ua_device_h *device_handle)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = NULL;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+
+ device = g_malloc0(sizeof(ua_dev_info_s));
+ if (!device) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+ device->user = NULL;
+ device->mac = NULL;
+ device->bssid = NULL;
+ device->ipv4 = NULL;
+ device->ipv6 = NULL;
+ device->device_id = NULL;
+ device->type = 0;
+ device->pairing_required = FALSE;
+ device->state = UA_PRSENCE_STATE_INVALID;
+ device->os = UA_OS_TYPE_NOT_DEFINE;
+ device->isadded = false;
+ device->discriminant = true;
+ device->payload = NULL;
+
+ /* Add device to list of devices */
+ *device_handle = (ua_device_h)device;
+ device->handle = *device_handle;
+ device->create_by_app = true;
+ ua_devices_list = g_slist_append(ua_devices_list, device);
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_destroy(ua_device_h device_handle)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
+
+ ua_devices_list = g_slist_remove(ua_devices_list, device);
+ _ua_free_ua_device_info_t((gpointer)device);
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_mac_type(ua_device_h handle, ua_mac_type_e mac_type)
+{
+ FUNC_ENTRY;
+
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ retv_if(UA_MAC_TYPE_NONE >= mac_type, UA_ERROR_INVALID_PARAMETER);
+ retv_if(UA_MAC_TYPE_INVALID <= mac_type, UA_ERROR_INVALID_PARAMETER);
+
+ device->type = mac_type;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_mac_type(ua_device_h handle, ua_mac_type_e *mac_type)
+{
+ FUNC_ENTRY;
+
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(mac_type);
+ UA_PRINT_DEVICE_HANDLE(handle);
+
+ *mac_type = device->type;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_mac_address(
+ ua_device_h handle,
+ const char *mac_address)
+{
+ FUNC_ENTRY;
+ int ret;
+ gboolean status = false;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(mac_address);
+ UA_VALIDATE_HANDLE(handle, ua_devices_list);
+
+ retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+
+ /* This code will check if app try to add mac address which is already set for same
+ * or for some other device handle, Then it does not allow to set and restrict to make
+ * suplicate entry as mac address is suppose to same for one device.
+ */
+ ret = _ua_is_device_exist(NULL, (char*)mac_address, device->type, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
+
+ retv_if((strlen(mac_address) != (UA_MAC_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER);
+
+ g_free(device->mac);
+ device->mac = g_malloc0(UA_MAC_ADDRESS_STRING_LEN);
+ if (device->mac){
+ g_strlcpy(device->mac, mac_address, UA_MAC_ADDRESS_STRING_LEN);
+ } else {
+ UA_ERR("Failt to allocate memory");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ g_strlcpy(device->mac, mac_address, UA_MAC_ADDRESS_STRING_LEN);
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_os_info(
+ ua_device_h handle,
+ ua_os_type_e os)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_devices_list);
+
+ retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+
+ if (os < UA_OS_TYPE_NOT_DEFINE || os > UA_OS_TYPE_IOS) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Invalid os type");
+ return UA_ERROR_INVALID_PARAMETER;
+ /* LCOV_EXCL_STOP */
+ }
+
+ device->os = os;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_device_id(
+ ua_device_h handle,
+ const char *device_id)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+ int ret;
+ gboolean status = false;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(device_id);
+ UA_VALIDATE_HANDLE(handle, ua_devices_list);
+
+ retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+ /* This code will check if app try to add device id which is already set for same
+ * or for some other device handle, Then it does not allow to set and restrict to make
+ * suplicate entry as device id is suppose to same for one device.
+ */
+ ret = _ua_is_device_exist((char*)device_id, NULL, device->type, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
+
+ g_free(device->device_id);
+ device->device_id = g_strdup(device_id);
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_wifi_bssid(
+ ua_device_h handle,
+ const char *bssid)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(bssid);
+ UA_VALIDATE_HANDLE(handle, ua_devices_list);
+
+ retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+ retv_if((strlen(bssid) != (UA_MAC_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER);
+
+ g_free(device->bssid);
+ device->bssid = g_malloc0(UA_MAC_ADDRESS_STRING_LEN);
+ if (device->bssid) {
+ g_strlcpy(device->bssid, bssid, UA_MAC_ADDRESS_STRING_LEN);
+ } else {
+ UA_ERR("Failed to allocated memory");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_wifi_ipv4_address(
+ ua_device_h handle,
+ const char *ipv4_address)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(ipv4_address);
+ UA_VALIDATE_HANDLE(handle, ua_devices_list);
+
+ retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+ retv_if((strlen(ipv4_address) > (UA_IPV4_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER);
+
+ g_free(device->ipv4);
+ device->ipv4 = g_malloc0(UA_IPV4_ADDRESS_STRING_LEN);
+ if (device->ipv4) {
+ g_strlcpy(device->ipv4, ipv4_address, UA_IPV4_ADDRESS_STRING_LEN);
+ } else {
+ UA_ERR("Failed to allocated memory");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_discriminant(
+ ua_device_h device_handle,
+ bool discriminant)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
+
+ device->discriminant = discriminant;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_payload_service_id(
+ ua_device_h handle,
+ const char service_id)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ _ua_create_ua_ble_payload_s(&device->payload);
+ if (!device->payload) {
+ UA_ERR("_ua_create_ua_ble_payload_s() failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ device->payload->service_id = service_id;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_payload_device_icon(
+ ua_device_h handle,
+ const char device_icon)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ _ua_create_ua_ble_payload_s(&device->payload);
+ if (!device->payload) {
+ UA_ERR("_ua_create_ua_ble_payload_s() failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ device->payload->device_icon = device_icon;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_payload_purpose(
+ ua_device_h handle,
+ const char purpose)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ _ua_create_ua_ble_payload_s(&device->payload);
+ if (!device->payload) {
+ UA_ERR("_ua_create_ua_ble_payload_s() failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ device->payload->purpose = purpose;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_set_payload_duid(
+ ua_device_h handle,
+ unsigned int duid_len,
+ const char *duid)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(duid);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+ retv_if(duid_len != UA_BLE_PAYLOAD_DUID_LEN, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ _ua_create_ua_ble_payload_s(&device->payload);
+ if (!device->payload) {
+ UA_ERR("_ua_create_ua_ble_payload_s() failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ g_free(device->payload->duid);
+ device->payload->duid = NULL;
+
+ device->payload->duid = g_malloc0(UA_BLE_PAYLOAD_DUID_LEN + 1);
+ if (device->payload->duid == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ memcpy(device->payload->duid, duid, UA_BLE_PAYLOAD_DUID_LEN);
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_mac_address(
+ ua_device_h device_handle,
+ char **mac_address)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(mac_address);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ if (!device->mac) {
+ /* LCOV_EXCL_START */
+ *mac_address = NULL;
+ goto done;
+ /* LCOV_EXCL_STOP */
+ }
+
+ *mac_address = g_strdup(device->mac);
+
+ if (*mac_address == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_os_info(
+ ua_device_h device_handle,
+ ua_os_type_e *os_info
+ )
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(os_info);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ *os_info = device->os;
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_device_id(
+ ua_device_h device_handle,
+ char **device_id)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(device_id);
+
+ if (!device->device_id) {
+ *device_id = NULL;
+ goto done;
+ }
+
+ *device_id = g_strdup(device->device_id);
+
+ if (*device_id == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_wifi_bssid(
+ ua_device_h device_handle,
+ char **bssid)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(bssid);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ if (!device->bssid) {
+ *bssid = NULL;
+ goto done;
+ }
+
+ *bssid = g_strdup(device->bssid);
+
+ if (*bssid == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_wifi_ipv4_address(
+ ua_device_h device_handle,
+ char **ipv4_address)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(ipv4_address);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ if (!device->ipv4) {
+ /* LCOV_EXCL_START */
+ *ipv4_address = NULL;
+ goto done;
+ /* LCOV_EXCL_STOP */
+ }
+
+ *ipv4_address = g_strdup(device->ipv4);
+
+ if (*ipv4_address == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_discriminant(
+ ua_device_h device_handle,
+ bool *discriminant)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(discriminant);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ *discriminant = device->discriminant;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_last_presence(
+ ua_device_h device_handle,
+ long *timestamp)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_INPUT_PARAMETER(timestamp);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ *timestamp = device->last_presence_timestamp;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_payload_service_id(
+ ua_device_h handle,
+ char *service_id)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(service_id);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ *service_id = 0x00;
+ UA_DBG("payload(service_id) is not found");
+ goto done;
+ }
+
+ *service_id = device->payload->service_id;
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_payload_device_icon(
+ ua_device_h handle,
+ char *device_icon)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(device_icon);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ *device_icon = 0x00;
+ UA_DBG("payload(device_icon) is not found");
+ goto done;
+ }
+
+ *device_icon = device->payload->device_icon;
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+int ua_device_get_payload_purpose(
+ ua_device_h handle,
+ char *purpose)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(purpose);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload) {
+ *purpose = 0x00;
+ UA_DBG("payload(purpose) is not found");
+ goto done;
+ }
+
+ *purpose = device->payload->purpose;
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_payload_duid(
+ ua_device_h handle,
+ char **duid)
+{
+ FUNC_ENTRY;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(duid);
+ UA_PRINT_DEVICE_HANDLE(handle);
+ retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+ if (!device->payload || !device->payload->duid) {
+ *duid = NULL;
+ UA_DBG("payload(duid) is not found");
+ goto done;
+ }
+
+ *duid = g_memdup(device->payload->duid, UA_BLE_PAYLOAD_DUID_LEN);
+ if (*duid == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_memdup failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_by_mac_address(
+ const char *mac,
+ ua_device_h *device_handle)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ int ret;
+ ua_dev_info_s *dev;
+ uam_device_info_s uam_dev;
+
+ UA_VALIDATE_INPUT_PARAMETER(mac);
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_s *)l->data;
+
+ if (!g_strcmp0(mac, dev->mac)) {
+ UA_INFO("MAC found [%s]", dev->mac);
+ *device_handle = (ua_device_h)dev;
+ goto done;
+ }
+ }
+
+ /* LCOV_EXCL_START */
+ ret = _ua_get_error_code(_uam_request_get_device_by_mac(mac, &uam_dev));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ *device_handle = NULL;
+ return ret;
+ }
+
+ dev = g_malloc0(sizeof(ua_dev_info_s));
+ if (!dev) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->user = NULL;
+ dev->bssid = NULL;
+ dev->ipv6 = NULL;
+
+ dev->mac = g_strdup(uam_dev.mac);
+
+ if (dev->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->ipv4 = g_strdup(uam_dev.ipv4_addr);
+
+ if (dev->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->device_id = g_strdup(uam_dev.device_id);
+
+ if (dev->device_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->payload = _ua_get_payload_from_uam(&uam_dev.payload);
+ if (dev->payload == NULL) {
+ UA_ERR("_ua_get_payload_from_uam() failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->type = _to_ua_mac_type(uam_dev.type);
+ dev->pairing_required = FALSE;
+ dev->discriminant= uam_dev.discriminant;
+ dev->os = uam_dev.operating_system;
+ dev->isadded = true;
+
+ /* Add device to list of devices */
+ *device_handle = (ua_device_h)dev;
+ dev->handle = *device_handle;
+ ua_devices_list = g_slist_append(ua_devices_list, dev);
+ /* LCOV_EXCL_STOP */
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_get_by_device_id(
+ const char *device_id,
+ ua_mac_type_e mac_type,
+ ua_device_h *device_handle)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ int ret;
+ ua_dev_info_s *dev;
+ uam_device_info_s uam_dev;
+ uam_tech_type_e type;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_id);
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ retv_if(UA_MAC_TYPE_NONE >= mac_type, UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_INVALID <= mac_type), UA_ERROR_INVALID_PARAMETER);
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_s *)l->data;
+
+ if ((mac_type == dev->type) && !g_strcmp0(device_id, dev->device_id)) {
+ UA_INFO("Mobile ID found [%s]", dev->device_id);
+ *device_handle = (ua_device_h)dev;
+ goto done;
+ }
+ }
+
+ /* LCOV_EXCL_START */
+ type = _ua_to_uam_tech_type(mac_type);
+ ret = _ua_get_error_code(_uam_request_get_device_by_deviceid(device_id, type, &uam_dev));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ *device_handle = NULL;
+ return ret;
+ }
+
+ dev = g_malloc0(sizeof(ua_dev_info_s));
+ if (!dev) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->user = NULL;
+ dev->bssid = NULL;
+ dev->ipv6 = NULL;
+
+ dev->mac = g_strdup(uam_dev.mac);
+
+ if (dev->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->ipv4 = g_strdup(uam_dev.ipv4_addr);
+
+ if (dev->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->device_id = g_strdup(uam_dev.device_id);
+
+ if (dev->device_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->payload = _ua_get_payload_from_uam(&uam_dev.payload);
+ if (dev->payload == NULL) {
+ UA_ERR("_ua_get_payload_from_uam() failed");
+ *device_handle = NULL;
+ _ua_free_ua_device_info_t((gpointer)dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->type = _to_ua_mac_type(uam_dev.type);
+ dev->pairing_required = FALSE;
+ dev->os = uam_dev.operating_system;
+ dev->discriminant= uam_dev.discriminant;
+ dev->isadded = true;
+
+ /* Add device to list of devices */
+ *device_handle = (ua_device_h)dev;
+ dev->handle = *device_handle;
+ ua_devices_list = g_slist_append(ua_devices_list, dev);
+ /* LCOV_EXCL_STOP */
+
+done:
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_update(ua_device_h device_handle)
+{
+ int ret;
+ gboolean is_registered = false;
+ uam_device_info_s uam_device;
+ ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+ UA_PRINT_DEVICE_HANDLE(device);
+
+ retv_if((device->device_id == NULL || device->mac == NULL), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
+
+ memset(&uam_device, 0, sizeof(uam_device_info_s));
+
+ uam_device.operating_system = device->os;
+ uam_device.type = _ua_to_uam_tech_type(device->type);
+ uam_device.discriminant = device->discriminant;
+
+ if (device->mac)
+ g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
+
+ if (device->device_id)
+ g_strlcpy(uam_device.device_id, device->device_id, UA_MOBILE_ID_STRING_LEN);
+
+ if (device->ipv4)
+ g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
+
+ _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
+
+ ret = _ua_get_error_code(_uam_is_device_registered(&uam_device, &is_registered));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ if (!is_registered) {
+ /* LCOV_EXCL_START */
+ UA_ERR("No registerd device");
+ /* LCOV_EXCL_STOP */
+ return UA_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _ua_get_error_code(_uam_request_update_device(&uam_device));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_uam_request_set_device_update returned %s",
+ _ua_get_error_string(ret));
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_device_clone(ua_device_h *cloned,
+ ua_device_h origin)
+{
+ FUNC_ENTRY;
+ int ret;
+ ua_dev_info_s *device;
+ uam_user_info_s uam_user;
+ ua_dev_info_s *org_device = (ua_dev_info_s *)origin;
+
+ /* LCOV_EXCL_START */
+ UA_VALIDATE_INPUT_PARAMETER(cloned);
+ UA_VALIDATE_INPUT_PARAMETER(origin);
+ UA_VALIDATE_HANDLE(origin, ua_devices_db_list);
+ UA_EXIST_HANDLE(origin, ua_devices_list);
+
+ device = __ua_get_device_from_list(org_device->device_id,
+ org_device->mac, org_device->type);
+ if (device) {
+//TODO lk, in this case cloned will be destroyed as per description of API, which will then delete device from list. ???
+ *cloned = (ua_device_h)device;
+ return UA_ERROR_NONE;
+ }
+
+ device = g_malloc0(sizeof(ua_dev_info_s));
+ if (!device) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ device->mac = g_strdup(org_device->mac);
+ if (device->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ device->ipv4 = g_strdup(org_device->ipv4);
+ if (device->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ device->device_id = g_strdup(org_device->device_id);
+ if (device->device_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ device->payload = _ua_payload_clone(org_device->payload);
+ if (device->payload == NULL && org_device->payload) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ device->isadded = org_device->isadded;
+ device->type = org_device->type;
+ device->os = org_device->os;
+ device->discriminant = org_device->discriminant;
+ device->last_presence_timestamp = org_device->last_presence_timestamp;
+
+ if (!device->user) {
+ /* Currently user info will be create and store at this point */
+ ret = _ua_get_error_code(_uam_request_get_user_by_deviceid(device->device_id, &uam_user));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ _ua_free_ua_device_info_t((gpointer)device);
+ return ret;
+ } else {
+ GSList *l;
+ ua_user_info_s *user_info;
+ int found = 0;
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ user_info = (ua_user_info_s *)l->data;
+
+ if (!g_strcmp0(uam_user.account, user_info->account)) {
+ UA_INFO("User found [%s]", user_info->account);
+ device->user = (ua_user_h)user_info;
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found)
+ UA_ERR("User not found [%s]", uam_user.account);
+ else
+ UA_ERR("User found [%s]", uam_user.account);
+
+ }
+ } else
+ UA_INFO("user handle is already present!");
+
+ /* Add device to list of devices */
+ *cloned = (ua_device_h)device;
+ device->handle = (ua_device_h)device;
+ device->create_by_app = true;
+ ua_devices_list = g_slist_append(ua_devices_list, device);
+
+ FUNC_EXIT;
+ /* LCOV_EXCL_STOP */
+ return UA_ERROR_NONE;
+}
+
+int ua_device_foreach_added(
+ ua_registered_dev_cb foreach_cb,
+ void *user_data)
+{
+ FUNC_ENTRY;
+ int i;
+ int ret;
+ GPtrArray *devices_list = NULL;
+ uam_device_info_s *ptr;
+ GSList *l;
+
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+
+ devices_list = g_ptr_array_new();
+ retv_if(NULL == devices_list, UA_ERROR_OUT_OF_MEMORY);
+
+ ret = _ua_get_error_code(_uam_request_get_devices(&devices_list));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ g_ptr_array_free(devices_list, TRUE);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ for (i = 0; i < devices_list->len; i++) {
+ /* LCOV_EXCL_START */
+ ptr = g_ptr_array_index(devices_list, i);
+ if (ptr) {
+ ua_dev_info_s* device_info;
+ device_info = g_malloc0(sizeof(ua_dev_info_s));
+ if (!device_info) {
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ device_info->mac = g_strdup(ptr->mac);
+ if (device_info->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ device_info->ipv4 = g_strdup(ptr->ipv4_addr);
+ if (device_info->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ device_info->device_id = g_strdup(ptr->device_id);
+ if (device_info->device_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ goto done;
+ }
+
+ device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
+ if (device_info->payload == NULL) {
+ UA_ERR("_ua_get_payload_from_uam() failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ goto done;
+ }
+
+ device_info->isadded = true;
+ device_info->handle = (ua_device_h)device_info;
+ device_info->type = _to_ua_mac_type(ptr->type);
+ device_info->os = ptr->operating_system;
+ device_info->discriminant = ptr->discriminant;
+ device_info->last_presence_timestamp = ptr->last_seen;
+ ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info);
+ } else {
+ UA_ERR("OPERATION_FAILED(0x%08x)",
+ UA_ERROR_OPERATION_FAILED);
+ ret = UA_ERROR_OPERATION_FAILED;
+ goto done;
+ }
+ /* LCOV_EXCL_STOP */
+ }
+
+ for (l = ua_devices_db_list; l; l = g_slist_next(l)) {
+ /* LCOV_EXCL_START */
+ ua_dev_info_s *u = l->data;
+
+ if (NULL == u)
+ continue;
+
+ if (!foreach_cb(u->handle, user_data))
+ break;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t);
+ ua_devices_db_list = NULL;
+
+ g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL);
+ g_ptr_array_free(devices_list, TRUE);
+
+ FUNC_EXIT;
+ return ret;
+}
+
+int ua_device_foreach_added_by_user(
+ ua_user_h user_handle,
+ ua_registered_dev_cb foreach_cb,
+ void *user_data)
+{
+ FUNC_ENTRY;
+ int i;
+ int ret;
+ ua_user_info_s *user = (ua_user_info_s *)user_handle;
+ GPtrArray *devices_list = NULL;
+ uam_device_info_s *ptr;
+ GSList *l;
+
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+ UA_VALIDATE_INPUT_PARAMETER(user_handle);
+ UA_VALIDATE_HANDLE(user_handle, ua_users_list);
+
+ devices_list = g_ptr_array_new();
+ retv_if(NULL == devices_list, UA_ERROR_OUT_OF_MEMORY);
+
+ ret = _ua_get_error_code(_uam_request_get_user_devices(user->account, &devices_list));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ g_ptr_array_free(devices_list, TRUE);
+ return ret;
+ }
+
+ for (i = 0; i < devices_list->len; i++) {
+ /* LCOV_EXCL_START */
+ ptr = g_ptr_array_index(devices_list, i);
+ if (ptr) {
+ ua_dev_info_s* device_info;
+ device_info = g_malloc0(sizeof(ua_dev_info_s));
+ if (!device_info) {
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ device_info->mac = g_strdup(ptr->mac);
+ if (device_info->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ goto done;
+ }
+
+ device_info->ipv4 = g_strdup(ptr->ipv4_addr);
+ if (device_info->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ goto done;
+ }
+
+ device_info->device_id = g_strdup(ptr->device_id);
+ if (device_info->device_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ goto done;
+ }
+
+ device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
+ if (device_info->payload == NULL) {
+ UA_ERR("_ua_get_payload_from_uam() failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_device_info_t((gpointer)device_info);
+ goto done;
+ }
+
+ device_info->isadded = true;
+ device_info->handle = (ua_device_h)device_info;
+ device_info->type = _to_ua_mac_type(ptr->type);
+ device_info->os = ptr->operating_system;
+ device_info->last_presence_timestamp = ptr->last_seen;
+ device_info->discriminant = ptr->discriminant;
+ device_info->user = (ua_user_h)user;
+ ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info);
+ } else {
+ UA_ERR("OPERATION_FAILED(0x%08x)",
+ UA_ERROR_OPERATION_FAILED);
+ ret = UA_ERROR_OPERATION_FAILED;
+ goto done;
+ }
+ /* LCOV_EXCL_STOP */
+ }
+
+ for (l = ua_devices_db_list; l; l = g_slist_next(l)) {
+ /* LCOV_EXCL_START */
+ ua_dev_info_s *u = l->data;
+
+ if (NULL == u)
+ continue;
+
+ if (!foreach_cb(u->handle, user_data))
+ break;
+ /* LCOV_EXCL_STOP */
+ }
+
+done:
+ g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t);
+ ua_devices_db_list = NULL;
+
+ g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL);
+ g_ptr_array_free(devices_list, TRUE);
+
+ FUNC_EXIT;
+ return ret;
+}
+
+int ua_device_get_pairing_required(
+ ua_device_h handle,
+ bool *pairing_required)
+{
+ FUNC_ENTRY;
+ int ret;
+ ua_dev_info_s *device = (ua_dev_info_s *)handle;
+ gboolean is_registered = FALSE;
+ uam_device_info_s uam_device;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(pairing_required);
+ UA_PRINT_DEVICE_HANDLE(device_handle);
+
+ retv_if((((device->device_id == NULL) && (device->mac == NULL))), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
+
+ memset(&uam_device, 0, sizeof(uam_device_info_s));
+
+ uam_device.operating_system = device->os;
+ uam_device.discriminant = device->discriminant;
+ uam_device.type = _ua_to_uam_tech_type(device->type);
+
+ if (device->mac)
+ g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
+
+ if (device->device_id)
+ g_strlcpy(uam_device.device_id, device->device_id, UA_MOBILE_ID_STRING_LEN);
+
+ if (device->ipv4)
+ g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
+
+ ret = _ua_get_error_code(_uam_is_device_registered(&uam_device, &is_registered));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ *pairing_required = is_registered ? false : true;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
retv_if(TRUE != is_initialized, UA_ERROR_NOT_INITIALIZED);
g_slist_free_full(ua_services_list, _ua_free_ua_service_info_s);
- g_slist_free_full(ua_monitor_list, __ua_free_ua_monitor_t);
+ g_slist_free_full(ua_monitor_list, _ua_free_ua_monitor_t);
g_slist_free_full(ua_users_list, _ua_free_ua_user_info_t);
g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t);
GSList *ua_monitor_list;
static ua_monitor_h scanning_monitor = NULL;
-static int __ua_stop_monitoring(unsigned int bitmask, char *service, ua_detection_type_e detect);
-static int __ua_start_monitoring(unsigned int bitmask, char *service, ua_detection_type_e detect);
+static int __ua_stop_monitoring(unsigned int bitmask, char *service,
+ ua_detection_type_e detect)
+{
+ FUNC_ENTRY;
+ int ret;
+
+ if (detect == UA_PRESENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_stop_presence_detection(bitmask, service));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_ua_stop_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ } else if (detect == UA_ABSENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_stop_absence_detection(bitmask, service));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_ua_stop_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ } else
+ UA_ERR("invalid detection type");
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+static int __ua_start_monitoring(unsigned int bitmask, char *service,
+ ua_detection_type_e detect)
+{
+ FUNC_ENTRY;
+ int ret;
+
+ if (detect == UA_PRESENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_start_presence_detection(bitmask, service));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_ua_start_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ } else if (detect == UA_ABSENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_start_absence_detection(bitmask, service));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_ua_start_absence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ } else
+ UA_ERR("invalid detection type");
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
static void __ua_monitor_internal_presence_ref(ua_monitor_s *monitor)
{
}
/* LCOV_EXCL_STOP */
-int ua_monitor_is_sensor_available(
- ua_sensor_e sensor,
- bool *available
- )
-{
- FUNC_ENTRY;
- unsigned int available_sensors = 0;
- int ret;
- unsigned int bitmask;
-
- UA_VALIDATE_INPUT_PARAMETER(available);
-
- bitmask = __ua_sensor_type_to_bitmask(sensor);
- retv_if(!bitmask, UA_ERROR_INVALID_PARAMETER);
-
- ret = _ua_get_error_code(_uam_get_available_sensors(&available_sensors));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_uam_get_available_sensors failed");
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- if (0 == (available_sensors & bitmask))
- *available = false; // LCOV_EXCL_LINE
- else
- *available = true;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-static void _ua_free_user_state_info_t(gpointer data)
+static void __ua_free_user_state_info_t(gpointer data)
{
FUNC_ENTRY;
ua_user_state_info_s *user_state = data;
FUNC_EXIT;
}
-int ua_set_app_info(const char *app_id, unsigned short uid)
+static void __ua_user_state_clean()
{
FUNC_ENTRY;
+ GSList *l;
- UA_VALIDATE_INPUT_PARAMETER(app_id);
+ for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
- int ret = _ua_get_error_code(_uam_register_app(app_id, uid));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_uam_register_app failed");
- return ret;
- /* LCOV_EXCL_STOP */
- }
+ if (!monitor)
+ continue;
+ g_slist_free_full(monitor->user_state, __ua_free_user_state_info_t);
+ monitor->user_state = NULL;
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_unset_app_info(const char *app_id, unsigned short uid)
+static bool __ua_check_all_users_absence_state(GSList *user_state, unsigned int bitmask)
{
FUNC_ENTRY;
+ GSList *l;
+ ua_user_state_info_s *u;
- UA_VALIDATE_INPUT_PARAMETER(app_id);
+ for (l = user_state; l; l = g_slist_next(l)) {
+ u = (ua_user_state_info_s *)l->data;
- int ret = _ua_get_error_code(_uam_deregister_app(app_id, uid));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_uam_deregister_app failed");
- return ret;
- /* LCOV_EXCL_STOP */
+ if (u->sensor_bitmask & bitmask) {
+ UA_INFO("User found [%s]", u->account);
+ return false;
+ }
}
- FUNC_EXIT;
- return UA_ERROR_NONE;
+ return true;
}
-int ua_monitor_create(ua_monitor_h *handle)
+static void __ua_send_presence_detection()
{
FUNC_ENTRY;
+ GSList *l;
- ua_monitor_s *monitor = NULL;
- unsigned int available_sensors;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
-
- monitor = g_malloc0(sizeof(ua_monitor_s));
- if (!monitor) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
+ for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
- /* Add monitor to list of monitors */
- ua_monitor_list = g_slist_append(ua_monitor_list, monitor);
+ if (!monitor)
+ continue;
- _uam_get_available_sensors(&available_sensors);
+ if (monitor->presence_mode == UA_DETECT_MODE_ANY_SENSOR) {
+ monitor->presence_detected_bitmask = 0;
+ continue;
+ }
- monitor->presence_bitmask_and = 0;
- monitor->presence_bitmask_or = (available_sensors & UA_SENSOR_BLE) | (available_sensors & UA_SENSOR_WIFI);
- monitor->absence_bitmask_and = (available_sensors & UA_SENSOR_BLE) | (available_sensors & UA_SENSOR_WIFI);
- monitor->absence_bitmask_or = 0;
+ UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
+ monitor->sensor_bitmask, monitor->absence_detected_bitmask);
+ if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) {
+ if (monitor->presence_cb)
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ UA_SENSOR_MAX, monitor->user_data);
+ }
- *handle = (ua_monitor_h)monitor;
+ monitor->presence_detected_bitmask = 0;
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-void __ua_free_ua_monitor_t(gpointer data)
+static ua_user_state_info_s* __ua_monitor_user_state_create(char *account)
{
- FUNC_ENTRY;
+ ua_user_state_info_s *user_state;
- ua_monitor_s *monitor = data;
- ret_if(NULL == monitor);
+ user_state = g_malloc0(sizeof(ua_user_state_info_s));
- if (monitor->presence_detection_timer) {
- /* LCOV_EXCL_START */
- g_source_remove(monitor->presence_detection_timer);
- monitor->presence_detection_timer = 0;
- /* LCOV_EXCL_STOP */
+ if (!user_state) {
+ UA_ERR("g_malloc0 failed");
+ return NULL;
}
+ user_state->account = g_strdup(account);
- if (monitor->absence_detection_timer) {
- /* LCOV_EXCL_START */
- g_source_remove(monitor->absence_detection_timer);
- monitor->absence_detection_timer = 0;
- /* LCOV_EXCL_STOP */
+ if (user_state->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ __ua_free_user_state_info_t((gpointer)user_state);
+ return NULL;
}
- /* One monitor can observe only one service. */
- g_free(monitor->service);
- /* Free user-state information */
- g_slist_free_full(monitor->user_state, _ua_free_user_state_info_t);
- g_free(monitor);
-
- FUNC_EXIT;
+ return user_state;
}
-int ua_monitor_destroy(ua_monitor_h handle)
+static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
+ ua_user_h user_handle,
+ unsigned int user_sensor_bitmask,
+ char *device_id)
{
FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
-
- ua_monitor_list = g_slist_remove(ua_monitor_list, monitor);
- __ua_free_ua_monitor_t(monitor);
+ /**
+ * Check whether user_handle present or not and also check
+ * whether presence has been started or not.
+ */
+ if (!user_handle || !monitor->presence_user_cb.callback ||
+ !monitor->presence_detection_started) {
+ FUNC_EXIT;
+ return;
+ }
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ UA_DBG("User's sensor bitmask [0x%u], monior presence bitmask AND [0x%u], OR [0x%u]",
+ user_sensor_bitmask,
+ monitor->presence_bitmask_and, monitor->presence_bitmask_or);
-int ua_monitor_set_sensor_state_cb(ua_monitor_h handle,
- ua_monitor_sensor_state_changed_cb callback, void *user_data)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ /**
+ * Check AND conditions for sensors.
+ */
+ if (monitor->presence_bitmask_and !=
+ (user_sensor_bitmask & monitor->presence_bitmask_and)) {
+ FUNC_EXIT;
+ return;
+ }
- UA_VALIDATE_INPUT_PARAMETER(callback);
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ UA_DBG("AND condition matched");
- monitor->sensor_state_cb.callback = callback;
- monitor->sensor_state_cb.user_data = user_data;
+ /**
+ * Check OR conditions for sensors.
+ */
+ if (monitor->presence_bitmask_or &&
+ !(user_sensor_bitmask & monitor->presence_bitmask_or)) {
+ FUNC_EXIT;
+ return;
+ }
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ UA_DBG("OR condition matched");
+ GSList *device_handles = NULL;
+ ua_device_h device_handle;
-int ua_monitor_unset_sensor_state_cb(ua_monitor_h handle)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ if (user_sensor_bitmask & UA_SENSOR_BT) {
+ ua_device_get_by_device_id(device_id,
+ user_sensor_bitmask & UA_SENSOR_BT,
+ &device_handle);
+ device_handles = g_slist_prepend(device_handles, device_handle);
+ }
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ if (user_sensor_bitmask & UA_SENSOR_BLE) {
+ ua_device_get_by_device_id(device_id,
+ user_sensor_bitmask & UA_SENSOR_BLE,
+ &device_handle);
+ device_handles = g_slist_prepend(device_handles, device_handle);
+ }
- monitor->sensor_state_cb.callback = NULL;
- monitor->sensor_state_cb.user_data = NULL;
+ if (user_sensor_bitmask & UA_SENSOR_WIFI) {
+ ua_device_get_by_device_id(device_id,
+ user_sensor_bitmask & UA_SENSOR_WIFI,
+ &device_handle);
+ device_handles = g_slist_prepend(device_handles, device_handle);
+ }
- FUNC_EXIT;
- return UA_ERROR_NONE;
+ ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
+ UA_ERROR_NONE, monitor, user_handle,
+ device_handles,
+ monitor->presence_user_cb.user_data);
+
+ g_slist_free(device_handles);
}
-int ua_monitor_set_user_absence_detected_cb(ua_monitor_h handle,
- ua_absence_user_detected_cb callback, void *user_data)
+static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
+ unsigned int bitmask, char *account, long timestamp, char *device_id)
{
FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- UA_VALIDATE_INPUT_PARAMETER(callback);
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ GSList *l;
+ int found = 0;
+ ua_user_state_info_s *user_state;
+ ret_if(NULL == monitor);
- if (monitor->absence_user_cb.callback != NULL) {
- FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
- }
+ if (account) {
+ for (l = monitor->user_state; l; l = g_slist_next(l)) {
+ user_state = (ua_user_state_info_s *)l->data;
+ UA_DBG("user_state->account [%s] account [%s]", user_state->account, account);
- monitor->absence_user_cb.callback = callback;
- monitor->absence_user_cb.user_data = user_data;
+ if (!g_strcmp0(account, user_state->account)) {
+ UA_DBG("Found!!");
+ found = 1;
+ break;
+ }
+ }
- if (monitor->absence_detection_started && !monitor->internal_presence_started &&
- !monitor->presence_detection_started)
- __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+ if (!found) {
+ user_state = __ua_monitor_user_state_create(account);
+ if (!user_state) {
+ UA_WARN("user_state is invalid");
+ return;
+ }
- __ua_monitor_internal_presence_ref(monitor);
+ monitor->user_state = g_slist_append(monitor->user_state, user_state);
+ }
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
-int ua_monitor_set_user_presence_detected_cb(ua_monitor_h handle,
- ua_presence_user_detected_cb callback, void *user_data)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ _ua_set_user_last_presence_timestamp(user_handle, timestamp);
+ user_state->sensor_bitmask |= bitmask;
- UA_VALIDATE_INPUT_PARAMETER(callback);
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ __ua_monitor_send_user_presence_cb(monitor, user_handle,
+ user_state->sensor_bitmask,
+ device_id);
+ }
- monitor->presence_user_cb.callback = callback;
- monitor->presence_user_cb.user_data = user_data;
+ switch (monitor->presence_mode) {
+ case UA_DETECT_MODE_ALL_SENSOR:
+ /*
+ * Sends presence if it is detected by all sensors irrespective of device/user i.e if
+ * presence will be detected by device 1 for sensor 1 and by device 2 for sensor 2 then
+ * send presence detection callback to application. This will make sure that each sensor is
+ * detected at least one device from registered devices list.
+ */
+ if (((bitmask == UA_SENSOR_BLE) && (monitor->sensor_bitmask & UA_SENSOR_WIFI))
+ || ((bitmask == UA_SENSOR_WIFI) && (monitor->sensor_bitmask & UA_SENSOR_BLE)))
+ monitor->presence_detected_bitmask |= (UA_SENSOR_BLE | UA_SENSOR_WIFI);
+ else
+ monitor->presence_detected_bitmask |= bitmask;
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ UA_INFO("UA_DETECT_MODE_ALL_SENSOR [%d][%d]",
+ bitmask, monitor->presence_detected_bitmask);
-int ua_monitor_unset_user_absence_detected_cb(ua_monitor_h handle)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ break;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ case UA_DETECT_MODE_ANY_SENSOR:
+ if ((monitor->presence_detected_bitmask & bitmask) == 0)
+ if (monitor->presence_cb)
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ bitmask, monitor->user_data);
- if (monitor->absence_user_cb.callback == NULL) {
- FUNC_EXIT;
- return UA_ERROR_NONE;
- }
+ monitor->presence_detected_bitmask |= bitmask;
- monitor->absence_user_cb.callback = NULL;
- monitor->absence_user_cb.user_data = NULL;
+ UA_INFO("UA_DETECT_MODE_ANY_SENSOR [%d][%d]",
+ bitmask, monitor->presence_detected_bitmask);
- __ua_monitor_internal_presence_unref(monitor);
+ break;
- if (!monitor->internal_presence_started && !monitor->presence_detection_started)
- __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+ default:
+ UA_WARN("Unexpected detection mode: %d", monitor->presence_mode);
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_unset_user_presence_detected_cb(ua_monitor_h handle)
+static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
+ ua_user_h user_handle, unsigned int user_sensor_bitmask)
{
FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- monitor->presence_user_cb.callback = NULL;
- monitor->presence_user_cb.user_data = NULL;
+ /**
+ * Check whether user_handle present or not and also check
+ * whether presence has been started or not.
+ */
+ if (!user_handle) {
+ FUNC_EXIT;
+ return;
+ }
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ UA_DBG("User's sensor bitmask [0x%u], monior presence bitmask AND [0x%u], OR [0x%u]",
+ user_sensor_bitmask,
+ monitor->presence_bitmask_and, monitor->presence_bitmask_or);
-int ua_monitor_set_user_presence_condition(ua_monitor_h handle,
- unsigned int bitmask_and,
- unsigned int bitmask_or)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- unsigned int available_sensors;
+ /**
+ * user_sensor_bitmask provides number of detected sensors,
+ * so we need to invert the user_sensor_bitmask to calculate absence.
+ */
+ user_sensor_bitmask = ~user_sensor_bitmask;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- if (bitmask_and & bitmask_or) {
- UA_ERR("AND/OR bitmask same");
+ /**
+ * Check AND conditions for sensors.
+ */
+ if (monitor->absence_bitmask_and !=
+ (user_sensor_bitmask & monitor->absence_bitmask_and)) {
FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
+ return;
}
- _uam_get_available_sensors(&available_sensors);
-
- if (bitmask_and != (available_sensors & bitmask_and)) {
- UA_ERR("AND bitmask out of range");
- FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
- }
+ UA_DBG("AND condition matched");
- if (bitmask_or != (available_sensors & bitmask_or)) {
- UA_ERR("OR bitmask out of range");
+ /**
+ * Check OR conditions for sensors.
+ */
+ if (monitor->absence_bitmask_or &&
+ !(user_sensor_bitmask & monitor->absence_bitmask_or)) {
FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
+ return;
}
- monitor->presence_bitmask_and = bitmask_and;
- monitor->presence_bitmask_or = bitmask_or;
+ UA_DBG("OR condition matched");
- FUNC_EXIT;
- return UA_ERROR_NONE;
+ ((ua_absence_user_detected_cb)monitor->absence_user_cb.callback)(
+ UA_ERROR_NONE, monitor, user_handle,
+ monitor->absence_user_cb.user_data);
}
-int ua_monitor_set_user_absence_condition(ua_monitor_h handle,
- unsigned int bitmask_and,
- unsigned int bitmask_or)
+static void __ua_send_absence_detection()
{
FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- unsigned int available_sensors;
+ GSList *l;
+ GSList *l1;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
- if (bitmask_and & bitmask_or) {
- UA_ERR("AND/OR bitmask same");
- FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
- }
+ if (!monitor)
+ continue;
- _uam_get_available_sensors(&available_sensors);
+ UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
+ monitor->sensor_bitmask, monitor->absence_detected_bitmask);
- if (bitmask_and != (available_sensors & bitmask_and)) {
- UA_ERR("AND bitmask out of range");
- FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
- }
+ if (monitor->absence_mode == UA_DETECT_MODE_ALL_SENSOR) {
+ if (monitor->sensor_bitmask & UA_SENSOR_BLE) {
+ if (__ua_check_all_users_absence_state(monitor->user_state, UA_SENSOR_BLE))
+ monitor->absence_detected_bitmask |= UA_SENSOR_BLE;
+ }
- if (bitmask_or != (available_sensors & bitmask_or)) {
- UA_ERR("OR bitmask out of range");
- FUNC_EXIT;
- return UA_ERROR_INVALID_PARAMETER;
- }
+ if (monitor->sensor_bitmask & UA_SENSOR_WIFI) {
+ if (__ua_check_all_users_absence_state(monitor->user_state, UA_SENSOR_WIFI))
+ monitor->absence_detected_bitmask |= UA_SENSOR_WIFI;
+ }
- monitor->absence_bitmask_and = bitmask_and;
- monitor->absence_bitmask_or = bitmask_or;
+ UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
+ monitor->sensor_bitmask, monitor->absence_detected_bitmask);
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_monitor_add_sensor(
- ua_monitor_h handle,
- ua_sensor_e sensor_type)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- unsigned int bitmask;
- unsigned int available_sensors = 0;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ if (monitor->sensor_bitmask == monitor->absence_detected_bitmask) {
+ if (monitor->absence_cb)
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ UA_SENSOR_MAX, monitor->user_data);
+ }
+ }
- retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOT_PERMITTED);
- retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOT_PERMITTED);
+ monitor->absence_detected_bitmask = 0;
- bitmask = __ua_sensor_type_to_bitmask(sensor_type);
- retv_if(0 != (monitor->sensor_bitmask & bitmask), UA_ERROR_ALREADY_DONE);
+ if (!monitor->absence_user_cb.callback)
+ continue;
- if (UA_ERROR_NONE != _ua_get_error_code(
- _uam_get_available_sensors(&available_sensors)))
- UA_WARN("_uam_get_available_sensors failed"); // LCOV_EXCL_LINE
+ for (l1 = monitor->user_state; NULL != l1; l1 = g_slist_next(l1)) {
+ ua_user_state_info_s *user_state = l1->data;
- retv_if(0 == (available_sensors & bitmask), UA_ERROR_NOT_READY);
+ UA_INFO("Scanning user list...");
+ if (!user_state)
+ continue;
- monitor->sensor_bitmask |= bitmask;
+ ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
+ __ua_monitor_send_user_absence_cb(monitor, user_handle,
+ user_state->sensor_bitmask);
+ }
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_remove_sensor(
- ua_monitor_h handle,
- ua_sensor_e sensor_type)
+static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
+ unsigned int bitmask, char *account)
{
FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- unsigned int bitmask;
+ ua_sensor_e sensor_type;
+ bool all_absence;
+ GSList *l;
+ int found = 0;
+ ua_user_state_info_s *user_state = NULL;
+ sensor_type = __ua_sensor_bitmask_to_type(bitmask);
+ ret_if(NULL == monitor);
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ if (account) {
+ for (l = monitor->user_state; l; l = g_slist_next(l)) {
+ user_state = (ua_user_state_info_s *)l->data;
- retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOT_PERMITTED);
- retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOT_PERMITTED);
+ if (!g_strcmp0(account, user_state->account)) {
+ found = 1;
+ break;
+ }
+ }
- bitmask = __ua_sensor_type_to_bitmask(sensor_type);
- retv_if(0 == (monitor->sensor_bitmask & bitmask), UA_ERROR_ALREADY_DONE);
+ if (!found) {
+ user_state = __ua_monitor_user_state_create(account);
- monitor->sensor_bitmask &= ~bitmask;
+ if (!user_state)
+ return;
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ monitor->user_state = g_slist_append(monitor->user_state, user_state);
+ }
-int ua_monitor_foreach_sensor(
- ua_monitor_h handle,
- ua_monitor_foreach_sensor_cb foreach_cb,
- void *user_data)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- unsigned int bitmask;
- int sensor;
+ user_state->sensor_bitmask &= ~bitmask;
+ }
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ switch (monitor->absence_mode) {
+ case UA_DETECT_MODE_ALL_SENSOR:
+ if (!account)
+ monitor->absence_detected_bitmask |= bitmask;
- bitmask = monitor->sensor_bitmask;
+ break;
+ case UA_DETECT_MODE_ANY_SENSOR:
+ /* First add user info to local users list and then invoke callback */
+ if (account) {
+ all_absence = __ua_check_all_users_absence_state(monitor->user_state, bitmask);
- for (sensor = UA_SENSOR_BT; sensor < UA_SENSOR_MAX; sensor <<= 1) {
- if (bitmask & sensor) {
- bitmask &= ~sensor;
- if (!foreach_cb(sensor, user_data))
- break;
+ if (all_absence) {
+ if (monitor->absence_cb)
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, monitor->user_data);
+ }
+ } else {
+ if (monitor->absence_cb)
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, monitor->user_data);
}
+ break;
+
+ default:
+ UA_WARN("Unexpected detection mode: %d", monitor->absence_mode);
}
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_start_scan_devices(
- ua_monitor_h handle,
- int scan_time,
- ua_scan_completed_cb callback,
- void *user_data)
+void _ua_monitor_handle_scanned_device(int result, uam_device_info_s *uam_info)
{
FUNC_ENTRY;
- int ret;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ ua_dev_info_s *dev = NULL;
+ ua_monitor_s *monitor = scanning_monitor;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- UA_VALIDATE_INPUT_PARAMETER(callback);
- retv_if(scan_time <= 0, UA_ERROR_INVALID_PARAMETER);
- retv_if(scanning_monitor != NULL, UA_ERROR_NOT_PERMITTED);
- retv_if(TRUE == monitor->scan_device_started, UA_ERROR_NOW_IN_PROGRESS);
- retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_DATA);
+ result = _ua_get_error_code(result);
+ if (UA_ERROR_NONE != result)
+ return;
- scan_time *= UA_SCAN_TIME_MULTIPLIER; /* scan_time converted into seconds */
+ UA_INFO("Mobile id[%s] Mac[%s]", uam_info->device_id, uam_info->mac);
- ret = _ua_get_error_code(_uam_start_search_active_devices(monitor->sensor_bitmask, scan_time));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
+ dev = _ua_get_device_info_from_uam(uam_info);
+
+ if (dev == NULL) {
+ UA_WARN("Unexpected, cannot find uam_device");
+ return;
}
- monitor->scan_device_cb = callback;
- monitor->user_data = user_data;
- monitor->scan_device_started = TRUE;
- scanning_monitor = monitor;
+ if (monitor && monitor->scan_device_cb) {
+ ((ua_scan_completed_cb)monitor->scan_device_cb)(
+ UA_ACTIVE_SCAN_TYPE_DEVICE_FOUND, monitor, dev, monitor->user_data);
+ UA_PRINT_DEVICE_HANDLE(dev);
+ UA_INFO("Invoked scan_device_cb callback");
+ } else {
+ UA_WARN("Unexpected, scan started but callbacks are NULL");
+ }
+ _ua_free_ua_device_info_t((gpointer)dev);
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_cancel_scan_devices(ua_monitor_h handle)
+void _ua_monitor_handle_scan_complete(int result)
{
FUNC_ENTRY;
- int ret;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ ua_monitor_s *monitor = scanning_monitor;
+ result = _ua_get_error_code(result);
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- retv_if(FALSE == monitor->scan_device_started, UA_ERROR_NOT_IN_PROGRESS);
+ if (UA_ERROR_NONE != result)
+ return;
- ret = _ua_get_error_code(_uam_stop_search_active_devices(monitor->sensor_bitmask));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
+ if (monitor && monitor->scan_device_cb) {
+ ((ua_scan_completed_cb)monitor->scan_device_cb)(
+ UA_ACTIVE_SCAN_TYPE_COMPLETED, monitor, NULL, monitor->user_data);
+ UA_INFO("Invoked scan_device_cb callback");
+
+ /* Reset callback when scan complete*/
+ monitor->scan_device_cb = NULL;
+ monitor->user_data = NULL;
+ monitor->scan_device_started = FALSE;
+ scanning_monitor = NULL;
+ } else {
+ UA_WARN("Unexpected, scan running but callbacks are NULL");
}
- monitor->scan_device_cb = NULL;
- monitor->user_data = NULL;
- monitor->scan_device_started = FALSE;
- scanning_monitor = NULL;
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-static int __ua_start_monitoring(unsigned int bitmask, char *service, ua_detection_type_e detect)
+void _ua_monitor_handle_user_presence_detected(unsigned int bitmask,
+ char *service, char *account, long timestamp, char *device_id)
{
FUNC_ENTRY;
- int ret;
+ GSList *l;
- if (detect == UA_PRESENCE_DETECTION) {
- ret = _ua_get_error_code(_uam_start_presence_detection(bitmask, service));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_ua_start_presence_detection failed with %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
- } else if (detect == UA_ABSENCE_DETECTION) {
- ret = _ua_get_error_code(_uam_start_absence_detection(bitmask, service));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_ua_start_absence_detection failed with %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
+
+ if (!monitor || (!monitor->presence_detection_started && !monitor->internal_presence_started))
+ continue;
+
+ if (0 == (bitmask & monitor->sensor_bitmask))
+ continue;
+
+ if (!service || !g_strcmp0(service, monitor->service)) {
+ /* Presence detection ongoing */
+ __ua_sensor_presence_detected(monitor, bitmask, account,
+ timestamp, device_id);
}
- } else
- UA_ERR("invalid detection type");
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_start_presence_detection(
- ua_monitor_h handle,
- ua_service_h service_handle,
- ua_detection_mode_e mode,
- ua_presence_detected_cb callback,
- void *user_data)
+void _ua_monitor_handle_user_absence_detected(unsigned int bitmask,
+ char *service, char *account)
{
FUNC_ENTRY;
- int ret;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- ua_service_info_s *service_info = (ua_service_info_s *)service_handle;
- ua_detection_type_e detect = UA_PRESENCE_DETECTION;
- char *service;
- GSList *ua_services_list = _ua_service_get_services();
+ GSList *l;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOW_IN_PROGRESS);
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
- if (service_handle) {
- UA_VALIDATE_HANDLE(service_handle, ua_services_list);
- service = g_strdup(service_info->name);
- } else
- service = NULL;
-
- if (monitor->service)
- if ((service && g_strcmp0(monitor->service, service)) ||
- (!service && g_strcmp0(monitor->service, UA_SERVICE_DEFAULT))) {
- g_free(service);
- return UA_ERROR_NOT_PERMITTED;
- }
+ if (!monitor || !monitor->absence_detection_started)
+ continue;
- if (UA_DETECT_MODE_INVALID <= mode) {
- g_free(service);
- return UA_ERROR_INVALID_PARAMETER;
- }
- if (0 == monitor->sensor_bitmask) {
- g_free(service);
- return UA_ERROR_NO_DATA;
- }
+ if (0 == (bitmask & monitor->sensor_bitmask))
+ continue;
- if (!monitor->service) {
- if (service == NULL)
- monitor->service = g_strndup(UA_SERVICE_DEFAULT, UA_MAX_SERVICE_LEN);
- else
- monitor->service = g_strndup(service, UA_MAX_SERVICE_LEN);
- }
- /**
- * TODO: Check if we have to check is_sensor_ready at this point and remove sensor
- * from monitor if sensor is not ready
- */
- if (!monitor->internal_presence_started || !monitor->absence_detection_started) {
- ret = __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, detect);
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- g_free(service);
- return ret;
- /* LCOV_EXCL_STOP */
+ if (!service || !g_strcmp0(service, monitor->service)) {
+ /* Absence detection ongoing */
+ __ua_sensor_absence_detected(monitor, bitmask, account);
}
}
- monitor->presence_mode = mode;
- monitor->presence_cb = callback;
- monitor->user_data = user_data;
- monitor->presence_detection_started = TRUE;
+ FUNC_EXIT;
+}
- g_free(service);
+void _ua_monitor_handle_detection_stopped()
+{
+ FUNC_ENTRY;
+
+ __ua_send_presence_detection();
+ __ua_send_absence_detection();
+ __ua_user_state_clean();
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_start_absence_detection(
- ua_monitor_h handle,
- ua_service_h service_handle,
- ua_detection_mode_e mode,
- ua_absence_detected_cb callback,
- void *user_data)
+#if 0
+static void __ua_remove_sensor(ua_monitor_s *monitor, ua_sensor_e sensor_type)
{
FUNC_ENTRY;
int ret;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- ua_service_info_s *service_info = (ua_service_info_s *)service_handle;
- ua_detection_type_e detect = UA_ABSENCE_DETECTION;
- char *service;
- GSList *ua_services_list = _ua_service_get_services();
+ int is_presence = 0;
+ int is_absence = 0;
+ void *presence_callback = NULL;
+ void *presence_user_data = NULL;
+ void *absence_callback = NULL;
+ void *absence_user_data = NULL;
+ ua_detection_mode_e mode_presence;
+ ua_detection_mode_e mode_absence;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOW_IN_PROGRESS);
+ if (monitor->presence_detection_started) {
+ /* Stop detection first */
+ if (monitor->presence_cb) {
+ /* Presence detection ongoing */
+ presence_callback = monitor->presence_cb;
+ presence_user_data = monitor->user_data;
+ mode_presence = monitor->presence_mode;
- if (service_handle) {
- UA_VALIDATE_HANDLE(service_handle, ua_services_list);
- service = g_strdup(service_info->name);
- } else
- service = NULL;
+ ret = ua_monitor_stop_presence_detection(monitor);
+ UA_INFO("ua_monitor_stop_presence_detection returned %s",
+ _ua_get_error_string(ret));
- if (monitor->service)
- if ((service && g_strcmp0(monitor->service, service)) ||
- (!service && g_strcmp0(monitor->service, UA_SERVICE_DEFAULT))) {
- g_free(service);
- return UA_ERROR_NOT_PERMITTED;
+ is_presence = 1;
+ } else {
+ UA_WARN("Unexpected, detection started but cbs are NULL");
}
-
- retv_if(UA_DETECT_MODE_INVALID <= mode, UA_ERROR_INVALID_PARAMETER);
- retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_DATA);
-
- if (!monitor->service) {
- if (service == NULL)
- monitor->service = g_strndup(UA_SERVICE_DEFAULT, UA_MAX_SERVICE_LEN);
- else
- monitor->service = g_strndup(service, UA_MAX_SERVICE_LEN);
}
- /* TODO: Check if we have to check is_sensor_ready at this point and remove sensor
- * from monitor if sensor is not ready.
- */
- ret = __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, detect);
+ if (monitor->absence_detection_started) {
+ /* Stop detection first */
+ if (monitor->absence_cb) {
+ /* absence detection ongoing */
+ absence_callback = monitor->absence_cb;
+ absence_user_data = monitor->user_data;
+ mode_absence = monitor->absence_mode;
- if (mode == UA_DETECT_MODE_ALL_SENSOR)
- __ua_monitor_internal_presence_ref(monitor);
+ ret = ua_monitor_stop_presence_detection(monitor);
+ UA_INFO("ua_monitor_stop_presence_detection returned %s",
+ _ua_get_error_string(ret));
- if (monitor->internal_presence_started)
- if (!monitor->presence_detection_started)
- __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+ is_absence = 1;
+ } else {
+ UA_WARN("Unexpected, detection started but cbs are NULL");
+ }
+ }
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- g_free(service);
- return ret;
- /* LCOV_EXCL_STOP */
+ if (is_presence || is_absence) {
+ ret = ua_monitor_remove_sensor(monitor, sensor_type);
+ UA_INFO("ua_monitor_remove_sensor returned %s",
+ _ua_get_error_string(ret));
}
- monitor->absence_mode = mode;
- monitor->absence_cb = callback;
- monitor->user_data = user_data;
- monitor->absence_detection_started = TRUE;
+ if (0 != monitor->sensor_bitmask) {
+ if (is_presence) {
+ ret = ua_monitor_start_presence_detection(
+ monitor, monitor->service, mode_presence, presence_callback, presence_user_data);
+ UA_INFO("ua_monitor_start_presence_detection returned %s",
+ _ua_get_error_string(ret));
+ }
- g_free(service);
+ if (is_absence) {
+ ret = ua_monitor_start_absence_detection(
+ monitor, monitor->service, mode_absence, absence_callback, absence_user_data);
+ UA_INFO("ua_monitor_start_absence_detection returned %s",
+ _ua_get_error_string(ret));
+ }
+ }
+
+ if (!is_presence && !is_absence) {
+ /* Monitoring is already stopped, just remove sensor from monitor */
+ ret = ua_monitor_remove_sensor(monitor, sensor_type);
+ UA_INFO("ua_monitor_remove_sensor returned %s",
+ _ua_get_error_string(ret));
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
+#endif
-static int __ua_stop_monitoring(unsigned int bitmask, char *service, ua_detection_type_e detect)
+void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready)
{
FUNC_ENTRY;
- int ret;
+ ua_sensor_e sensor_type;
+ GSList *l;
- if (detect == UA_PRESENCE_DETECTION) {
- ret = _ua_get_error_code(_uam_stop_presence_detection(bitmask, service));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_ua_stop_presence_detection failed with %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
- } else if (detect == UA_ABSENCE_DETECTION) {
- ret = _ua_get_error_code(_uam_stop_absence_detection(bitmask, service));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_ua_stop_presence_detection failed with %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
- } else
- UA_ERR("invalid detection type");
+ sensor_type = __ua_sensor_bitmask_to_type(bitmask);
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
+ if (!monitor)
+ continue;
+
+ if (monitor->sensor_state_cb.callback)
+ ((ua_monitor_sensor_state_changed_cb)monitor->sensor_state_cb.callback)(
+ (bool)ready, sensor_type, (ua_monitor_h)monitor,
+ monitor->sensor_state_cb.user_data);
+ }
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_stop_presence_detection(ua_monitor_h handle)
+void _ua_free_ua_monitor_t(gpointer data)
{
FUNC_ENTRY;
- int ret;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- ua_detection_type_e detect = UA_PRESENCE_DETECTION;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- retv_if(FALSE == monitor->presence_detection_started, UA_ERROR_NOT_IN_PROGRESS);
+ ua_monitor_s *monitor = data;
+ ret_if(NULL == monitor);
- if (!monitor->internal_presence_started || !monitor->absence_detection_started) {
- ret = __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, detect);
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
+ if (monitor->presence_detection_timer) {
+ /* LCOV_EXCL_START */
+ g_source_remove(monitor->presence_detection_timer);
+ monitor->presence_detection_timer = 0;
+ /* LCOV_EXCL_STOP */
}
- monitor->presence_mode = UA_DETECT_MODE_INVALID;
- monitor->presence_cb = NULL;
- monitor->user_data = NULL;
- monitor->presence_detection_started = FALSE;
- g_slist_free_full(monitor->user_state, _ua_free_user_state_info_t);
- monitor->user_state = NULL;
-
- if (!monitor->absence_detection_started) {
- g_free(monitor->service);
- monitor->service = NULL;
+ if (monitor->absence_detection_timer) {
+ /* LCOV_EXCL_START */
+ g_source_remove(monitor->absence_detection_timer);
+ monitor->absence_detection_timer = 0;
+ /* LCOV_EXCL_STOP */
}
+ /* One monitor can observe only one service. */
+ g_free(monitor->service);
+ /* Free user-state information */
+ g_slist_free_full(monitor->user_state, __ua_free_user_state_info_t);
+ g_free(monitor);
+
FUNC_EXIT;
- return UA_ERROR_NONE;
}
-int ua_monitor_stop_absence_detection(ua_monitor_h handle)
+int ua_monitor_is_sensor_available(
+ ua_sensor_e sensor,
+ bool *available
+ )
{
FUNC_ENTRY;
+ unsigned int available_sensors = 0;
int ret;
- ua_monitor_s *monitor = (ua_monitor_s *)handle;
- ua_detection_type_e detect = UA_ABSENCE_DETECTION;
+ unsigned int bitmask;
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- retv_if(FALSE == monitor->absence_detection_started, UA_ERROR_NOT_IN_PROGRESS);
- retv_if(NULL == monitor->absence_cb, UA_ERROR_NOT_IN_PROGRESS);
+ UA_VALIDATE_INPUT_PARAMETER(available);
- ret = __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, detect);
+ bitmask = __ua_sensor_type_to_bitmask(sensor);
+ retv_if(!bitmask, UA_ERROR_INVALID_PARAMETER);
+
+ ret = _ua_get_error_code(_uam_get_available_sensors(&available_sensors));
if (UA_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
+ UA_ERR("_uam_get_available_sensors failed");
return ret;
/* LCOV_EXCL_STOP */
}
- if (!monitor->presence_detection_started)
- __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+ if (0 == (available_sensors & bitmask))
+ *available = false; // LCOV_EXCL_LINE
+ else
+ *available = true;
- if (monitor->absence_mode == UA_DETECT_MODE_ALL_SENSOR)
- __ua_monitor_internal_presence_unref(monitor);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- monitor->absence_mode = UA_DETECT_MODE_INVALID;
- monitor->absence_cb = NULL;
- monitor->user_data = NULL;
- monitor->absence_detection_started = FALSE;
+int ua_set_app_info(const char *app_id, unsigned short uid)
+{
+ FUNC_ENTRY;
- if (!monitor->presence_detection_started) {
- g_free(monitor->service);
- monitor->service = NULL;
+ UA_VALIDATE_INPUT_PARAMETER(app_id);
+
+ int ret = _ua_get_error_code(_uam_register_app(app_id, uid));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_uam_register_app failed");
+ return ret;
+ /* LCOV_EXCL_STOP */
}
FUNC_EXIT;
return UA_ERROR_NONE;
}
-static void __ua_user_state_clean()
+int ua_unset_app_info(const char *app_id, unsigned short uid)
{
FUNC_ENTRY;
- GSList *l;
-
- for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
- if (!monitor)
- continue;
+ UA_VALIDATE_INPUT_PARAMETER(app_id);
- g_slist_free_full(monitor->user_state, _ua_free_user_state_info_t);
- monitor->user_state = NULL;
+ int ret = _ua_get_error_code(_uam_deregister_app(app_id, uid));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("_uam_deregister_app failed");
+ return ret;
+ /* LCOV_EXCL_STOP */
}
+
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static bool _ua_check_all_users_absence_state(GSList *user_state, unsigned int bitmask)
+int ua_monitor_create(ua_monitor_h *handle)
{
FUNC_ENTRY;
- GSList *l;
- ua_user_state_info_s *u;
- for (l = user_state; l; l = g_slist_next(l)) {
- u = (ua_user_state_info_s *)l->data;
+ ua_monitor_s *monitor = NULL;
+ unsigned int available_sensors;
- if (u->sensor_bitmask & bitmask) {
- UA_INFO("User found [%s]", u->account);
- return false;
- }
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+
+ monitor = g_malloc0(sizeof(ua_monitor_s));
+ if (!monitor) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
}
- return true;
+ /* Add monitor to list of monitors */
+ ua_monitor_list = g_slist_append(ua_monitor_list, monitor);
+
+ _uam_get_available_sensors(&available_sensors);
+
+ monitor->presence_bitmask_and = 0;
+ monitor->presence_bitmask_or = (available_sensors & UA_SENSOR_BLE) | (available_sensors & UA_SENSOR_WIFI);
+ monitor->absence_bitmask_and = (available_sensors & UA_SENSOR_BLE) | (available_sensors & UA_SENSOR_WIFI);
+ monitor->absence_bitmask_or = 0;
+
+ *handle = (ua_monitor_h)monitor;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static void __ua_send_presence_detection()
+int ua_monitor_destroy(ua_monitor_h handle)
{
FUNC_ENTRY;
- GSList *l;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- if (!monitor)
- continue;
+ ua_monitor_list = g_slist_remove(ua_monitor_list, monitor);
- if (monitor->presence_mode == UA_DETECT_MODE_ANY_SENSOR) {
- monitor->presence_detected_bitmask = 0;
- continue;
- }
+ _ua_free_ua_monitor_t(monitor);
- UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
- monitor->sensor_bitmask, monitor->absence_detected_bitmask);
- if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) {
- if (monitor->presence_cb)
- monitor->presence_cb(UA_ERROR_NONE, monitor,
- UA_SENSOR_MAX, monitor->user_data);
- }
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- monitor->presence_detected_bitmask = 0;
- }
+int ua_monitor_set_sensor_state_cb(ua_monitor_h handle,
+ ua_monitor_sensor_state_changed_cb callback, void *user_data)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(callback);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->sensor_state_cb.callback = callback;
+ monitor->sensor_state_cb.user_data = user_data;
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static ua_user_state_info_s* __ua_monitor_user_state_create(char *account)
+int ua_monitor_unset_sensor_state_cb(ua_monitor_h handle)
{
- ua_user_state_info_s *user_state;
-
- user_state = g_malloc0(sizeof(ua_user_state_info_s));
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- if (!user_state) {
- UA_ERR("g_malloc0 failed");
- return NULL;
- }
- user_state->account = g_strdup(account);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- if (user_state->account == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_user_state_info_t((gpointer)user_state);
- return NULL;
- }
+ monitor->sensor_state_cb.callback = NULL;
+ monitor->sensor_state_cb.user_data = NULL;
- return user_state;
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
- ua_user_h user_handle,
- unsigned int user_sensor_bitmask,
- char *device_id)
+int ua_monitor_set_user_absence_detected_cb(ua_monitor_h handle,
+ ua_absence_user_detected_cb callback, void *user_data)
{
FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- /**
- * Check whether user_handle present or not and also check
- * whether presence has been started or not.
- */
- if (!user_handle || !monitor->presence_user_cb.callback ||
- !monitor->presence_detection_started) {
- FUNC_EXIT;
- return;
- }
-
- UA_DBG("User's sensor bitmask [0x%u], monior presence bitmask AND [0x%u], OR [0x%u]",
- user_sensor_bitmask,
- monitor->presence_bitmask_and, monitor->presence_bitmask_or);
+ UA_VALIDATE_INPUT_PARAMETER(callback);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- /**
- * Check AND conditions for sensors.
- */
- if (monitor->presence_bitmask_and !=
- (user_sensor_bitmask & monitor->presence_bitmask_and)) {
+ if (monitor->absence_user_cb.callback != NULL) {
FUNC_EXIT;
- return;
+ return UA_ERROR_INVALID_PARAMETER;
}
- UA_DBG("AND condition matched");
+ monitor->absence_user_cb.callback = callback;
+ monitor->absence_user_cb.user_data = user_data;
- /**
- * Check OR conditions for sensors.
- */
- if (monitor->presence_bitmask_or &&
- !(user_sensor_bitmask & monitor->presence_bitmask_or)) {
- FUNC_EXIT;
- return;
- }
+ if (monitor->absence_detection_started && !monitor->internal_presence_started &&
+ !monitor->presence_detection_started)
+ __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
- UA_DBG("OR condition matched");
- GSList *device_handles = NULL;
- ua_device_h device_handle;
+ __ua_monitor_internal_presence_ref(monitor);
- if (user_sensor_bitmask & UA_SENSOR_BT) {
- ua_device_get_by_device_id(device_id,
- user_sensor_bitmask & UA_SENSOR_BT,
- &device_handle);
- device_handles = g_slist_prepend(device_handles, device_handle);
- }
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- if (user_sensor_bitmask & UA_SENSOR_BLE) {
- ua_device_get_by_device_id(device_id,
- user_sensor_bitmask & UA_SENSOR_BLE,
- &device_handle);
- device_handles = g_slist_prepend(device_handles, device_handle);
- }
+int ua_monitor_set_user_presence_detected_cb(ua_monitor_h handle,
+ ua_presence_user_detected_cb callback, void *user_data)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- if (user_sensor_bitmask & UA_SENSOR_WIFI) {
- ua_device_get_by_device_id(device_id,
- user_sensor_bitmask & UA_SENSOR_WIFI,
- &device_handle);
- device_handles = g_slist_prepend(device_handles, device_handle);
- }
+ UA_VALIDATE_INPUT_PARAMETER(callback);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
- UA_ERROR_NONE, monitor, user_handle,
- device_handles,
- monitor->presence_user_cb.user_data);
+ monitor->presence_user_cb.callback = callback;
+ monitor->presence_user_cb.user_data = user_data;
- g_slist_free(device_handles);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
- unsigned int bitmask, char *account,
- long timestamp, char *device_id)
+int ua_monitor_unset_user_absence_detected_cb(ua_monitor_h handle)
{
FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- GSList *l;
- int found = 0;
- ua_user_state_info_s *user_state;
- ret_if(NULL == monitor);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- if (account) {
- for (l = monitor->user_state; l; l = g_slist_next(l)) {
- user_state = (ua_user_state_info_s *)l->data;
- UA_DBG("user_state->account [%s] account [%s]", user_state->account, account);
+ if (monitor->absence_user_cb.callback == NULL) {
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+ }
- if (!g_strcmp0(account, user_state->account)) {
- UA_DBG("Found!!");
- found = 1;
- break;
- }
- }
+ monitor->absence_user_cb.callback = NULL;
+ monitor->absence_user_cb.user_data = NULL;
- if (!found) {
- user_state = __ua_monitor_user_state_create(account);
- if (!user_state) {
- UA_WARN("user_state is invalid");
- return;
- }
+ __ua_monitor_internal_presence_unref(monitor);
- monitor->user_state = g_slist_append(monitor->user_state, user_state);
- }
+ if (!monitor->internal_presence_started && !monitor->presence_detection_started)
+ __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
- ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- _ua_set_user_last_presence_timestamp(user_handle, timestamp);
- user_state->sensor_bitmask |= bitmask;
+int ua_monitor_unset_user_presence_detected_cb(ua_monitor_h handle)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- __ua_monitor_send_user_presence_cb(monitor, user_handle,
- user_state->sensor_bitmask,
- device_id);
- }
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- switch (monitor->presence_mode) {
- case UA_DETECT_MODE_ALL_SENSOR:
- /*
- * Sends presence if it is detected by all sensors irrespective of device/user i.e if
- * presence will be detected by device 1 for sensor 1 and by device 2 for sensor 2 then
- * send presence detection callback to application. This will make sure that each sensor is
- * detected at least one device from registered devices list.
- */
- if (((bitmask == UA_SENSOR_BLE) && (monitor->sensor_bitmask & UA_SENSOR_WIFI))
- || ((bitmask == UA_SENSOR_WIFI) && (monitor->sensor_bitmask & UA_SENSOR_BLE)))
- monitor->presence_detected_bitmask |= (UA_SENSOR_BLE | UA_SENSOR_WIFI);
- else
- monitor->presence_detected_bitmask |= bitmask;
+ monitor->presence_user_cb.callback = NULL;
+ monitor->presence_user_cb.user_data = NULL;
- UA_INFO("UA_DETECT_MODE_ALL_SENSOR [%d][%d]",
- bitmask, monitor->presence_detected_bitmask);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- break;
+int ua_monitor_set_user_presence_condition(ua_monitor_h handle,
+ unsigned int bitmask_and,
+ unsigned int bitmask_or)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ unsigned int available_sensors;
- case UA_DETECT_MODE_ANY_SENSOR:
- if ((monitor->presence_detected_bitmask & bitmask) == 0)
- if (monitor->presence_cb)
- monitor->presence_cb(UA_ERROR_NONE, monitor,
- bitmask, monitor->user_data);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- monitor->presence_detected_bitmask |= bitmask;
+ if (bitmask_and & bitmask_or) {
+ UA_ERR("AND/OR bitmask same");
+ FUNC_EXIT;
+ return UA_ERROR_INVALID_PARAMETER;
+ }
- UA_INFO("UA_DETECT_MODE_ANY_SENSOR [%d][%d]",
- bitmask, monitor->presence_detected_bitmask);
+ _uam_get_available_sensors(&available_sensors);
- break;
+ if (bitmask_and != (available_sensors & bitmask_and)) {
+ UA_ERR("AND bitmask out of range");
+ FUNC_EXIT;
+ return UA_ERROR_INVALID_PARAMETER;
+ }
- default:
- UA_WARN("Unexpected detection mode: %d", monitor->presence_mode);
+ if (bitmask_or != (available_sensors & bitmask_or)) {
+ UA_ERR("OR bitmask out of range");
+ FUNC_EXIT;
+ return UA_ERROR_INVALID_PARAMETER;
}
+ monitor->presence_bitmask_and = bitmask_and;
+ monitor->presence_bitmask_or = bitmask_or;
+
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
- ua_user_h user_handle,
- unsigned int user_sensor_bitmask)
+int ua_monitor_set_user_absence_condition(ua_monitor_h handle,
+ unsigned int bitmask_and,
+ unsigned int bitmask_or)
{
FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ unsigned int available_sensors;
- /**
- * Check whether user_handle present or not and also check
- * whether presence has been started or not.
- */
- if (!user_handle) {
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ if (bitmask_and & bitmask_or) {
+ UA_ERR("AND/OR bitmask same");
FUNC_EXIT;
- return;
+ return UA_ERROR_INVALID_PARAMETER;
}
- UA_DBG("User's sensor bitmask [0x%u], monior presence bitmask AND [0x%u], OR [0x%u]",
- user_sensor_bitmask,
- monitor->presence_bitmask_and, monitor->presence_bitmask_or);
-
- /**
- * user_sensor_bitmask provides number of detected sensors,
- * so we need to invert the user_sensor_bitmask to calculate absence.
- */
- user_sensor_bitmask = ~user_sensor_bitmask;
-
+ _uam_get_available_sensors(&available_sensors);
- /**
- * Check AND conditions for sensors.
- */
- if (monitor->absence_bitmask_and !=
- (user_sensor_bitmask & monitor->absence_bitmask_and)) {
+ if (bitmask_and != (available_sensors & bitmask_and)) {
+ UA_ERR("AND bitmask out of range");
FUNC_EXIT;
- return;
+ return UA_ERROR_INVALID_PARAMETER;
}
- UA_DBG("AND condition matched");
-
- /**
- * Check OR conditions for sensors.
- */
- if (monitor->absence_bitmask_or &&
- !(user_sensor_bitmask & monitor->absence_bitmask_or)) {
+ if (bitmask_or != (available_sensors & bitmask_or)) {
+ UA_ERR("OR bitmask out of range");
FUNC_EXIT;
- return;
+ return UA_ERROR_INVALID_PARAMETER;
}
- UA_DBG("OR condition matched");
+ monitor->absence_bitmask_and = bitmask_and;
+ monitor->absence_bitmask_or = bitmask_or;
- ((ua_absence_user_detected_cb)monitor->absence_user_cb.callback)(
- UA_ERROR_NONE, monitor, user_handle,
- monitor->absence_user_cb.user_data);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static void __ua_send_absence_detection()
+int ua_monitor_add_sensor(
+ ua_monitor_h handle,
+ ua_sensor_e sensor_type)
{
FUNC_ENTRY;
- GSList *l;
- GSList *l1;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ unsigned int bitmask;
+ unsigned int available_sensors = 0;
- for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- if (!monitor)
- continue;
+ retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOT_PERMITTED);
+ retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOT_PERMITTED);
- UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
- monitor->sensor_bitmask, monitor->absence_detected_bitmask);
+ bitmask = __ua_sensor_type_to_bitmask(sensor_type);
+ retv_if(0 != (monitor->sensor_bitmask & bitmask), UA_ERROR_ALREADY_DONE);
- if (monitor->absence_mode == UA_DETECT_MODE_ALL_SENSOR) {
- if (monitor->sensor_bitmask & UA_SENSOR_BLE) {
- if (_ua_check_all_users_absence_state(monitor->user_state, UA_SENSOR_BLE))
- monitor->absence_detected_bitmask |= UA_SENSOR_BLE;
- }
+ if (UA_ERROR_NONE != _ua_get_error_code(
+ _uam_get_available_sensors(&available_sensors)))
+ UA_WARN("_uam_get_available_sensors failed"); // LCOV_EXCL_LINE
- if (monitor->sensor_bitmask & UA_SENSOR_WIFI) {
- if (_ua_check_all_users_absence_state(monitor->user_state, UA_SENSOR_WIFI))
- monitor->absence_detected_bitmask |= UA_SENSOR_WIFI;
- }
+ retv_if(0 == (available_sensors & bitmask), UA_ERROR_NOT_READY);
- UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
- monitor->sensor_bitmask, monitor->absence_detected_bitmask);
+ monitor->sensor_bitmask |= bitmask;
- if (monitor->sensor_bitmask == monitor->absence_detected_bitmask) {
- if (monitor->absence_cb)
- monitor->absence_cb(UA_ERROR_NONE, monitor,
- UA_SENSOR_MAX, monitor->user_data);
- }
- }
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- monitor->absence_detected_bitmask = 0;
+int ua_monitor_remove_sensor(
+ ua_monitor_h handle,
+ ua_sensor_e sensor_type)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ unsigned int bitmask;
- if (!monitor->absence_user_cb.callback)
- continue;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- for (l1 = monitor->user_state; NULL != l1; l1 = g_slist_next(l1)) {
- ua_user_state_info_s *user_state = l1->data;
+ retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOT_PERMITTED);
+ retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOT_PERMITTED);
- UA_INFO("Scanning user list...");
- if (!user_state)
- continue;
+ bitmask = __ua_sensor_type_to_bitmask(sensor_type);
+ retv_if(0 == (monitor->sensor_bitmask & bitmask), UA_ERROR_ALREADY_DONE);
- ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
- __ua_monitor_send_user_absence_cb(monitor, user_handle,
- user_state->sensor_bitmask);
- }
- }
+ monitor->sensor_bitmask &= ~bitmask;
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-static void __ua_sensor_absence_detected(ua_monitor_s *monitor, unsigned int bitmask, char *account)
+int ua_monitor_foreach_sensor(
+ ua_monitor_h handle,
+ ua_monitor_foreach_sensor_cb foreach_cb,
+ void *user_data)
{
FUNC_ENTRY;
- ua_sensor_e sensor_type;
- bool all_absence;
- GSList *l;
- int found = 0;
- ua_user_state_info_s *user_state = NULL;
- sensor_type = __ua_sensor_bitmask_to_type(bitmask);
- ret_if(NULL == monitor);
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ unsigned int bitmask;
+ int sensor;
- if (account) {
- for (l = monitor->user_state; l; l = g_slist_next(l)) {
- user_state = (ua_user_state_info_s *)l->data;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
- if (!g_strcmp0(account, user_state->account)) {
- found = 1;
+ bitmask = monitor->sensor_bitmask;
+
+ for (sensor = UA_SENSOR_BT; sensor < UA_SENSOR_MAX; sensor <<= 1) {
+ if (bitmask & sensor) {
+ bitmask &= ~sensor;
+ if (!foreach_cb(sensor, user_data))
break;
- }
}
+ }
- if (!found) {
- user_state = __ua_monitor_user_state_create(account);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- if (!user_state)
- return;
+int ua_monitor_start_scan_devices(
+ ua_monitor_h handle,
+ int scan_time,
+ ua_scan_completed_cb callback,
+ void *user_data)
+{
+ FUNC_ENTRY;
+ int ret;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- monitor->user_state = g_slist_append(monitor->user_state, user_state);
- }
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ UA_VALIDATE_INPUT_PARAMETER(callback);
+ retv_if(scan_time <= 0, UA_ERROR_INVALID_PARAMETER);
+ retv_if(scanning_monitor != NULL, UA_ERROR_NOT_PERMITTED);
+ retv_if(TRUE == monitor->scan_device_started, UA_ERROR_NOW_IN_PROGRESS);
+ retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_DATA);
- user_state->sensor_bitmask &= ~bitmask;
+ scan_time *= UA_SCAN_TIME_MULTIPLIER; /* scan_time converted into seconds */
+
+ ret = _ua_get_error_code(_uam_start_search_active_devices(monitor->sensor_bitmask, scan_time));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
}
- switch (monitor->absence_mode) {
- case UA_DETECT_MODE_ALL_SENSOR:
- if (!account)
- monitor->absence_detected_bitmask |= bitmask;
+ monitor->scan_device_cb = callback;
+ monitor->user_data = user_data;
+ monitor->scan_device_started = TRUE;
+ scanning_monitor = monitor;
- break;
- case UA_DETECT_MODE_ANY_SENSOR:
- /* First add user info to local users list and then invoke callback */
- if (account) {
- all_absence = _ua_check_all_users_absence_state(monitor->user_state, bitmask);
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
- if (all_absence) {
- if (monitor->absence_cb)
- monitor->absence_cb(UA_ERROR_NONE, monitor,
- sensor_type, monitor->user_data);
- }
- } else {
- if (monitor->absence_cb)
- monitor->absence_cb(UA_ERROR_NONE, monitor,
- sensor_type, monitor->user_data);
- }
- break;
+int ua_monitor_cancel_scan_devices(ua_monitor_h handle)
+{
+ FUNC_ENTRY;
+ int ret;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
- default:
- UA_WARN("Unexpected detection mode: %d", monitor->absence_mode);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(FALSE == monitor->scan_device_started, UA_ERROR_NOT_IN_PROGRESS);
+
+ ret = _ua_get_error_code(_uam_stop_search_active_devices(monitor->sensor_bitmask));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
}
+ monitor->scan_device_cb = NULL;
+ monitor->user_data = NULL;
+ monitor->scan_device_started = FALSE;
+ scanning_monitor = NULL;
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-void _ua_monitor_handle_scanned_device(int result, uam_device_info_s *uam_info)
+int ua_monitor_start_presence_detection(
+ ua_monitor_h handle,
+ ua_service_h service_handle,
+ ua_detection_mode_e mode,
+ ua_presence_detected_cb callback,
+ void *user_data)
{
FUNC_ENTRY;
- ua_dev_info_s *dev = NULL;
- ua_monitor_s *monitor = scanning_monitor;
+ int ret;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ ua_service_info_s *service_info = (ua_service_info_s *)service_handle;
+ ua_detection_type_e detect = UA_PRESENCE_DETECTION;
+ char *service;
+ GSList *ua_services_list = _ua_service_get_services();
- result = _ua_get_error_code(result);
- if (UA_ERROR_NONE != result)
- return;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOW_IN_PROGRESS);
- UA_INFO("Mobile id[%s] Mac[%s]", uam_info->device_id, uam_info->mac);
+ if (service_handle) {
+ UA_VALIDATE_HANDLE(service_handle, ua_services_list);
+ service = g_strdup(service_info->name);
+ } else
+ service = NULL;
- dev = __ua_get_device_info_from_uam(uam_info);
+ if (monitor->service)
+ if ((service && g_strcmp0(monitor->service, service)) ||
+ (!service && g_strcmp0(monitor->service, UA_SERVICE_DEFAULT))) {
+ g_free(service);
+ return UA_ERROR_NOT_PERMITTED;
+ }
- if (dev == NULL) {
- UA_WARN("Unexpected, cannot find uam_device");
- return;
+ if (UA_DETECT_MODE_INVALID <= mode) {
+ g_free(service);
+ return UA_ERROR_INVALID_PARAMETER;
}
-
- if (monitor && monitor->scan_device_cb) {
- ((ua_scan_completed_cb)monitor->scan_device_cb)(
- UA_ACTIVE_SCAN_TYPE_DEVICE_FOUND, monitor, dev, monitor->user_data);
- UA_PRINT_DEVICE_HANDLE(dev);
- UA_INFO("Invoked scan_device_cb callback");
- } else {
- UA_WARN("Unexpected, scan started but callbacks are NULL");
+ if (0 == monitor->sensor_bitmask) {
+ g_free(service);
+ return UA_ERROR_NO_DATA;
}
- _ua_free_ua_device_info_t((gpointer)dev);
- FUNC_EXIT;
-}
-
-void _ua_monitor_handle_scan_complete(int result)
-{
- FUNC_ENTRY;
- ua_monitor_s *monitor = scanning_monitor;
- result = _ua_get_error_code(result);
-
- if (UA_ERROR_NONE != result)
- return;
+ if (!monitor->service) {
+ if (service == NULL)
+ monitor->service = g_strndup(UA_SERVICE_DEFAULT, UA_MAX_SERVICE_LEN);
+ else
+ monitor->service = g_strndup(service, UA_MAX_SERVICE_LEN);
+ }
+ /**
+ * TODO: Check if we have to check is_sensor_ready at this point and remove sensor
+ * from monitor if sensor is not ready
+ */
+ if (!monitor->internal_presence_started || !monitor->absence_detection_started) {
+ ret = __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, detect);
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ g_free(service);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ }
- if (monitor && monitor->scan_device_cb) {
- ((ua_scan_completed_cb)monitor->scan_device_cb)(
- UA_ACTIVE_SCAN_TYPE_COMPLETED, monitor, NULL, monitor->user_data);
- UA_INFO("Invoked scan_device_cb callback");
+ monitor->presence_mode = mode;
+ monitor->presence_cb = callback;
+ monitor->user_data = user_data;
+ monitor->presence_detection_started = TRUE;
- /* Reset callback when scan complete*/
- monitor->scan_device_cb = NULL;
- monitor->user_data = NULL;
- monitor->scan_device_started = FALSE;
- scanning_monitor = NULL;
- } else {
- UA_WARN("Unexpected, scan running but callbacks are NULL");
- }
+ g_free(service);
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, char *service,
- char *account, long timestamp,
- char *device_id)
+int ua_monitor_start_absence_detection(
+ ua_monitor_h handle,
+ ua_service_h service_handle,
+ ua_detection_mode_e mode,
+ ua_absence_detected_cb callback,
+ void *user_data)
{
FUNC_ENTRY;
- GSList *l;
-
- for (l = ua_monitor_list; l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
+ int ret;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ ua_service_info_s *service_info = (ua_service_info_s *)service_handle;
+ ua_detection_type_e detect = UA_ABSENCE_DETECTION;
+ char *service;
+ GSList *ua_services_list = _ua_service_get_services();
- if (!monitor || (!monitor->presence_detection_started && !monitor->internal_presence_started))
- continue;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOW_IN_PROGRESS);
- if (0 == (bitmask & monitor->sensor_bitmask))
- continue;
+ if (service_handle) {
+ UA_VALIDATE_HANDLE(service_handle, ua_services_list);
+ service = g_strdup(service_info->name);
+ } else
+ service = NULL;
- if (!service || !g_strcmp0(service, monitor->service)) {
- /* Presence detection ongoing */
- __ua_sensor_presence_detected(monitor, bitmask, account,
- timestamp, device_id);
+ if (monitor->service)
+ if ((service && g_strcmp0(monitor->service, service)) ||
+ (!service && g_strcmp0(monitor->service, UA_SERVICE_DEFAULT))) {
+ g_free(service);
+ return UA_ERROR_NOT_PERMITTED;
}
- }
- FUNC_EXIT;
-}
+ retv_if(UA_DETECT_MODE_INVALID <= mode, UA_ERROR_INVALID_PARAMETER);
+ retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_DATA);
-void _ua_monitor_handle_user_absence_detected(unsigned int bitmask, char *service, char *account)
-{
- FUNC_ENTRY;
- GSList *l;
+ if (!monitor->service) {
+ if (service == NULL)
+ monitor->service = g_strndup(UA_SERVICE_DEFAULT, UA_MAX_SERVICE_LEN);
+ else
+ monitor->service = g_strndup(service, UA_MAX_SERVICE_LEN);
+ }
- for (l = ua_monitor_list; l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
+ /* TODO: Check if we have to check is_sensor_ready at this point and remove sensor
+ * from monitor if sensor is not ready.
+ */
+ ret = __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, detect);
- if (!monitor || !monitor->absence_detection_started)
- continue;
+ if (mode == UA_DETECT_MODE_ALL_SENSOR)
+ __ua_monitor_internal_presence_ref(monitor);
- if (0 == (bitmask & monitor->sensor_bitmask))
- continue;
+ if (monitor->internal_presence_started)
+ if (!monitor->presence_detection_started)
+ __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
- if (!service || !g_strcmp0(service, monitor->service)) {
- /* Absence detection ongoing */
- __ua_sensor_absence_detected(monitor, bitmask, account);
- }
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ g_free(service);
+ return ret;
+ /* LCOV_EXCL_STOP */
}
- FUNC_EXIT;
-}
-
-void _ua_monitor_handle_detection_stopped()
-{
- FUNC_ENTRY;
+ monitor->absence_mode = mode;
+ monitor->absence_cb = callback;
+ monitor->user_data = user_data;
+ monitor->absence_detection_started = TRUE;
- __ua_send_presence_detection();
- __ua_send_absence_detection();
- __ua_user_state_clean();
+ g_free(service);
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-#if 0
-static void __ua_remove_sensor(ua_monitor_s *monitor, ua_sensor_e sensor_type)
+int ua_monitor_stop_presence_detection(ua_monitor_h handle)
{
FUNC_ENTRY;
int ret;
- int is_presence = 0;
- int is_absence = 0;
- void *presence_callback = NULL;
- void *presence_user_data = NULL;
- void *absence_callback = NULL;
- void *absence_user_data = NULL;
- ua_detection_mode_e mode_presence;
- ua_detection_mode_e mode_absence;
-
- if (monitor->presence_detection_started) {
- /* Stop detection first */
- if (monitor->presence_cb) {
- /* Presence detection ongoing */
- presence_callback = monitor->presence_cb;
- presence_user_data = monitor->user_data;
- mode_presence = monitor->presence_mode;
-
- ret = ua_monitor_stop_presence_detection(monitor);
- UA_INFO("ua_monitor_stop_presence_detection returned %s",
- _ua_get_error_string(ret));
-
- is_presence = 1;
- } else {
- UA_WARN("Unexpected, detection started but cbs are NULL");
- }
- }
-
- if (monitor->absence_detection_started) {
- /* Stop detection first */
- if (monitor->absence_cb) {
- /* absence detection ongoing */
- absence_callback = monitor->absence_cb;
- absence_user_data = monitor->user_data;
- mode_absence = monitor->absence_mode;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ ua_detection_type_e detect = UA_PRESENCE_DETECTION;
- ret = ua_monitor_stop_presence_detection(monitor);
- UA_INFO("ua_monitor_stop_presence_detection returned %s",
- _ua_get_error_string(ret));
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(FALSE == monitor->presence_detection_started, UA_ERROR_NOT_IN_PROGRESS);
- is_absence = 1;
- } else {
- UA_WARN("Unexpected, detection started but cbs are NULL");
+ if (!monitor->internal_presence_started || !monitor->absence_detection_started) {
+ ret = __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, detect);
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
}
}
- if (is_presence || is_absence) {
- ret = ua_monitor_remove_sensor(monitor, sensor_type);
- UA_INFO("ua_monitor_remove_sensor returned %s",
- _ua_get_error_string(ret));
- }
-
- if (0 != monitor->sensor_bitmask) {
- if (is_presence) {
- ret = ua_monitor_start_presence_detection(
- monitor, monitor->service, mode_presence, presence_callback, presence_user_data);
- UA_INFO("ua_monitor_start_presence_detection returned %s",
- _ua_get_error_string(ret));
- }
-
- if (is_absence) {
- ret = ua_monitor_start_absence_detection(
- monitor, monitor->service, mode_absence, absence_callback, absence_user_data);
- UA_INFO("ua_monitor_start_absence_detection returned %s",
- _ua_get_error_string(ret));
- }
- }
+ monitor->presence_mode = UA_DETECT_MODE_INVALID;
+ monitor->presence_cb = NULL;
+ monitor->user_data = NULL;
+ monitor->presence_detection_started = FALSE;
+ g_slist_free_full(monitor->user_state, __ua_free_user_state_info_t);
+ monitor->user_state = NULL;
- if (!is_presence && !is_absence) {
- /* Monitoring is already stopped, just remove sensor from monitor */
- ret = ua_monitor_remove_sensor(monitor, sensor_type);
- UA_INFO("ua_monitor_remove_sensor returned %s",
- _ua_get_error_string(ret));
+ if (!monitor->absence_detection_started) {
+ g_free(monitor->service);
+ monitor->service = NULL;
}
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-#endif
-void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready)
+int ua_monitor_stop_absence_detection(ua_monitor_h handle)
{
FUNC_ENTRY;
- ua_sensor_e sensor_type;
- GSList *l;
+ int ret;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+ ua_detection_type_e detect = UA_ABSENCE_DETECTION;
- sensor_type = __ua_sensor_bitmask_to_type(bitmask);
- for (l = ua_monitor_list; l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(FALSE == monitor->absence_detection_started, UA_ERROR_NOT_IN_PROGRESS);
+ retv_if(NULL == monitor->absence_cb, UA_ERROR_NOT_IN_PROGRESS);
- if (!monitor)
- continue;
+ ret = __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, detect);
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
- if (monitor->sensor_state_cb.callback)
- ((ua_monitor_sensor_state_changed_cb)monitor->sensor_state_cb.callback)(
- (bool)ready, sensor_type, (ua_monitor_h)monitor,
- monitor->sensor_state_cb.user_data);
+ if (!monitor->presence_detection_started)
+ __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+
+ if (monitor->absence_mode == UA_DETECT_MODE_ALL_SENSOR)
+ __ua_monitor_internal_presence_unref(monitor);
+
+ monitor->absence_mode = UA_DETECT_MODE_INVALID;
+ monitor->absence_cb = NULL;
+ monitor->user_data = NULL;
+ monitor->absence_detection_started = FALSE;
+
+ if (!monitor->presence_detection_started) {
+ g_free(monitor->service);
+ monitor->service = NULL;
}
+
FUNC_EXIT;
+ return UA_ERROR_NONE;
}
-int ua_monitor_set_brightness_threshold(ua_monitor_h handle, int presence_threshold, int absence_threshold)
+int ua_monitor_set_brightness_threshold(ua_monitor_h handle,
+ int presence_threshold, int absence_threshold)
{
FUNC_ENTRY;
int ret;
GSList *ua_services_list;
-static ua_mac_type_e __to_ua_mac_type(uam_tech_type_e tech_type)
+static ua_service_info_s* __ua_get_service_from_list(const char *service_name)
{
- switch (tech_type) {
- case UAM_TECH_TYPE_BT:
- return UA_MAC_TYPE_BT;
- case UAM_TECH_TYPE_BLE:
- return UA_MAC_TYPE_BLE;
- case UAM_TECH_TYPE_WIFI:
- return UA_MAC_TYPE_WIFI;
- case UAM_TECH_TYPE_P2P:
- return UA_MAC_TYPE_P2P;
- default:
- return UA_MAC_TYPE_INVALID;
+ GSList *l;
+ ua_service_info_s *service_info;
+
+ retv_if(NULL == service_name, NULL);
+
+ for (l = ua_services_list; l; l = g_slist_next(l)) {
+ service_info = (ua_service_info_s *)l->data;
+
+ if (!g_strcmp0(service_name, service_info->name))
+ return service_info;
}
+
+ return NULL;
}
void _ua_free_ua_service_info_s(gpointer data)
FUNC_EXIT;
}
-static ua_service_info_s* __ua_get_service_from_list(const char *service_name)
+int _ua_intr_foreach_registered_services(
+ _ua_intr_registered_service_cb foreach_cb, void *user_data)
{
+ int ret;
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+
+ ret = _ua_foreach_registered_services(foreach_cb, user_data);
+ return ret;
+}
+
+int _ua_intr_get_default_service(void)
+{
+ FUNC_ENTRY;
+ int ret;
+ uam_service_info_s uam_service;
+ ua_service_info_s *service = NULL;
GSList *l;
- ua_service_info_s *service_info;
- retv_if(NULL == service_name, NULL);
+ ret = _ua_get_error_code(_uam_get_default_service(&uam_service));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
for (l = ua_services_list; l; l = g_slist_next(l)) {
- service_info = (ua_service_info_s *)l->data;
+ service = (ua_service_info_s *)l->data;
- if (!g_strcmp0(service_name, service_info->name))
- return service_info;
+ if (!g_strcmp0(uam_service.name, service->name)) {
+ UA_INFO("Service found [%s]", service->name);
+ service->default_service = true;
+ service->isadded = true;
+ return UA_ERROR_NONE;
+ }
}
- return NULL;
+ /* LCOV_EXCL_START */
+ service = g_malloc0(sizeof(ua_service_info_s));
+ if (!service) {
+ UA_ERR("Failed to allocate memory");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ service->name = g_strdup(uam_service.name);
+ service->service_handle = (ua_service_h)service;
+ service->default_service = true;
+ service->isadded = true;
+
+ ua_services_list = g_slist_append(ua_services_list, service);
+ FUNC_EXIT;
+ /* LCOV_EXCL_STOP */
+ return UA_ERROR_NONE;
+}
+
+GSList *_ua_service_get_services(void)
+{
+ FUNC_ENTRY;
+ FUNC_EXIT;
+ return ua_services_list;
}
int _ua_service_add_info_to_list(ua_service_info_s* ua_info)
return UA_ERROR_NONE;
}
-/* LCOV_EXCL_START */
int _ua_service_add_info_to_list_from_uam_data(uam_service_info_s *uam_info)
{
FUNC_ENTRY;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-/* LCOV_EXCL_STOP */
-/* LCOV_EXCL_START */
int _ua_service_remove_info_from_list(uam_service_info_s *uam_info)
{
FUNC_ENTRY;
FUNC_EXIT;
return ret;
}
-/* LCOV_EXCL_STOP */
+
+int _ua_foreach_registered_services(ua_service_added_service_cb foreach_cb,
+ void *user_data)
+{
+ FUNC_ENTRY;
+ int i;
+ int ret;
+ GPtrArray *service_list = NULL;
+ uam_service_info_s *ptr;
+
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+
+ service_list = g_ptr_array_new();
+ retv_if(NULL == service_list, UA_ERROR_OUT_OF_MEMORY);
+
+ ret = _ua_get_error_code(_uam_get_registered_services(&service_list));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ g_ptr_array_free(service_list, TRUE);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ for (i = 0; i < service_list->len; i++) {
+ ptr = g_ptr_array_index(service_list, i);
+ if (ptr) {
+ ua_service_info_s *service_info;
+ service_info = g_malloc0(sizeof(ua_service_info_s));
+
+ if (!service_info) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_service_info_s(service_info);
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+
+ service_info->name = g_strndup(ptr->name, UAM_SERVICE_MAX_STRING_LEN);
+ if (service_info->name == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_service_info_s(service_info);
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+
+ service_info->isadded = true;
+ service_info->service_handle = (ua_service_h)service_info;
+ if (!foreach_cb(service_info->service_handle, user_data)) {
+ _ua_free_ua_service_info_s(service_info);
+ break;
+ } else
+ _ua_free_ua_service_info_s(service_info);
+ } else {
+ /* LCOV_EXCL_START */
+ UA_ERR("OPERATION_FAILED(0x%08x)",
+ UA_ERROR_OPERATION_FAILED);
+ ret = UA_ERROR_OPERATION_FAILED;
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+ }
+
+done:
+ g_ptr_array_foreach(service_list, (GFunc)g_free, NULL);
+ g_ptr_array_free(service_list, TRUE);
+
+ FUNC_EXIT;
+ return ret;
+}
+
int ua_service_create(ua_service_h *service_handle)
{
device_info->isadded = true;
device_info->handle = (ua_device_h)device_info;
- device_info->type = __to_ua_mac_type(ptr->type);
+ device_info->type = _to_ua_mac_type(ptr->type);
device_info->os = ptr->operating_system;
device_info->discriminant = ptr->discriminant;
device_info->user = NULL;
return ret;
}
-int _ua_foreach_registered_services(
- ua_service_added_service_cb foreach_cb,
- void *user_data)
-{
- FUNC_ENTRY;
- int i;
- int ret;
- GPtrArray *service_list = NULL;
- uam_service_info_s *ptr;
-
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
-
- service_list = g_ptr_array_new();
- retv_if(NULL == service_list, UA_ERROR_OUT_OF_MEMORY);
-
- ret = _ua_get_error_code(_uam_get_registered_services(&service_list));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- g_ptr_array_free(service_list, TRUE);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- for (i = 0; i < service_list->len; i++) {
- ptr = g_ptr_array_index(service_list, i);
- if (ptr) {
- ua_service_info_s *service_info;
- service_info = g_malloc0(sizeof(ua_service_info_s));
-
- if (!service_info) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_service_info_s(service_info);
- /* LCOV_EXCL_STOP */
- goto done;
- }
-
- service_info->name = g_strndup(ptr->name, UAM_SERVICE_MAX_STRING_LEN);
- if (service_info->name == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_service_info_s(service_info);
- /* LCOV_EXCL_STOP */
- goto done;
- }
-
- service_info->isadded = true;
- service_info->service_handle = (ua_service_h)service_info;
- if (!foreach_cb(service_info->service_handle, user_data)) {
- _ua_free_ua_service_info_s(service_info);
- break;
- } else
- _ua_free_ua_service_info_s(service_info);
- } else {
- /* LCOV_EXCL_START */
- UA_ERR("OPERATION_FAILED(0x%08x)",
- UA_ERROR_OPERATION_FAILED);
- ret = UA_ERROR_OPERATION_FAILED;
- /* LCOV_EXCL_STOP */
- goto done;
- }
- }
-
-done:
- g_ptr_array_foreach(service_list, (GFunc)g_free, NULL);
- g_ptr_array_free(service_list, TRUE);
-
- FUNC_EXIT;
- return ret;
-}
-
-int _ua_intr_foreach_registered_services(
- _ua_intr_registered_service_cb foreach_cb,
- void *user_data)
-{
- int ret;
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
-
- ret = _ua_foreach_registered_services(foreach_cb, user_data);
- return ret;
-}
-
-int _ua_intr_get_default_service(void)
-{
- FUNC_ENTRY;
- int ret;
- uam_service_info_s uam_service;
- ua_service_info_s *service = NULL;
- GSList *l;
-
- ret = _ua_get_error_code(_uam_get_default_service(&uam_service));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- for (l = ua_services_list; l; l = g_slist_next(l)) {
- service = (ua_service_info_s *)l->data;
-
- if (!g_strcmp0(uam_service.name, service->name)) {
- UA_INFO("Service found [%s]", service->name);
- service->default_service = true;
- service->isadded = true;
- return UA_ERROR_NONE;
- }
- }
-
- /* LCOV_EXCL_START */
- service = g_malloc0(sizeof(ua_service_info_s));
- if (!service) {
- UA_ERR("Failed to allocate memory");
- return UA_ERROR_OUT_OF_MEMORY;
- }
- service->name = g_strdup(uam_service.name);
- service->service_handle = (ua_service_h)service;
- service->default_service = true;
- service->isadded = true;
-
- ua_services_list = g_slist_append(ua_services_list, service);
- FUNC_EXIT;
- /* LCOV_EXCL_STOP */
- return UA_ERROR_NONE;
-}
-
-/* LCOV_EXCL_START */
-GSList *_ua_service_get_services(void)
-{
- FUNC_ENTRY;
- FUNC_EXIT;
- return ua_services_list;
-}
-/* LCOV_EXCL_STOP */
-
#include <user-awareness-private.h>
#include <user-awareness-util.h>
-typedef enum {
- UA_USER_EVENT_DEVICE_ADDED = 0,
-
- UA_USER_EVENT_MAX
-} ua_user_event_e;
-
GSList *ua_users_list;
-GSList *ua_devices_db_list;
-GSList *ua_devices_list;
-
-static ua_callback_s user_callbacks[UA_USER_EVENT_MAX] = {{NULL, NULL},};
-
-static ua_mac_type_e __to_ua_mac_type(uam_tech_type_e tech_type)
-{
- switch (tech_type) {
- case UAM_TECH_TYPE_BT:
- return UA_MAC_TYPE_BT;
- case UAM_TECH_TYPE_BLE:
- return UA_MAC_TYPE_BLE;
- case UAM_TECH_TYPE_WIFI:
- return UA_MAC_TYPE_WIFI;
- case UAM_TECH_TYPE_P2P:
- return UA_MAC_TYPE_P2P;
- default:
- return UA_MAC_TYPE_INVALID;
- }
-}
-
-void _ua_create_ua_ble_payload_s(ua_ble_payload_s **payload_handle)
-{
- FUNC_ENTRY;
- ua_ble_payload_s *payload = NULL;
-
- ret_if(NULL == payload_handle);
-
- payload = g_malloc0(sizeof(ua_ble_payload_s));
- if (!payload) {
- UA_ERR("g_malloc0 failed");
- *payload_handle = NULL;
- return;
- }
-
-//TODO lk, set default value of these vars
- payload->service_id = 0x00;
- payload->device_icon = 0x00;
- payload->purpose = 0x00;
- payload->duid = NULL;
- payload->bt_mac = NULL;
-
- *payload_handle = payload;
- FUNC_EXIT;
-}
-
-void _ua_free_ua_ble_payload_s(gpointer data)
-{
- FUNC_ENTRY;
- ua_ble_payload_s *payload = data;
-
- ret_if(NULL == payload);
-
- g_free(payload->duid);
- g_free(payload->bt_mac);
-
- g_free(payload);
- FUNC_EXIT;
-}
-
-ua_ble_payload_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload)
-{
- FUNC_ENTRY;
- ua_ble_payload_s *payload = NULL;
-
- retv_if(NULL == uam_payload, NULL);
-
- payload = g_malloc0(sizeof(ua_ble_payload_s));
- if (!payload) {
- UA_ERR("g_malloc0 failed");
- return NULL;
- }
-
- payload->service_id = uam_payload->service_id;
- payload->device_icon = uam_payload->device_icon;
- payload->purpose = uam_payload->purpose;
-
- payload->duid = g_memdup(uam_payload->duid, UA_BLE_PAYLOAD_DUID_LEN + 1);
- if (!payload->duid) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_ble_payload_s(payload);
- return NULL;
- }
-
- payload->bt_mac = g_strdup(uam_payload->bt_mac);
- if (!payload->bt_mac) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_ble_payload_s(payload);
- return NULL;
- }
-
- FUNC_EXIT;
- return payload;
-}
-
-void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, ua_ble_payload_s *payload)
-{
- FUNC_ENTRY;
- memset(uam_payload, 0, sizeof(uam_ble_payload_s));
-
- ret_if(NULL == payload);
-
- uam_payload->service_id = payload->service_id;
- uam_payload->device_icon = payload->device_icon;
- uam_payload->purpose = payload->purpose;
- if (payload->duid)
- memcpy(uam_payload->duid, payload->duid, UA_BLE_PAYLOAD_DUID_LEN + 1);
-
- if (payload->bt_mac)
- g_strlcpy(uam_payload->bt_mac, payload->bt_mac, UA_BT_MAC_MAX_LEN);
-
- FUNC_EXIT;
-}
+extern GSList *ua_devices_list;
+extern ua_callback_s user_callbacks[UA_USER_EVENT_MAX];
-ua_ble_payload_s* _ua_payload_clone(ua_ble_payload_s *org_payload)
+static ua_user_info_s *__ua_get_user_from_list(const char *account)
{
- FUNC_ENTRY;
- ua_ble_payload_s *payload = NULL;
-
- retv_if(NULL == org_payload, NULL);
-
- payload = g_malloc0(sizeof(ua_ble_payload_s));
- if (!payload) {
- UA_ERR("g_malloc0 failed");
- return NULL;
- }
+ GSList *l;
+ ua_user_info_s *user_info;
- payload->service_id = org_payload->service_id;
- payload->device_icon = org_payload->device_icon;
- payload->purpose = org_payload->purpose;
+ retv_if(NULL == account, NULL);
- payload->duid = g_memdup(org_payload->duid, UA_BLE_PAYLOAD_DUID_LEN + 1);
- if (!payload->duid && org_payload->duid) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_ble_payload_s(payload);
- return NULL;
- }
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ user_info = (ua_user_info_s *)l->data;
- payload->bt_mac = g_strdup(org_payload->bt_mac);
- if (!payload->bt_mac && org_payload->bt_mac) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_ble_payload_s(payload);
- return NULL;
+ if (!g_strcmp0(account, user_info->account))
+ return user_info;
}
- FUNC_EXIT;
- return payload;
-}
-
-void _ua_free_ua_device_info_t(gpointer data)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = data;
-
- ret_if(NULL == device);
-
- g_free(device->mac);
- g_free(device->bssid);
- g_free(device->ipv4);
- g_free(device->ipv6); // LCOV_EXCL_LINE
- g_free(device->device_id);
- _ua_free_ua_ble_payload_s(device->payload);
-
- g_free(device);
- FUNC_EXIT;
+ return NULL;
}
void _ua_free_ua_user_info_t(gpointer data)
FUNC_EXIT;
}
-ua_dev_info_s* __ua_get_device_info_from_uam(uam_device_info_s *uam_info)
-{
- FUNC_ENTRY;
- ua_dev_info_s *dev;
- retv_if(NULL == uam_info, NULL);
-
- dev = g_malloc0(sizeof(ua_dev_info_s));
- if (!dev) {
- UA_ERR("g_malloc0 failed");
- return NULL;
- }
- dev->user = NULL;
- dev->bssid = NULL;
- dev->ipv6 = NULL;
-
- dev->mac = g_strdup(uam_info->mac);
- if (dev->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->ipv4 = g_strdup(uam_info->ipv4_addr);
- if (dev->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->device_id = g_strdup(uam_info->device_id);
- if (dev->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->payload = _ua_get_payload_from_uam(&uam_info->payload);
- if (dev->payload == NULL) {
- UA_ERR("_ua_get_payload_from_uam() failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->type = __to_ua_mac_type(uam_info->type);
- dev->pairing_required = FALSE;
- dev->os = uam_info->operating_system;
- dev->isadded = true;
- dev->discriminant = uam_info->discriminant;
-
- dev->handle = (ua_device_h)dev;
-
- FUNC_EXIT;
- return dev;
-}
-
/* LCOV_EXCL_START */
-int _ua_mark_user_info_state_db(char *account, int state, unsigned sensor_bitmask)
+int _ua_mark_user_info_state_db(char *account, int state,
+ unsigned sensor_bitmask)
{
FUNC_ENTRY;
int ret = UA_ERROR_NO_DATA;
}
/* LCOV_EXCL_STOP */
-static ua_user_info_s *__ua_get_user_from_list(const char *account)
-{
- GSList *l;
- ua_user_info_s *user_info;
-
- retv_if(NULL == account, NULL);
-
- for (l = ua_users_list; l; l = g_slist_next(l)) {
- user_info = (ua_user_info_s *)l->data;
-
- if (!g_strcmp0(account, user_info->account))
- return user_info;
- }
-
- return NULL;
-}
-
-/* LCOV_EXCL_START */
-static ua_dev_info_s *__ua_get_device_from_list(
- const char *device_id, const char *mac, ua_mac_type_e type)
-{
- GSList *l;
- ua_dev_info_s *dev;
-
- for (l = ua_devices_list; NULL != l; l = g_slist_next(l)) {
- dev = (ua_dev_info_s *)l->data;
-
- if (type != dev->type)
- continue;
-
- if (device_id && !g_strcmp0(device_id, dev->device_id)) {
- UA_INFO("Device found, device id[%s]", dev->device_id);
- return dev;
- }
-
- if (mac && !g_strcmp0(mac, dev->mac)) {
- UA_INFO("Device found, mac address[%s]", dev->mac);
- return dev;
- }
- }
-
- return NULL;
-}
-/* LCOV_EXCL_STOP */
-
-int _ua_is_device_exist(char *device_id, char *mac, ua_mac_type_e type, gboolean *is_exist)
-{
- GSList *l;
- UA_VALIDATE_INPUT_PARAMETER(is_exist);
- ua_dev_info_s *dev;
- *is_exist = false;
-
- for (l = ua_devices_list; l; l = g_slist_next(l)) {
- dev = (ua_dev_info_s *)l->data;
-
- if ((int)type == (int)dev->type) {
- if (device_id && !g_strcmp0(device_id, dev->device_id)) {
- /* LCOV_EXCL_START */
- UA_INFO("Device found, device id[%s]", dev->device_id);
- *is_exist = true;
- /* LCOV_EXCL_STOP */
- }
-
- if (mac && !g_strcmp0(mac, dev->mac)) {
- /* LCOV_EXCL_START */
- UA_INFO("Device found, mac address[%s]", dev->mac);
- *is_exist = true;
- /* LCOV_EXCL_STOP */
- }
- }
- }
-
- return UA_ERROR_NONE;
-}
-
-/* LCOV_EXCL_START */
int _ua_user_add_info_to_list_from_uapi_data(uam_user_info_s *uam_info)
{
FUNC_ENTRY;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-/* LCOV_EXCL_STOP */
int _ua_user_add_info_to_list(ua_user_info_s* ua_info)
{
return UA_ERROR_NONE;
}
-/* LCOV_EXCL_START */
int _ua_remove_user_info_from_list(char *account)
{
FUNC_ENTRY;
return ret;
}
-static ua_dev_info_s* __ua_add_device_info_to_list(uam_device_info_s *uam_info)
-{
- FUNC_ENTRY;
- ua_dev_info_s *dev;
- retv_if(NULL == uam_info, NULL);
-
- dev = __ua_get_device_from_list(uam_info->device_id,
- uam_info->mac, __to_ua_mac_type(uam_info->type));
- if (dev) {
- /* Update device info */
- g_free(dev->mac);
- dev->mac = g_strdup(uam_info->mac);
-
- g_free(dev->ipv4);
- dev->ipv4 = g_strdup(uam_info->ipv4_addr);
-
- g_free(dev->device_id);
- dev->device_id = g_strdup(uam_info->device_id);
-
- dev->os = uam_info->operating_system;
- dev->pairing_required = FALSE;
- dev->discriminant= true;
- dev->isadded = true;
- return dev;
- }
-
- dev = g_malloc0(sizeof(ua_dev_info_s));
- if (!dev) {
- UA_ERR("g_malloc0 failed");
- return NULL;
- }
- dev->user = NULL;
- dev->bssid = NULL;
- dev->ipv6 = NULL;
-
- dev->mac = g_strdup(uam_info->mac);
- if (dev->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->ipv4 = g_strdup(uam_info->ipv4_addr);
- if (dev->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->device_id = g_strdup(uam_info->device_id);
- if (dev->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)dev);
- return NULL;
- }
-
- dev->type = __to_ua_mac_type(uam_info->type);
- dev->pairing_required = FALSE;
- dev->os = uam_info->operating_system;
- dev->discriminant= uam_info->discriminant;
- dev->isadded = true;
-
- /* Add device to list of devices */
- dev->handle = (ua_device_h)dev;
- ua_devices_list = g_slist_append(ua_devices_list, dev);
-
- FUNC_EXIT;
- return dev;
-}
-
-void _ua_handle_device_added(int result, uam_device_info_s *uam_info)
-{
- FUNC_ENTRY;
- ua_dev_info_s *dev;
- result = _ua_get_error_code(result);
-
- if (UA_ERROR_NONE != result) {
- dev = __ua_get_device_from_list(uam_info->device_id,
- uam_info->mac, __to_ua_mac_type(uam_info->type));
- ret_if(NULL == dev);
- UA_ERR("Add device failed for Id:[%s] MAC type:[0x%4.4X]",
- dev->device_id, dev->type);
- } else {
- dev = __ua_add_device_info_to_list(uam_info);
- ret_if(NULL == dev);
- }
-
- if (user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback) {
- ((ua_user_device_added_cb)user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback)(
- result, dev, user_callbacks[UA_USER_EVENT_DEVICE_ADDED].user_data);
- UA_INFO("Invoked device added callback");
-
- /* Reset callback */
- user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback = NULL;
- user_callbacks[UA_USER_EVENT_DEVICE_ADDED].user_data = NULL;
- }
-
- FUNC_EXIT;
-}
-
-static void __ua_remove_device_info_from_list(uam_device_info_s *uam_info)
-{
- FUNC_ENTRY;
- GSList *l;
- ua_dev_info_s *u;
- ua_mac_type_e type;
- ret_if(NULL == uam_info);
-
- type = __to_ua_mac_type(uam_info->type);
- for (l = ua_devices_list; l; l = g_slist_next(l)) {
- u = (ua_dev_info_s *)l->data;
-
- if (type != u->type)
- continue;
-
- if (g_strcmp0(uam_info->device_id, u->device_id))
- continue;
-
- if (u->create_by_app) {
- UA_INFO("Device created by APP, do not remove");
- u->isadded = false;
- }
-
- UA_INFO("Device found, device id[%s]", u->device_id);
- ua_devices_list = g_slist_remove(ua_devices_list, u);
- _ua_free_ua_device_info_t((gpointer)u);
- break;
- }
-
- FUNC_EXIT;
-}
-
-void _ua_handle_device_removed(int result, uam_device_info_s *uam_info)
-{
- FUNC_ENTRY;
-
- result = _ua_get_error_code(result);
- ret_if(UA_ERROR_NONE != result);
-
- __ua_remove_device_info_from_list(uam_info);
-
- FUNC_EXIT;
-}
-
ua_user_h _ua_get_user_handle_by_account(const char *account)
{
FUNC_ENTRY;
}
void _ua_set_user_last_presence_timestamp(ua_user_h user_handle,
- long timestamp)
+ long timestamp)
{
FUNC_ENTRY;
ua_user_info_s *user = (ua_user_info_s *)user_handle;
FUNC_EXIT;
}
-/* LCOV_EXCL_STOP */
-int ua_user_create(ua_user_h *user_handle)
+ int _ua_intr_foreach_registered_users(_ua_intr_registered_user_cb foreach_cb,
+ void *user_data)
+{
+ int ret;
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+
+ ret = _ua_foreach_registered_users(foreach_cb, user_data);
+ return ret;
+}
+
+int _ua_intr_get_default_user(void)
{
FUNC_ENTRY;
+ int ret;
+ uam_user_info_s uam_user;
ua_user_info_s *user = NULL;
+ GSList *l;
- UA_VALIDATE_INPUT_PARAMETER(user_handle);
-
- user = g_malloc0(sizeof(ua_user_info_s));
- if (!user) {
+ ret = _ua_get_error_code(_uam_get_default_user(&uam_user));
+ if (UA_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ user = (ua_user_info_s *)l->data;
+
+ if (!g_strcmp0(uam_user.account, user->account)) {
+ UA_INFO("User found [%s]", user->account);
+ user->default_user = true;
+ user->isadded = true;
+ return UA_ERROR_NONE;
+ }
+ }
+
+ /* LCOV_EXCL_START */
+ user = g_malloc0(sizeof(ua_user_info_s));
+ if (!user) {
+ UA_ERR("Failed to allocate memory");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ user->account = g_strdup(uam_user.account);
+ user->name = g_strdup(uam_user.name);
+ user->state = UA_PRESENCE_STATE_INACTIVATE;
+ user->sensor_bitmask = 0;
+ user->user_handle = (ua_user_h)user;
+ user->default_user = true;
+ user->isadded = true;
+
+ ua_users_list = g_slist_append(ua_users_list, user);
+ FUNC_EXIT;
+ /* LCOV_EXCL_STOP */
+ return UA_ERROR_NONE;
+}
+
+/* LCOV_EXCL_START */
+GSList *_ua_user_get_users(void)
+{
+ FUNC_ENTRY;
+ FUNC_EXIT;
+ return ua_users_list;
+}
+
+int _ua_foreach_registered_users(ua_registered_user_cb foreach_cb,
+ void *user_data)
+{
+ FUNC_ENTRY;
+ int i;
+ int ret;
+ GPtrArray *user_list = NULL;
+ uam_user_info_s *ptr;
+
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+
+ user_list = g_ptr_array_new();
+ retv_if(NULL == user_list, UA_ERROR_OUT_OF_MEMORY);
+
+ ret = _ua_get_error_code(_uam_get_registered_users(&user_list));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ g_ptr_array_free(user_list, TRUE);
+ /* LCOV_EXCL_STOP */
+ return ret;
+ }
+
+ for (i = 0; i < user_list->len; i++) {
+ ptr = g_ptr_array_index(user_list, i);
+ if (ptr) {
+ ua_user_info_s* user_info;
+ user_info = g_malloc0(sizeof(ua_user_info_s));
+
+ if (!user_info) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_user_info_t(user_info);
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+
+ user_info->account = g_strdup(ptr->account);
+
+ if (user_info->account == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_user_info_t(user_info);
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+
+ user_info->name = g_strdup(ptr->name);
+
+ if (user_info->name == NULL) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ ret = UA_ERROR_OUT_OF_MEMORY;
+ _ua_free_ua_user_info_t(user_info);
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+ if (!foreach_cb(user_info->user_handle, user_data)) {
+ _ua_free_ua_user_info_t(user_info);
+ break;
+ } else
+ _ua_free_ua_user_info_t(user_info);
+ } else {
+ /* LCOV_EXCL_START */
+ UA_ERR("OPERATION_FAILED(0x%08x)",
+ UA_ERROR_OPERATION_FAILED);
+ ret = UA_ERROR_OPERATION_FAILED;
+ /* LCOV_EXCL_STOP */
+ goto done;
+ }
+ }
+
+done:
+ g_ptr_array_foreach(user_list, (GFunc)g_free, NULL);
+ g_ptr_array_free(user_list, TRUE);
+
+ FUNC_EXIT;
+ return ret;
+}
+
+
+int ua_user_create(ua_user_h *user_handle)
+{
+ FUNC_ENTRY;
+ ua_user_info_s *user = NULL;
+
+ UA_VALIDATE_INPUT_PARAMETER(user_handle);
+
+ user = g_malloc0(sizeof(ua_user_info_s));
+ if (!user) {
+ /* LCOV_EXCL_START */
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
/* LCOV_EXCL_STOP */
}
user->state = UA_PRSENCE_STATE_INVALID;
return UA_ERROR_NONE;
}
-int ua_device_create(ua_device_h *device_handle)
+int ua_user_foreach_added(
+ ua_registered_user_cb foreach_cb,
+ void *user_data)
{
FUNC_ENTRY;
- ua_dev_info_s *device = NULL;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ GSList *l;
+ ua_user_info_s *u;
- device = g_malloc0(sizeof(ua_dev_info_s));
- if (!device) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
- device->user = NULL;
- device->mac = NULL;
- device->bssid = NULL;
- device->ipv4 = NULL;
- device->ipv6 = NULL;
- device->device_id = NULL;
- device->type = 0;
- device->pairing_required = FALSE;
- device->state = UA_PRSENCE_STATE_INVALID;
- device->os = UA_OS_TYPE_NOT_DEFINE;
- device->isadded = false;
- device->discriminant = true;
- device->payload = NULL;
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ u = (ua_user_info_s *)l->data;
- /* Add device to list of devices */
- *device_handle = (ua_device_h)device;
- device->handle = *device_handle;
- device->create_by_app = true;
- ua_devices_list = g_slist_append(ua_devices_list, device);
+ if (!foreach_cb(u->user_handle, user_data))
+ break;
+ }
FUNC_EXIT;
return UA_ERROR_NONE;
}
-int ua_device_destroy(ua_device_h device_handle)
+int ua_user_add_device(ua_user_h user_handle, ua_device_h device_handle,
+ ua_user_device_added_cb callback, void *user_data)
{
FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
+ int ret;
+ ua_user_h handle = NULL;
+ ua_user_h temp_handle = NULL;
+ ua_dev_info_s *device = (ua_dev_info_s *) device_handle;
+ ua_user_info_s* user = NULL;
+ uam_device_info_s uam_device;
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
+ retv_if((((device->device_id == NULL) && (device->mac == NULL))), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
- ua_devices_list = g_slist_remove(ua_devices_list, device);
- _ua_free_ua_device_info_t((gpointer)device);
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_mac_type(ua_device_h handle, ua_mac_type_e mac_type)
-{
- FUNC_ENTRY;
+ temp_handle = device->user;
+ if (user_handle == NULL) {
+ /* LCOV_EXCL_START */
+ ret = ua_user_get_default_user(&handle);
+ if (ret != UA_ERROR_NONE) {
+ UA_ERR("Failed to get default user with error");
+ return ret;
+ }
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
+ device->user = (ua_user_h)handle;
+ /* LCOV_EXCL_STOP */
+ } else {
+ UA_VALIDATE_HANDLE(user_handle, ua_users_list);
+ device->user = user_handle;
+ }
- UA_VALIDATE_INPUT_PARAMETER(handle);
- retv_if(UA_MAC_TYPE_NONE >= mac_type, UA_ERROR_INVALID_PARAMETER);
- retv_if(UA_MAC_TYPE_INVALID <= mac_type, UA_ERROR_INVALID_PARAMETER);
+ user = (ua_user_info_s *)device->user;
+ memset(&uam_device, 0, sizeof(uam_device_info_s));
- device->type = mac_type;
+ uam_device.operating_system = device->os;
+ uam_device.type = _ua_to_uam_tech_type(device->type);
+ uam_device.discriminant = device->discriminant;
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ if (device->mac)
+ g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
-int ua_device_get_mac_type(ua_device_h handle, ua_mac_type_e *mac_type)
-{
- FUNC_ENTRY;
+ g_strlcpy(uam_device.device_id, device->device_id, UA_MOBILE_ID_STRING_LEN);
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
+ if (device->ipv4)
+ g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(mac_type);
- UA_PRINT_DEVICE_HANDLE(handle);
+ _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
- *mac_type = device->type;
+ ret = _ua_get_error_code(_uam_request_add_device(user->account, &uam_device));
+ if (UA_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ device->user = temp_handle;
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback = callback;
+ user_callbacks[UA_USER_EVENT_DEVICE_ADDED].user_data = user_data;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-int ua_device_set_mac_address(
- ua_device_h handle,
- const char *mac_address)
+int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle)
{
FUNC_ENTRY;
int ret;
- gboolean status = false;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(mac_address);
- UA_VALIDATE_HANDLE(handle, ua_devices_list);
-
- retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+ ua_user_h handle = NULL;
+ ua_dev_info_s *device = (ua_dev_info_s *) device_handle;
+ ua_user_info_s* user = NULL;
+ uam_device_info_s uam_device;
- /* This code will check if app try to add mac address which is already set for same
- * or for some other device handle, Then it does not allow to set and restrict to make
- * suplicate entry as mac address is suppose to same for one device.
- */
- ret = _ua_is_device_exist(NULL, (char*)mac_address, device->type, &status);
- if (ret == UA_ERROR_NONE) {
- if (status)
- return UA_ERROR_ALREADY_DONE;
- } else
- return ret;
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
+ retv_if((((device->device_id == NULL) && (device->mac == NULL))), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
+ retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
- retv_if((strlen(mac_address) != (UA_MAC_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER);
+ if (user_handle == NULL) {
+ /* LCOV_EXCL_START */
+ ret = ua_user_get_default_user(&handle);
+ if (ret != UA_ERROR_NONE) {
+ UA_ERR("Failed to get default user with error");
+ return ret;
+ }
- g_free(device->mac);
- device->mac = g_malloc0(UA_MAC_ADDRESS_STRING_LEN);
- if (device->mac){
- g_strlcpy(device->mac, mac_address, UA_MAC_ADDRESS_STRING_LEN);
+ user = (ua_user_info_s *)handle;
+ /* LCOV_EXCL_STOP */
} else {
- UA_ERR("Failt to allocate memory");
- return UA_ERROR_OUT_OF_MEMORY;
+ UA_VALIDATE_HANDLE(user_handle, ua_users_list);
+ retv_if((device->user != user_handle), UA_ERROR_INVALID_PARAMETER);
+ user = (ua_user_info_s *)user_handle;
}
- g_strlcpy(device->mac, mac_address, UA_MAC_ADDRESS_STRING_LEN);
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_os_info(
- ua_device_h handle,
- ua_os_type_e os)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_HANDLE(handle, ua_devices_list);
-
- retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
-
- if (os < UA_OS_TYPE_NOT_DEFINE || os > UA_OS_TYPE_IOS) {
- /* LCOV_EXCL_START */
- UA_ERR("Invalid os type");
- return UA_ERROR_INVALID_PARAMETER;
- /* LCOV_EXCL_STOP */
- }
-
- device->os = os;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_device_id(
- ua_device_h handle,
- const char *device_id)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
- int ret;
- gboolean status = false;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(device_id);
- UA_VALIDATE_HANDLE(handle, ua_devices_list);
-
- retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
- /* This code will check if app try to add device id which is already set for same
- * or for some other device handle, Then it does not allow to set and restrict to make
- * suplicate entry as device id is suppose to same for one device.
- */
- ret = _ua_is_device_exist((char*)device_id, NULL, device->type, &status);
- if (ret == UA_ERROR_NONE) {
- if (status)
- return UA_ERROR_ALREADY_DONE;
- } else
- return ret;
-
- g_free(device->device_id);
- device->device_id = g_strdup(device_id);
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_wifi_bssid(
- ua_device_h handle,
- const char *bssid)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(bssid);
- UA_VALIDATE_HANDLE(handle, ua_devices_list);
-
- retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
- retv_if((strlen(bssid) != (UA_MAC_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER);
-
- g_free(device->bssid);
- device->bssid = g_malloc0(UA_MAC_ADDRESS_STRING_LEN);
- if (device->bssid) {
- g_strlcpy(device->bssid, bssid, UA_MAC_ADDRESS_STRING_LEN);
- } else {
- UA_ERR("Failed to allocated memory");
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_wifi_ipv4_address(
- ua_device_h handle,
- const char *ipv4_address)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(ipv4_address);
- UA_VALIDATE_HANDLE(handle, ua_devices_list);
-
- retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
- retv_if((strlen(ipv4_address) > (UA_IPV4_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER);
-
- g_free(device->ipv4);
- device->ipv4 = g_malloc0(UA_IPV4_ADDRESS_STRING_LEN);
- if (device->ipv4) {
- g_strlcpy(device->ipv4, ipv4_address, UA_IPV4_ADDRESS_STRING_LEN);
- } else {
- UA_ERR("Failed to allocated memory");
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_discriminant(
- ua_device_h device_handle,
- bool discriminant)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
-
- device->discriminant = discriminant;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_service_id(
- ua_device_h handle,
- const char service_id)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- _ua_create_ua_ble_payload_s(&device->payload);
- if (!device->payload) {
- UA_ERR("_ua_create_ua_ble_payload_s() failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
- }
-
- device->payload->service_id = service_id;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_device_icon(
- ua_device_h handle,
- const char device_icon)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- _ua_create_ua_ble_payload_s(&device->payload);
- if (!device->payload) {
- UA_ERR("_ua_create_ua_ble_payload_s() failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
- }
-
- device->payload->device_icon = device_icon;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_purpose(
- ua_device_h handle,
- const char purpose)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- _ua_create_ua_ble_payload_s(&device->payload);
- if (!device->payload) {
- UA_ERR("_ua_create_ua_ble_payload_s() failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
- }
-
- device->payload->purpose = purpose;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_duid(
- ua_device_h handle,
- unsigned int duid_len,
- const char *duid)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(duid);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
- retv_if(duid_len != UA_BLE_PAYLOAD_DUID_LEN, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- _ua_create_ua_ble_payload_s(&device->payload);
- if (!device->payload) {
- UA_ERR("_ua_create_ua_ble_payload_s() failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
- }
-
- g_free(device->payload->duid);
- device->payload->duid = NULL;
-
- device->payload->duid = g_malloc0(UA_BLE_PAYLOAD_DUID_LEN + 1);
- if (device->payload->duid == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- memcpy(device->payload->duid, duid, UA_BLE_PAYLOAD_DUID_LEN);
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_mac_address(
- ua_device_h device_handle,
- char **mac_address)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(mac_address);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- if (!device->mac) {
- /* LCOV_EXCL_START */
- *mac_address = NULL;
- goto done;
- /* LCOV_EXCL_STOP */
- }
-
- *mac_address = g_strdup(device->mac);
-
- if (*mac_address == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_os_info(
- ua_device_h device_handle,
- ua_os_type_e *os_info
- )
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(os_info);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- *os_info = device->os;
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_device_id(
- ua_device_h device_handle,
- char **device_id)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_PRINT_DEVICE_HANDLE(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(device_id);
-
- if (!device->device_id) {
- *device_id = NULL;
- goto done;
- }
-
- *device_id = g_strdup(device->device_id);
-
- if (*device_id == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_wifi_bssid(
- ua_device_h device_handle,
- char **bssid)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(bssid);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- if (!device->bssid) {
- *bssid = NULL;
- goto done;
- }
-
- *bssid = g_strdup(device->bssid);
-
- if (*bssid == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_wifi_ipv4_address(
- ua_device_h device_handle,
- char **ipv4_address)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(ipv4_address);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- if (!device->ipv4) {
- /* LCOV_EXCL_START */
- *ipv4_address = NULL;
- goto done;
- /* LCOV_EXCL_STOP */
- }
-
- *ipv4_address = g_strdup(device->ipv4);
-
- if (*ipv4_address == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_discriminant(
- ua_device_h device_handle,
- bool *discriminant)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(discriminant);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- *discriminant = device->discriminant;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_last_presence(
- ua_device_h device_handle,
- long *timestamp)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_INPUT_PARAMETER(timestamp);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- *timestamp = device->last_presence_timestamp;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_payload_service_id(
- ua_device_h handle,
- char *service_id)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(service_id);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- *service_id = 0x00;
- UA_DBG("payload(service_id) is not found");
- goto done;
- }
-
- *service_id = device->payload->service_id;
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_payload_device_icon(
- ua_device_h handle,
- char *device_icon)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(device_icon);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- *device_icon = 0x00;
- UA_DBG("payload(device_icon) is not found");
- goto done;
- }
-
- *device_icon = device->payload->device_icon;
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-int ua_device_get_payload_purpose(
- ua_device_h handle,
- char *purpose)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(purpose);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload) {
- *purpose = 0x00;
- UA_DBG("payload(purpose) is not found");
- goto done;
- }
-
- *purpose = device->payload->purpose;
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_payload_duid(
- ua_device_h handle,
- char **duid)
-{
- FUNC_ENTRY;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(duid);
- UA_PRINT_DEVICE_HANDLE(handle);
- retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
- if (!device->payload || !device->payload->duid) {
- *duid = NULL;
- UA_DBG("payload(duid) is not found");
- goto done;
- }
-
- *duid = g_memdup(device->payload->duid, UA_BLE_PAYLOAD_DUID_LEN);
- if (*duid == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_memdup failed");
- return UA_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_by_mac_address(
- const char *mac,
- ua_device_h *device_handle)
-{
- FUNC_ENTRY;
- GSList *l;
- int ret;
- ua_dev_info_s *dev;
- uam_device_info_s uam_dev;
-
- UA_VALIDATE_INPUT_PARAMETER(mac);
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
-
- for (l = ua_devices_list; l; l = g_slist_next(l)) {
- dev = (ua_dev_info_s *)l->data;
-
- if (!g_strcmp0(mac, dev->mac)) {
- UA_INFO("MAC found [%s]", dev->mac);
- *device_handle = (ua_device_h)dev;
- goto done;
- }
- }
-
- /* LCOV_EXCL_START */
- ret = _ua_get_error_code(_uam_request_get_device_by_mac(mac, &uam_dev));
- if (UA_ERROR_NONE != ret) {
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- *device_handle = NULL;
- return ret;
- }
-
- dev = g_malloc0(sizeof(ua_dev_info_s));
- if (!dev) {
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->user = NULL;
- dev->bssid = NULL;
- dev->ipv6 = NULL;
-
- dev->mac = g_strdup(uam_dev.mac);
-
- if (dev->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->ipv4 = g_strdup(uam_dev.ipv4_addr);
-
- if (dev->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->device_id = g_strdup(uam_dev.device_id);
-
- if (dev->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->payload = _ua_get_payload_from_uam(&uam_dev.payload);
- if (dev->payload == NULL) {
- UA_ERR("_ua_get_payload_from_uam() failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->type = __to_ua_mac_type(uam_dev.type);
- dev->pairing_required = FALSE;
- dev->discriminant= uam_dev.discriminant;
- dev->os = uam_dev.operating_system;
- dev->isadded = true;
-
- /* Add device to list of devices */
- *device_handle = (ua_device_h)dev;
- dev->handle = *device_handle;
- ua_devices_list = g_slist_append(ua_devices_list, dev);
- /* LCOV_EXCL_STOP */
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_get_by_device_id(
- const char *device_id,
- ua_mac_type_e mac_type,
- ua_device_h *device_handle)
-{
- FUNC_ENTRY;
- GSList *l;
- int ret;
- ua_dev_info_s *dev;
- uam_device_info_s uam_dev;
- uam_tech_type_e type;
-
- UA_VALIDATE_INPUT_PARAMETER(device_id);
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- retv_if(UA_MAC_TYPE_NONE >= mac_type, UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_INVALID <= mac_type), UA_ERROR_INVALID_PARAMETER);
-
- for (l = ua_devices_list; l; l = g_slist_next(l)) {
- dev = (ua_dev_info_s *)l->data;
-
- if ((mac_type == dev->type) && !g_strcmp0(device_id, dev->device_id)) {
- UA_INFO("Mobile ID found [%s]", dev->device_id);
- *device_handle = (ua_device_h)dev;
- goto done;
- }
- }
-
- /* LCOV_EXCL_START */
- type = _ua_to_uam_tech_type(mac_type);
- ret = _ua_get_error_code(_uam_request_get_device_by_deviceid(device_id, type, &uam_dev));
- if (UA_ERROR_NONE != ret) {
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- *device_handle = NULL;
- return ret;
- }
-
- dev = g_malloc0(sizeof(ua_dev_info_s));
- if (!dev) {
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->user = NULL;
- dev->bssid = NULL;
- dev->ipv6 = NULL;
-
- dev->mac = g_strdup(uam_dev.mac);
-
- if (dev->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->ipv4 = g_strdup(uam_dev.ipv4_addr);
-
- if (dev->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->device_id = g_strdup(uam_dev.device_id);
-
- if (dev->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->payload = _ua_get_payload_from_uam(&uam_dev.payload);
- if (dev->payload == NULL) {
- UA_ERR("_ua_get_payload_from_uam() failed");
- *device_handle = NULL;
- _ua_free_ua_device_info_t((gpointer)dev);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- dev->type = __to_ua_mac_type(uam_dev.type);
- dev->pairing_required = FALSE;
- dev->os = uam_dev.operating_system;
- dev->discriminant= uam_dev.discriminant;
- dev->isadded = true;
-
- /* Add device to list of devices */
- *device_handle = (ua_device_h)dev;
- dev->handle = *device_handle;
- ua_devices_list = g_slist_append(ua_devices_list, dev);
- /* LCOV_EXCL_STOP */
-
-done:
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_device_update(ua_device_h device_handle)
-{
- int ret;
- gboolean is_registered = false;
- uam_device_info_s uam_device;
- ua_dev_info_s *device = (ua_dev_info_s *)device_handle;
- UA_PRINT_DEVICE_HANDLE(device);
-
- retv_if((device->device_id == NULL || device->mac == NULL), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
-
- memset(&uam_device, 0, sizeof(uam_device_info_s));
-
- uam_device.operating_system = device->os;
- uam_device.type = _ua_to_uam_tech_type(device->type);
- uam_device.discriminant = device->discriminant;
-
- if (device->mac)
- g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
-
- if (device->device_id)
- g_strlcpy(uam_device.device_id, device->device_id, UA_MOBILE_ID_STRING_LEN);
-
- if (device->ipv4)
- g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
-
- _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
-
- ret = _ua_get_error_code(_uam_is_device_registered(&uam_device, &is_registered));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- if (!is_registered) {
- /* LCOV_EXCL_START */
- UA_ERR("No registerd device");
- /* LCOV_EXCL_STOP */
- return UA_ERROR_INVALID_PARAMETER;
- }
-
- ret = _ua_get_error_code(_uam_request_update_device(&uam_device));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("_uam_request_set_device_update returned %s",
- _ua_get_error_string(ret));
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_user_foreach_added(
- ua_registered_user_cb foreach_cb,
- void *user_data)
-{
- FUNC_ENTRY;
- GSList *l;
- ua_user_info_s *u;
-
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
-
- for (l = ua_users_list; l; l = g_slist_next(l)) {
- u = (ua_user_info_s *)l->data;
-
- if (!foreach_cb(u->user_handle, user_data))
- break;
- }
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int _ua_foreach_registered_users(
- ua_registered_user_cb foreach_cb,
- void *user_data)
-{
- FUNC_ENTRY;
- int i;
- int ret;
- GPtrArray *user_list = NULL;
- uam_user_info_s *ptr;
-
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
-
- user_list = g_ptr_array_new();
- retv_if(NULL == user_list, UA_ERROR_OUT_OF_MEMORY);
-
- ret = _ua_get_error_code(_uam_get_registered_users(&user_list));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- g_ptr_array_free(user_list, TRUE);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- for (i = 0; i < user_list->len; i++) {
- ptr = g_ptr_array_index(user_list, i);
- if (ptr) {
- ua_user_info_s* user_info;
- user_info = g_malloc0(sizeof(ua_user_info_s));
-
- if (!user_info) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_user_info_t(user_info);
- /* LCOV_EXCL_STOP */
- goto done;
- }
-
- user_info->account = g_strdup(ptr->account);
-
- if (user_info->account == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_user_info_t(user_info);
- /* LCOV_EXCL_STOP */
- goto done;
- }
-
- user_info->name = g_strdup(ptr->name);
-
- if (user_info->name == NULL) {
- /* LCOV_EXCL_START */
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_user_info_t(user_info);
- /* LCOV_EXCL_STOP */
- goto done;
- }
-
- user_info->isadded = true;
- user_info->user_handle = (ua_user_h)user_info;
- if (!foreach_cb(user_info->user_handle, user_data)) {
- _ua_free_ua_user_info_t(user_info);
- break;
- } else
- _ua_free_ua_user_info_t(user_info);
- } else {
- /* LCOV_EXCL_START */
- UA_ERR("OPERATION_FAILED(0x%08x)",
- UA_ERROR_OPERATION_FAILED);
- ret = UA_ERROR_OPERATION_FAILED;
- /* LCOV_EXCL_STOP */
- goto done;
- }
- }
-
-done:
- g_ptr_array_foreach(user_list, (GFunc)g_free, NULL);
- g_ptr_array_free(user_list, TRUE);
-
- FUNC_EXIT;
- return ret;
-}
-
-int ua_device_clone(ua_device_h *cloned,
- ua_device_h origin)
-{
- FUNC_ENTRY;
- int ret;
- ua_dev_info_s *device;
- uam_user_info_s uam_user;
- ua_dev_info_s *org_device = (ua_dev_info_s *)origin;
-
- /* LCOV_EXCL_START */
- UA_VALIDATE_INPUT_PARAMETER(cloned);
- UA_VALIDATE_INPUT_PARAMETER(origin);
- UA_VALIDATE_HANDLE(origin, ua_devices_db_list);
- UA_EXIST_HANDLE(origin, ua_devices_list);
-
- device = __ua_get_device_from_list(org_device->device_id,
- org_device->mac, org_device->type);
- if (device) {
-//TODO lk, in this case cloned will be destroyed as per description of API, which will then delete device from list. ???
- *cloned = (ua_device_h)device;
- return UA_ERROR_NONE;
- }
-
- device = g_malloc0(sizeof(ua_dev_info_s));
- if (!device) {
- UA_ERR("g_malloc0 failed");
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- device->mac = g_strdup(org_device->mac);
- if (device->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- device->ipv4 = g_strdup(org_device->ipv4);
- if (device->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- device->device_id = g_strdup(org_device->device_id);
- if (device->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- device->payload = _ua_payload_clone(org_device->payload);
- if (device->payload == NULL && org_device->payload) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device);
- return UA_ERROR_OUT_OF_MEMORY;
- }
-
- device->isadded = org_device->isadded;
- device->type = org_device->type;
- device->os = org_device->os;
- device->discriminant = org_device->discriminant;
- device->last_presence_timestamp = org_device->last_presence_timestamp;
-
- if (!device->user) {
- /* Currently user info will be create and store at this point */
- ret = _ua_get_error_code(_uam_request_get_user_by_deviceid(device->device_id, &uam_user));
- if (UA_ERROR_NONE != ret) {
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- _ua_free_ua_device_info_t((gpointer)device);
- return ret;
- } else {
- GSList *l;
- ua_user_info_s *user_info;
- int found = 0;
-
- for (l = ua_users_list; l; l = g_slist_next(l)) {
- user_info = (ua_user_info_s *)l->data;
-
- if (!g_strcmp0(uam_user.account, user_info->account)) {
- UA_INFO("User found [%s]", user_info->account);
- device->user = (ua_user_h)user_info;
- found = 1;
- break;
- }
- }
-
- if (!found)
- UA_ERR("User not found [%s]", uam_user.account);
- else
- UA_ERR("User found [%s]", uam_user.account);
-
- }
- } else
- UA_INFO("user handle is already present!");
-
- /* Add device to list of devices */
- *cloned = (ua_device_h)device;
- device->handle = (ua_device_h)device;
- device->create_by_app = true;
- ua_devices_list = g_slist_append(ua_devices_list, device);
-
- FUNC_EXIT;
- /* LCOV_EXCL_STOP */
- return UA_ERROR_NONE;
-}
-
-int ua_user_add_device(ua_user_h user_handle, ua_device_h device_handle,
- ua_user_device_added_cb callback, void *user_data)
-{
- FUNC_ENTRY;
- int ret;
- ua_user_h handle = NULL;
- ua_user_h temp_handle = NULL;
- ua_dev_info_s *device = (ua_dev_info_s *) device_handle;
- ua_user_info_s* user = NULL;
- uam_device_info_s uam_device;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
- retv_if((((device->device_id == NULL) && (device->mac == NULL))), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
-
- temp_handle = device->user;
- if (user_handle == NULL) {
- /* LCOV_EXCL_START */
- ret = ua_user_get_default_user(&handle);
- if (ret != UA_ERROR_NONE) {
- UA_ERR("Failed to get default user with error");
- return ret;
- }
-
- device->user = (ua_user_h)handle;
- /* LCOV_EXCL_STOP */
- } else {
- UA_VALIDATE_HANDLE(user_handle, ua_users_list);
- device->user = user_handle;
- }
-
- user = (ua_user_info_s *)device->user;
- memset(&uam_device, 0, sizeof(uam_device_info_s));
-
- uam_device.operating_system = device->os;
- uam_device.type = _ua_to_uam_tech_type(device->type);
- uam_device.discriminant = device->discriminant;
-
- if (device->mac)
- g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
-
- g_strlcpy(uam_device.device_id, device->device_id, UA_MOBILE_ID_STRING_LEN);
-
- if (device->ipv4)
- g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
-
- _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
-
- ret = _ua_get_error_code(_uam_request_add_device(user->account, &uam_device));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- device->user = temp_handle;
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- user_callbacks[UA_USER_EVENT_DEVICE_ADDED].callback = callback;
- user_callbacks[UA_USER_EVENT_DEVICE_ADDED].user_data = user_data;
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle)
-{
- FUNC_ENTRY;
- int ret;
- ua_user_h handle = NULL;
- ua_dev_info_s *device = (ua_dev_info_s *) device_handle;
- ua_user_info_s* user = NULL;
- uam_device_info_s uam_device;
-
- UA_VALIDATE_INPUT_PARAMETER(device_handle);
- UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
- retv_if((((device->device_id == NULL) && (device->mac == NULL))), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
-
- if (user_handle == NULL) {
- /* LCOV_EXCL_START */
- ret = ua_user_get_default_user(&handle);
- if (ret != UA_ERROR_NONE) {
- UA_ERR("Failed to get default user with error");
- return ret;
- }
-
- user = (ua_user_info_s *)handle;
- /* LCOV_EXCL_STOP */
- } else {
- UA_VALIDATE_HANDLE(user_handle, ua_users_list);
- retv_if((device->user != user_handle), UA_ERROR_INVALID_PARAMETER);
- user = (ua_user_info_s *)user_handle;
- }
-
- memset(&uam_device, 0, sizeof(uam_device_info_s));
- uam_device.operating_system = device->os;
- uam_device.type = _ua_to_uam_tech_type(device->type);
+ memset(&uam_device, 0, sizeof(uam_device_info_s));
+ uam_device.operating_system = device->os;
+ uam_device.type = _ua_to_uam_tech_type(device->type);
if (device->mac)
g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
return UA_ERROR_NONE;
}
-int ua_device_foreach_added(
- ua_registered_dev_cb foreach_cb,
- void *user_data)
-{
- FUNC_ENTRY;
- int i;
- int ret;
- GPtrArray *devices_list = NULL;
- uam_device_info_s *ptr;
- GSList *l;
-
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
-
- devices_list = g_ptr_array_new();
- retv_if(NULL == devices_list, UA_ERROR_OUT_OF_MEMORY);
-
- ret = _ua_get_error_code(_uam_request_get_devices(&devices_list));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- g_ptr_array_free(devices_list, TRUE);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- for (i = 0; i < devices_list->len; i++) {
- /* LCOV_EXCL_START */
- ptr = g_ptr_array_index(devices_list, i);
- if (ptr) {
- ua_dev_info_s* device_info;
- device_info = g_malloc0(sizeof(ua_dev_info_s));
- if (!device_info) {
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- goto done;
- }
-
- device_info->mac = g_strdup(ptr->mac);
- if (device_info->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device_info);
- ret = UA_ERROR_OUT_OF_MEMORY;
- goto done;
- }
-
- device_info->ipv4 = g_strdup(ptr->ipv4_addr);
- if (device_info->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- _ua_free_ua_device_info_t((gpointer)device_info);
- ret = UA_ERROR_OUT_OF_MEMORY;
- goto done;
- }
-
- device_info->device_id = g_strdup(ptr->device_id);
- if (device_info->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_device_info_t((gpointer)device_info);
- goto done;
- }
-
- device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
- if (device_info->payload == NULL) {
- UA_ERR("_ua_get_payload_from_uam() failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_device_info_t((gpointer)device_info);
- goto done;
- }
-
- device_info->isadded = true;
- device_info->handle = (ua_device_h)device_info;
- device_info->type = __to_ua_mac_type(ptr->type);
- device_info->os = ptr->operating_system;
- device_info->discriminant = ptr->discriminant;
- device_info->last_presence_timestamp = ptr->last_seen;
- ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info);
- } else {
- UA_ERR("OPERATION_FAILED(0x%08x)",
- UA_ERROR_OPERATION_FAILED);
- ret = UA_ERROR_OPERATION_FAILED;
- goto done;
- }
- /* LCOV_EXCL_STOP */
- }
-
- for (l = ua_devices_db_list; l; l = g_slist_next(l)) {
- /* LCOV_EXCL_START */
- ua_dev_info_s *u = l->data;
-
- if (NULL == u)
- continue;
-
- if (!foreach_cb(u->handle, user_data))
- break;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t);
- ua_devices_db_list = NULL;
-
- g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL);
- g_ptr_array_free(devices_list, TRUE);
-
- FUNC_EXIT;
- return ret;
-}
-
-int ua_device_foreach_added_by_user(
- ua_user_h user_handle,
- ua_registered_dev_cb foreach_cb,
- void *user_data)
-{
- FUNC_ENTRY;
- int i;
- int ret;
- ua_user_info_s *user = (ua_user_info_s *)user_handle;
- GPtrArray *devices_list = NULL;
- uam_device_info_s *ptr;
- GSList *l;
-
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
- UA_VALIDATE_INPUT_PARAMETER(user_handle);
- UA_VALIDATE_HANDLE(user_handle, ua_users_list);
-
- devices_list = g_ptr_array_new();
- retv_if(NULL == devices_list, UA_ERROR_OUT_OF_MEMORY);
-
- ret = _ua_get_error_code(_uam_request_get_user_devices(user->account, &devices_list));
- if (UA_ERROR_NONE != ret) {
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- g_ptr_array_free(devices_list, TRUE);
- return ret;
- }
-
- for (i = 0; i < devices_list->len; i++) {
- /* LCOV_EXCL_START */
- ptr = g_ptr_array_index(devices_list, i);
- if (ptr) {
- ua_dev_info_s* device_info;
- device_info = g_malloc0(sizeof(ua_dev_info_s));
- if (!device_info) {
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- goto done;
- }
-
- device_info->mac = g_strdup(ptr->mac);
- if (device_info->mac == NULL) {
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_device_info_t((gpointer)device_info);
- goto done;
- }
-
- device_info->ipv4 = g_strdup(ptr->ipv4_addr);
- if (device_info->ipv4 == NULL) {
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_device_info_t((gpointer)device_info);
- goto done;
- }
-
- device_info->device_id = g_strdup(ptr->device_id);
- if (device_info->device_id == NULL) {
- UA_ERR("g_malloc0 failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_device_info_t((gpointer)device_info);
- goto done;
- }
-
- device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
- if (device_info->payload == NULL) {
- UA_ERR("_ua_get_payload_from_uam() failed");
- ret = UA_ERROR_OUT_OF_MEMORY;
- _ua_free_ua_device_info_t((gpointer)device_info);
- goto done;
- }
-
- device_info->isadded = true;
- device_info->handle = (ua_device_h)device_info;
- device_info->type = __to_ua_mac_type(ptr->type);
- device_info->os = ptr->operating_system;
- device_info->last_presence_timestamp = ptr->last_seen;
- device_info->discriminant = ptr->discriminant;
- device_info->user = (ua_user_h)user;
- ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info);
- } else {
- UA_ERR("OPERATION_FAILED(0x%08x)",
- UA_ERROR_OPERATION_FAILED);
- ret = UA_ERROR_OPERATION_FAILED;
- goto done;
- }
- /* LCOV_EXCL_STOP */
- }
-
- for (l = ua_devices_db_list; l; l = g_slist_next(l)) {
- /* LCOV_EXCL_START */
- ua_dev_info_s *u = l->data;
-
- if (NULL == u)
- continue;
-
- if (!foreach_cb(u->handle, user_data))
- break;
- /* LCOV_EXCL_STOP */
- }
-
-done:
- g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t);
- ua_devices_db_list = NULL;
-
- g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL);
- g_ptr_array_free(devices_list, TRUE);
-
- FUNC_EXIT;
- return ret;
-}
-
-int ua_device_get_pairing_required(
- ua_device_h handle,
- bool *pairing_required)
-{
- FUNC_ENTRY;
- int ret;
- ua_dev_info_s *device = (ua_dev_info_s *)handle;
- gboolean is_registered = FALSE;
- uam_device_info_s uam_device;
-
- UA_VALIDATE_INPUT_PARAMETER(handle);
- UA_VALIDATE_INPUT_PARAMETER(pairing_required);
- UA_PRINT_DEVICE_HANDLE(device_handle);
-
- retv_if((((device->device_id == NULL) && (device->mac == NULL))), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_NONE >= device->type), UA_ERROR_INVALID_PARAMETER);
- retv_if((UA_MAC_TYPE_INVALID <= device->type), UA_ERROR_INVALID_PARAMETER);
-
- memset(&uam_device, 0, sizeof(uam_device_info_s));
-
- uam_device.operating_system = device->os;
- uam_device.discriminant = device->discriminant;
- uam_device.type = _ua_to_uam_tech_type(device->type);
-
- if (device->mac)
- g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_LEN);
-
- if (device->device_id)
- g_strlcpy(uam_device.device_id, device->device_id, UA_MOBILE_ID_STRING_LEN);
-
- if (device->ipv4)
- g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
-
- ret = _ua_get_error_code(_uam_is_device_registered(&uam_device, &is_registered));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- *pairing_required = is_registered ? false : true;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
-int _ua_intr_foreach_registered_users(
- _ua_intr_registered_user_cb foreach_cb,
- void *user_data)
-{
- int ret;
- UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
-
- ret = _ua_foreach_registered_users(foreach_cb, user_data);
- return ret;
-}
-
-int _ua_intr_get_default_user(void)
-{
- FUNC_ENTRY;
- int ret;
- uam_user_info_s uam_user;
- ua_user_info_s *user = NULL;
- GSList *l;
-
- ret = _ua_get_error_code(_uam_get_default_user(&uam_user));
- if (UA_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- UA_ERR("Failed with error: %s(0x%X)",
- _ua_get_error_string(ret), ret);
- /* LCOV_EXCL_STOP */
- return ret;
- }
-
- for (l = ua_users_list; l; l = g_slist_next(l)) {
- user = (ua_user_info_s *)l->data;
-
- if (!g_strcmp0(uam_user.account, user->account)) {
- UA_INFO("User found [%s]", user->account);
- user->default_user = true;
- user->isadded = true;
- return UA_ERROR_NONE;
- }
- }
-
- /* LCOV_EXCL_START */
- user = g_malloc0(sizeof(ua_user_info_s));
- if (!user) {
- UA_ERR("Failed to allocate memory");
- return UA_ERROR_OUT_OF_MEMORY;
- }
- user->account = g_strdup(uam_user.account);
- user->name = g_strdup(uam_user.name);
- user->state = UA_PRESENCE_STATE_INACTIVATE;
- user->sensor_bitmask = 0;
- user->user_handle = (ua_user_h)user;
- user->default_user = true;
- user->isadded = true;
-
- ua_users_list = g_slist_append(ua_users_list, user);
- FUNC_EXIT;
- /* LCOV_EXCL_STOP */
- return UA_ERROR_NONE;
-}
-
-/* LCOV_EXCL_START */
-GSList *_ua_user_get_users(void)
-{
- FUNC_ENTRY;
- FUNC_EXIT;
- return ua_users_list;
-}
-
/* LCOV_EXCL_STOP */
#include <user-awareness-log.h>
#include <user-awareness-private.h>
+ua_mac_type_e _to_ua_mac_type(uam_tech_type_e tech_type)
+{
+ switch (tech_type) {
+ case UAM_TECH_TYPE_BT:
+ return UA_MAC_TYPE_BT;
+ case UAM_TECH_TYPE_BLE:
+ return UA_MAC_TYPE_BLE;
+ case UAM_TECH_TYPE_WIFI:
+ return UA_MAC_TYPE_WIFI;
+ case UAM_TECH_TYPE_P2P:
+ return UA_MAC_TYPE_P2P;
+ default:
+ return UA_MAC_TYPE_INVALID;
+ }
+}
+
int _ua_get_error_code(int ua_error)
{
switch (ua_error) {