summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/user-awareness-private.h180
-rw-r--r--include/user-awareness-type.h41
-rw-r--r--include/user-awareness.h106
-rw-r--r--packaging/capi-network-ua.spec2
-rw-r--r--src/user-awareness-event-handler.c194
-rw-r--r--src/user-awareness-monitors.c878
-rw-r--r--src/user-awareness-users.c892
-rw-r--r--test/user-awareness-test.c678
-rw-r--r--test/user-awareness-test.h31
10 files changed, 2642 insertions, 362 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4a0b6ef..6657dfd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,4 +74,4 @@ CONFIGURE_FILE(
)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc DESTINATION ${LIB_PKGCONFIG_DIR})
-#ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(test)
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h
index 7c80c20..d5f5d41 100644
--- a/include/user-awareness-private.h
+++ b/include/user-awareness-private.h
@@ -69,6 +69,23 @@ extern "C" {
} \
} \
+#define UA_EXIST_HANDLE(h1, list) \
+ { \
+ GSList *l; \
+ bool valid = FALSE; \
+ for (l = list; l; l = g_slist_next(l)) { \
+ void *h2 = (void *)l->data; \
+ if (h1 == h2) { \
+ UA_INFO("Handle matched [%p]", h2); \
+ valid = TRUE; break; \
+ } \
+ } \
+ if (valid == TRUE) { \
+ UA_ERR("Handle [%p] match with any stored handles!!", h1); \
+ return UA_ERROR_ALREADY_DONE; \
+ } \
+ } \
+
#define UA_INITIALIZE() \
{ \
int ret = ua_initialize(); \
@@ -89,53 +106,124 @@ extern "C" {
#define UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME 200
-typedef struct {
- const void *callback;
- void *user_data;
-} ua_callback_t;
-
-typedef struct {
- unsigned int sensor_bitmask;
- unsigned int detected_bitmask;
- GSList *sensors;
- ua_detection_mode_e mode;
- gboolean detection_started;
- unsigned int detection_timer;
- unsigned int all_absence_timer;
- unsigned int all_presence_timer;
- ua_callback_t sensor_state_cb;
- ua_persence_detected_cb presence_cb;
- ua_absence_detected_cb absence_cb;
- void *user_data;
-} ua_monitor_t;
-
-typedef struct {
- ua_monitor_t *monitor;
- ua_sensor_e type;
- unsigned short absence_period;
- unsigned int absence_timer;
- unsigned int detection_timer;
-} ua_sensors_t;
-
-typedef struct {
- ua_user_h user_handle;
- ua_presence_state_e state;
- char* account;
- char* name;
- gboolean isadded;
-} ua_user_info_t;
-
-ua_user_h _ua_user_add_to_list(ua_user_info_t *user);
-
-int ua_initialize(void);
-
-int ua_deinitialize(void);
-
-void _ua_monitor_handle_user_presence_detected(
- unsigned int bitmask, ua_user_info_t *user_info);
-
-void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready);
+ typedef struct {
+ const void *callback;
+ void *user_data;
+ } ua_callback_t;
+
+ typedef struct {
+ unsigned int sensor_bitmask;
+ unsigned int presence_detected_bitmask;
+ unsigned int absence_detected_bitmask;
+ ua_detection_mode_e presence_mode;
+ ua_detection_mode_e absence_mode;
+ gboolean presence_detection_started;
+ gboolean absence_detection_started;
+ unsigned int presence_detection_timer;
+ unsigned int absence_detection_timer;
+ ua_callback_t sensor_state_cb;
+ ua_persence_detected_cb presence_cb;
+ ua_absence_detected_cb absence_cb;
+ void *user_data;
+ } ua_monitor_t;
+
+ typedef struct {
+ ua_monitor_t *monitor;
+ ua_sensor_e type;
+ unsigned short absence_period;
+ unsigned int absence_timer;
+ unsigned int detection_timer;
+ } ua_sensors_t;
+
+ typedef struct {
+ ua_user_h user_handle;
+ ua_presence_state_e state;
+ char* account;
+ char* name;
+ gboolean isadded;
+ gboolean default_user;
+ gboolean create_by_app;
+ } ua_user_info_t;
+
+ typedef enum {
+ UA_PRESENCE_DETECTION = 0x00,
+ UA_ABSENCE_DETECTION
+ } ua_detection_type_e;
+
+ typedef struct {
+ ua_user_h user;
+ ua_device_h handle;
+ char *mac;
+ char *bssid;
+ char *ipv4;
+ char *ipv6;
+ char *mobile_id;
+ ua_mac_type_e type;
+ bool pairing_required;
+ ua_presence_state_e state;
+ ua_os_type_e os;
+ gboolean isadded;
+ gboolean create_by_app;
+ } ua_dev_info_t;
+
+ int ua_initialize(void);
+
+ int ua_deinitialize(void);
+
+ void _ua_monitor_handle_user_presence_detected(
+ unsigned int bitmask, ua_user_info_t *user_info);
+
+ void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready);
+
+ void _ua_monitor_handle_user_absence_detected(
+ unsigned int bitmask, ua_user_info_t *user_info);
+
+ void _ua_free_ua_device_info_t(ua_dev_info_t *device);
+
+ void _ua_free_ua_user_info_t(ua_user_info_t *user);
+
+ int _ua_add_user_info_to_local_db(ua_user_info_t* user_info);
+
+ int _ua_mark_user_info_state_db(char* account, int state);
+
+ bool _ua_check_all_users_absence();
+
+ int _ua_remove_user_info_from_local_db(ua_user_info_t* user_info);
+
+ int _ua_add_user_info_to_list(ua_user_info_t* ua_info);
+
+ int _ua_add_user_info_to_list_from_uapi_data(uam_user_info_t* uam_info);
+
+ int _ua_remove_user_info_from_list(char* account);
+
+ int _ua_add_device_info_to_list(uam_device_info_t* uam_info);
+
+ int _ua_remove_device_info_from_list(uam_device_info_t* uam_info);
+
+ ua_user_h _ua_make_user_handle_from_uapi_data(uam_user_info_t *ptr);
+
+ ua_user_h _ua_make_user_handle_from_local_data(ua_user_info_t *ptr);
+
+ typedef bool (*_ua_intr_registered_user_cb)(
+ ua_user_h user_handle,
+ void *user_data
+ );
+
+ int _ua_intr_foreach_registered_users(
+ _ua_intr_registered_user_cb foreach_cb,
+ void *user_data);
+
+ int _ua_foreach_registered_users(
+ ua_registered_user_cb foreach_cb,
+ void *user_data);
+
+ int _ua_is_user_exist(char* account, gboolean* is_exist);
+
+ int _ua_intr_get_default_user();
+
+ ua_user_h _ua_get_user_handle_by_account(char* account);
+ int _ua_is_device_exist(char* mobile_id, char* mac, ua_mac_type_e type, gboolean* is_exist);
#ifdef __cplusplus
}
#endif
diff --git a/include/user-awareness-type.h b/include/user-awareness-type.h
index 2b72dcc..3cc26c1 100644
--- a/include/user-awareness-type.h
+++ b/include/user-awareness-type.h
@@ -34,17 +34,19 @@ extern "C" {
#define UA_IPV4_ADDRESS_STRING_SIZE 16
#define UA_IP_ADDRESS_MAX_STRING_SIZE 50
#define UA_MOBILE_ID_STRING_SIZE 50
+#define UA_USER_NAME_MAX_STRING_SIZE 50
+#define UA_USER_ACCOUNT_MAX_STRING_SIZE 70
#define TIZEN_ERROR_UA 0x10000000
/**
- * @file uaer-awareness-type.h
- */
+ * @file uaer-awareness-type.h
+ */
- /**
- * @ingroup CAPI_NETWORK_FRAMEWORK
- * @addtogroup CAPI_NETWORK_UA_MODULE User Awareness
- * @{
- */
+ /**
+ * @ingroup CAPI_NETWORK_FRAMEWORK
+ * @addtogroup CAPI_NETWORK_UA_MODULE User Awareness
+ * @{
+ */
/**
* @ingroup CAPI_NETWORK_UA_MODULE
@@ -155,31 +157,6 @@ extern "C" {
/**
* @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Structure of user device info.
- *
- * @see #ua_os_type_e
- * @see #ua_mac_type_e
- * @see #ua_user_h
- * @see #ua_device_h
- * @see #ua_presence_state_e
- */
- typedef struct {
- ua_user_h user;
- ua_device_h handle;
- char *mac;
- char *bssid;
- char *ipv4;
- char *ipv6;
- char *mobile_id;
- ua_mac_type_e type;
- bool pairing_required;
- ua_presence_state_e state;
- ua_os_type_e os;
- gboolean isadded;
- } ua_dev_info_t;
-
- /**
- * @ingroup CAPI_NETWORK_UA_MODULE
* @brief Callback to be invoked if a sensor state changed (ready <-> not ready)
*
* @param[in] ready TRUE is sensor is ready FALSE otherwise.
diff --git a/include/user-awareness.h b/include/user-awareness.h
index 0868181..461b621 100644
--- a/include/user-awareness.h
+++ b/include/user-awareness.h
@@ -92,8 +92,8 @@ extern "C" {
*
*/
int ua_monitor_add_sensor(
- ua_monitor_h monitor,
- ua_sensor_e sensor
+ ua_monitor_h handle,
+ ua_sensor_e sensor_type
);
/**
@@ -110,8 +110,8 @@ extern "C" {
*
*/
int ua_monitor_remove_sensor(
- ua_monitor_h monitor,
- ua_sensor_e sensor
+ ua_monitor_h handle,
+ ua_sensor_e sensor_type
);
/**
@@ -157,7 +157,8 @@ extern "C" {
* @brief Set the brightness threshold level for detecting absence or presence.
*
* @param[in] handle - UA monitor's handle
- * @param[in] threshold - threshold value, in lux level
+ * @param[in] presence_threshold - presence threshold value, in lux level
+ * @param[in] absence_threshold - absence threshold value, in lux level
*
* @return 0 on success, otherwise a negative error value
* @retval #UA_ERROR_NONE - Successful
@@ -167,7 +168,8 @@ extern "C" {
*/
int ua_monitor_set_brightness_threshold(
ua_monitor_h handle,
- int threshold
+ int presence_threshold,
+ int absence_threshold
);
/**
@@ -430,6 +432,40 @@ extern "C" {
);
/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Get name info for user handle.
+ *
+ * @param[in] user_handle - User handle
+ * @param[out] name - account information
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_NOT_SUPPORTED Not supported
+ *
+ */
+ int ua_user_get_name(
+ ua_user_h user_handle,
+ char** name);
+
+ /**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Set name info for user handle.
+ *
+ * @param[in] user_handle - User handle
+ * @param[out] name - account information
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_NOT_SUPPORTED Not supported
+ *
+ */
+ int ua_user_set_name(
+ ua_device_h handle,
+ const char* name);
+
+ /**
* @ingroup capi_ua_module
* @brief Sets device's operating system info.
*
@@ -605,6 +641,24 @@ extern "C" {
/**
* @ingroup capi_ua_module
+ * @brief Gets device's os info.
+ *
+ *
+ * @param[in] device_handle - device handle
+ * @param[out] os_info - device's os info.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #ua_error_none successful
+ * @retval #ua_error_invalid_parameter invalid parameter
+ * @retval #ua_error_not_supported not supported
+ *
+ */
+ int ua_device_get_os_info(
+ ua_device_h device_handle,
+ ua_os_type_e *os_info
+ );
+ /**
+ * @ingroup capi_ua_module
* @brief Gets device handle by mac address.
*
* @param[in] mac - mac address
@@ -618,7 +672,7 @@ extern "C" {
*/
int ua_device_get_handle_by_mac_address(
const char* mac,
- ua_device_h * device_handle
+ ua_device_h *device_handle
);
/**
@@ -769,6 +823,42 @@ extern "C" {
/**
* @ingroup capi_ua_module
+ * @brief to clone user handle if application wants to store it after foreach.
+ * It should be call before foreach callback return.
+ *
+ * @param[out] cloned - cloned user handle.
+ * @param[in] origin - input user handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #ua_error_none successful
+ * @retval #ua_error_invalid_parameter invalid parameter
+ * @retval #ua_error_not_supported not supported
+ *
+ * @see ua_registered_user_cb()
+ */
+ int ua_user_clone(ua_user_h *cloned,
+ ua_user_h origin);
+
+ /**
+ * @ingroup capi_ua_module
+ * @brief to clone user handle if application wants to store it after foreach.
+ * It should be call before foreach callback return.
+ *
+ * @param[out] cloned - cloned device handle.
+ * @param[in] origin - input device handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #ua_error_none successful
+ * @retval #ua_error_invalid_parameter invalid parameter
+ * @retval #ua_error_not_supported not supported
+ *
+ * @see ua_registered_dev_cb()
+ */
+ int ua_device_clone(ua_device_h *cloned,
+ ua_device_h origin);
+
+ /**
+ * @ingroup capi_ua_module
* @brief get all users.
*
* @param[in] foreach_cb - Callback function to be invoked with user handle.
@@ -781,7 +871,7 @@ extern "C" {
*
* @see ua_registered_user_cb()
*/
- int ua_foreach_registered_user(
+ int ua_foreach_registered_users(
ua_registered_user_cb foreach_cb,
void *user_data
);
diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec
index 5555159..9d5c5ac 100644
--- a/packaging/capi-network-ua.spec
+++ b/packaging/capi-network-ua.spec
@@ -80,4 +80,4 @@ make %{?jobs:-j%jobs}
%files test
%manifest %{name}.manifest
-#%{_bindir}/ua-test
+%{_bindir}/ua-test
diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c
index 5bfe89e..5190f3e 100644
--- a/src/user-awareness-event-handler.c
+++ b/src/user-awareness-event-handler.c
@@ -33,20 +33,178 @@ static gboolean is_initialized = FALSE;
static void __ua_event_handler(int event, uam_event_data_t *event_param, void *user_data)
{
FUNC_ENTRY;
- int result;
+ //int result;
ret_if(NULL == event_param);
- result = event_param->result;
+ //result = event_param->result;
- switch (result) {
+ switch (event) {
case UAM_EVENT_USER_PRESENCE_DETECTED: {
+ uam_presence_detected_event_data_t *event_data = NULL;
+ ua_user_info_t* user_info;
+ ua_user_h user_handle = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+
+ if ((event_data->sensor_bitmask & UAM_SENSOR_BITMASK_BLE) || (event_data->sensor_bitmask & UAM_SENSOR_BITMASK_WIFI)) {
+
+ user_handle = _ua_get_user_handle_by_account(event_data->user_info.account);
+
+ if (user_handle) {
+ user_info = (ua_user_info_t*) user_handle;
+ } else {
+ /* TODO : This else case is to be remove as user handle will always available
+ * so there should not be a case when application need to clone it at this point
+ * This section of code will be remove
+ */
+ user_info = g_malloc0(sizeof(ua_user_info_t));
+ if (!user_info)
+ UA_ERR("g_malloc0 failed");
+
+ user_info->account = strndup(event_data->user_info.account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+
+ if (user_info->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ break;
+ }
+
+ user_info->name = strndup(event_data->user_info.name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ if (user_info->name == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ break;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+ user_info->state = event_data->user_info.presence_state;
+ }
+
+ _ua_monitor_handle_user_presence_detected(
+ event_data->sensor_bitmask, user_info);
+ } else
+ _ua_monitor_handle_user_presence_detected(
+ event_data->sensor_bitmask, NULL);
+ break;
+ }
+ case UAM_EVENT_USER_ABSENCE_DETECTED: {
+ uam_absence_detected_event_data_t *event_data = NULL;
+ ua_user_info_t* user_info;
+ ua_user_h user_handle = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+
+ if ((event_data->sensor_bitmask & UAM_SENSOR_BITMASK_BLE) || (event_data->sensor_bitmask & UAM_SENSOR_BITMASK_WIFI)) {
+
+ user_handle = _ua_get_user_handle_by_account(event_data->user_info.account);
+
+ if (user_handle) {
+ user_info = (ua_user_info_t*) user_handle;
+ } else {
+ /* TODO : This else case is to be remove as user handle will always available
+ * so there should not be a case when application need to clone it at this point
+ * This section of code will be remove
+ */
+ user_info = g_malloc0(sizeof(ua_user_info_t));
+ if (!user_info)
+ UA_ERR("g_malloc0 failed");
+
+ user_info->account = strndup(event_data->user_info.account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+
+ if (user_info->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ break;
+ }
+
+ user_info->name = strndup(event_data->user_info.name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ if (user_info->name == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ break;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+ user_info->state = event_data->user_info.presence_state;
+ }
+
+ _ua_monitor_handle_user_absence_detected(
+ event_data->sensor_bitmask, user_info);
+ } else
+ _ua_monitor_handle_user_absence_detected(
+ event_data->sensor_bitmask, NULL);
break;
}
case UAM_EVENT_SENSOR_STATE_READY: {
+ unsigned int *sensor_bitmask = event_param->data;
+
+ ret_if(NULL == sensor_bitmask);
+
+ _ua_monitor_handle_sensor_state(*sensor_bitmask, TRUE);
break;
}
case UAM_EVENT_SENSOR_STATE_NOT_READY: {
+ unsigned int *sensor_bitmask = event_param->data;
+
+ ret_if(NULL == sensor_bitmask);
+ ret_if(0 == *sensor_bitmask);
+
+ _ua_monitor_handle_sensor_state(*sensor_bitmask, FALSE);
+ break;
+ }
+ case UAM_EVENT_USER_ADDED: {
+ uam_user_info_t *event_data = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+
+ if (_ua_add_user_info_to_list_from_uapi_data(event_data) != UA_ERROR_NONE)
+ UA_ERR("Fail to add user");
+ else
+ UA_INFO("User Added");
+ break;
+ }
+ case UAM_EVENT_USER_REMOVED: {
+ uam_user_info_t *event_data = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+
+ if (_ua_remove_user_info_from_list(event_data->account) != UA_ERROR_NONE)
+ UA_ERR("Fail to remove user");
+ else
+ UA_INFO("Removed user");
+ break;
+ }
+ case UAM_EVENT_DEVICE_ADDED: {
+ uam_device_info_t *event_data = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+
+ if (_ua_add_device_info_to_list(event_data) != UA_ERROR_NONE)
+ UA_ERR("Fail to add device");
+ else
+ UA_INFO("Device Added");
+ break;
+ }
+ case UAM_EVENT_DEVICE_REMOVED: {
+ uam_device_info_t *event_data = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+
+ if (_ua_remove_device_info_from_list(event_data) != UA_ERROR_NONE)
+ UA_ERR("Fail to remove device");
+ else
+ UA_INFO("Removed device");
break;
}
default:
@@ -57,6 +215,22 @@ static void __ua_event_handler(int event, uam_event_data_t *event_param, void *u
FUNC_EXIT;
}
+static bool __foreach_intr_registered_user_info(
+ ua_user_h handle, void *user_data)
+{
+ int ret;
+ ua_user_info_t* user_info;
+ retv_if(NULL == handle, false);
+
+ user_info = (ua_user_info_t*)handle;
+ /* TODO : Initial state need to be set INACTIVATE to handle absence case */
+ ret = _ua_add_user_info_to_list(user_info);
+
+ if (ret != UA_ERROR_NONE)
+ return false;
+ else
+ return true;
+}
int ua_initialize(void)
{
@@ -72,6 +246,20 @@ int ua_initialize(void)
return ret;
}
+ ret = _ua_intr_foreach_registered_users(__foreach_intr_registered_user_info, NULL);
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
+ ret = _ua_intr_get_default_user();
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
is_initialized = TRUE;
FUNC_EXIT;
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index 9188783..02a2df6 100644
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -28,7 +28,6 @@
#include <user-awareness-private.h>
#include <user-awareness-util.h>
-#define VD_REQ
#define UA_MONITORING_TIME 60 /* Default: 60 seconds for scanning for device */
#define REF(val) \
@@ -47,26 +46,168 @@
UA_DBG("UNREF: %s = %d", #val, val); \
}
+static GSList *ua_monitor_list;
+static char ref_count[UA_SENSOR_MAX];
+
+static unsigned int __ua_sensor_type_to_bitmask(ua_sensor_e sensor_type)
+{
+ FUNC_ENTRY;
+ unsigned int bitmask;
+ switch (sensor_type) {
+ case UA_SENSOR_BT:
+ bitmask = UAM_SENSOR_BITMASK_BT;
+ break;
+ case UA_SENSOR_BLE:
+ bitmask = UAM_SENSOR_BITMASK_BLE;
+ break;
+ case UA_SENSOR_WIFI:
+ bitmask = UAM_SENSOR_BITMASK_WIFI;
+ break;
+ case UA_SENSOR_MOTION:
+ bitmask = UAM_SENSOR_BITMASK_MOTION;
+ break;
+ case UA_SENSOR_BRIGHTNESS:
+ bitmask = UAM_SENSOR_BITMASK_BRIGHTNESS;
+ break;
+ case UA_SENSOR_AUDIO:
+ bitmask = UAM_SENSOR_BITMASK_AUDIO;
+ break;
+ default:
+ UA_WARN("Unsupported sensor [%d]", sensor_type);
+ bitmask = 0x00;
+ }
+
+ FUNC_EXIT;
+ return bitmask;
+}
+
+static ua_sensor_e __ua_sensor_bitmask_to_type(unsigned int bitmask)
+{
+ FUNC_ENTRY;
+
+ switch (bitmask) {
+ case UAM_SENSOR_BITMASK_BT:
+ return UA_SENSOR_BT;
+ case UAM_SENSOR_BITMASK_BLE:
+ return UA_SENSOR_BLE;
+ case UAM_SENSOR_BITMASK_WIFI:
+ return UA_SENSOR_WIFI;
+ case UAM_SENSOR_BITMASK_MOTION:
+ return UA_SENSOR_MOTION;
+ case UAM_SENSOR_BITMASK_BRIGHTNESS:
+ return UA_SENSOR_BRIGHTNESS;
+ case UAM_SENSOR_BITMASK_AUDIO:
+ return UA_SENSOR_AUDIO;
+ default:
+ UA_WARN("Unknown sensor bitmask [0x%8.8X]", bitmask);
+ return UA_SENSOR_MAX;
+ }
+}
+
+int ua_sensor_is_available(
+ ua_sensor_e sensor,
+ bool *available
+ )
+{
+ FUNC_ENTRY;
+ unsigned int available_sensors = 0;
+ int ret;
+ unsigned int bitmask;
+
+ UA_VALIDATE_INPUT_PARAMETER(available);
+ UA_INITIALIZE();
+
+ 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) {
+ UA_ERR("_uam_get_available_sensors failed");
+ return ret;
+ }
+
+ if (0 == (available_sensors & bitmask))
+ *available = false;
+ else
+ *available = true;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
int ua_create_monitor(ua_monitor_h *handle)
{
FUNC_ENTRY;
+ ua_monitor_t *monitor = NULL;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+
+ monitor = g_malloc0(sizeof(ua_monitor_t));
+ if (!monitor) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ /* Add monitor to list of monitors */
+ ua_monitor_list = g_slist_append(ua_monitor_list, monitor);
+
+ *handle = (ua_monitor_h)monitor;
+
FUNC_EXIT;
return UA_ERROR_NONE;
}
+static void __ua_free_ua_monitor_t(ua_monitor_t *monitor)
+{
+ FUNC_ENTRY;
+
+ ret_if(NULL == monitor);
+
+ if (monitor->presence_detection_timer) {
+ g_source_remove(monitor->presence_detection_timer);
+ monitor->presence_detection_timer = 0;
+ }
+
+ if (monitor->absence_detection_timer) {
+ g_source_remove(monitor->absence_detection_timer);
+ monitor->absence_detection_timer = 0;
+ }
+
+ g_free(monitor);
+
+ FUNC_EXIT;
+}
+
int ua_destroy_monitor(ua_monitor_h handle)
{
FUNC_ENTRY;
+ ua_monitor_t *monitor = (ua_monitor_t *)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);
FUNC_EXIT;
return UA_ERROR_NONE;
+
}
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_t *monitor = (ua_monitor_t *)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;
@@ -75,16 +216,44 @@ int ua_monitor_set_sensor_state_cb(ua_monitor_h handle,
int ua_monitor_unset_sensor_state_cb(ua_monitor_h handle)
{
FUNC_ENTRY;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->sensor_state_cb.callback = NULL;
+ monitor->sensor_state_cb.user_data = NULL;
FUNC_EXIT;
return UA_ERROR_NONE;
}
int ua_monitor_add_sensor(
- ua_monitor_h monitor,
- ua_sensor_e sensor)
+ ua_monitor_h handle,
+ ua_sensor_e sensor_type)
{
FUNC_ENTRY;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+ unsigned int bitmask;
+ unsigned int available_sensors = 0;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ UA_INITIALIZE();
+
+ retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOT_PERMITTED);
+ retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOT_PERMITTED);
+
+ bitmask = __ua_sensor_type_to_bitmask(sensor_type);
+ retv_if(0 != (monitor->sensor_bitmask & bitmask), UA_ERROR_ALREADY_DONE);
+
+ if (UA_ERROR_NONE != _ua_get_error_code(
+ _uam_get_available_sensors(&available_sensors)))
+ UA_WARN("_uam_get_available_sensors failed");
+
+ retv_if(0 == (available_sensors & bitmask), UA_ERROR_NOT_READY);
+
+ monitor->sensor_bitmask |= bitmask;
FUNC_EXIT;
return UA_ERROR_NONE;
@@ -95,17 +264,140 @@ int ua_monitor_remove_sensor(
ua_sensor_e sensor_type)
{
FUNC_ENTRY;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+ unsigned int bitmask;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOT_PERMITTED);
+ retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOT_PERMITTED);
+
+ bitmask = __ua_sensor_type_to_bitmask(sensor_type);
+ retv_if(0 == (monitor->sensor_bitmask & bitmask), UA_ERROR_ALREADY_DONE);
+
+ monitor->sensor_bitmask &= ~bitmask;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-int ua_monitor_set_absence_period(
- ua_monitor_h handle,
- ua_sensor_e sensor_type,
- unsigned short absence_period)
+static int __ua_start_monitoring(unsigned int bitmask, ua_detection_type_e detect)
{
FUNC_ENTRY;
+ int ret;
+ int indx;
+ unsigned int sensors = bitmask;
+
+ for (indx = 0; indx < UA_SENSOR_MAX; indx++) {
+ switch (indx) {
+ case UA_SENSOR_BT:
+ if (!(bitmask & UAM_SENSOR_BITMASK_BT))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_BT]: %d",
+ ref_count[UA_SENSOR_BT]);
+ if (0 < ref_count[UA_SENSOR_BT])
+ sensors &= ~UAM_SENSOR_BITMASK_BT;
+ break;
+ case UA_SENSOR_BLE:
+ if (!(bitmask & UAM_SENSOR_BITMASK_BLE))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_BLE]: %d",
+ ref_count[UA_SENSOR_BLE]);
+ if (0 < ref_count[UA_SENSOR_BLE])
+ sensors &= ~UAM_SENSOR_BITMASK_BLE;
+ break;
+ case UA_SENSOR_WIFI:
+ if (!(bitmask & UAM_SENSOR_BITMASK_WIFI))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_WIFI]: %d",
+ ref_count[UA_SENSOR_WIFI]);
+ if (0 < ref_count[UA_SENSOR_WIFI])
+ sensors &= ~UAM_SENSOR_BITMASK_WIFI;
+ break;
+ case UA_SENSOR_MOTION:
+ if (!(bitmask & UAM_SENSOR_BITMASK_MOTION))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_MOTION]: %d",
+ ref_count[UA_SENSOR_MOTION]);
+ if (0 < ref_count[UA_SENSOR_MOTION])
+ sensors &= ~UAM_SENSOR_BITMASK_MOTION;
+ break;
+ case UA_SENSOR_BRIGHTNESS:
+ if (!(bitmask & UAM_SENSOR_BITMASK_BRIGHTNESS))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_BRIGHTNESS]: %d",
+ ref_count[UA_SENSOR_BRIGHTNESS]);
+ if (0 < ref_count[UA_SENSOR_BRIGHTNESS])
+ sensors &= ~UAM_SENSOR_BITMASK_BRIGHTNESS;
+ break;
+ case UA_SENSOR_AUDIO:
+ if (!(bitmask & UAM_SENSOR_BITMASK_AUDIO))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_AUDIO]: %d",
+ ref_count[UA_SENSOR_AUDIO]);
+ if (0 < ref_count[UA_SENSOR_AUDIO])
+ sensors &= ~UAM_SENSOR_BITMASK_AUDIO;
+ break;
+ default:
+ UA_WARN("Unsupported sensor [%d]", indx);
+ }
+ }
+
+ if (detect == UA_PRESENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_start_presence_detection(sensors));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("_ua_start_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+ } else if (detect == UA_ABSENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_start_absence_detection(sensors));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("_ua_start_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+ } else
+ UA_ERR("invalid detection type");
+
+ /* Start detection success, increase ref count */
+ for (indx = 0; indx < UA_SENSOR_MAX; indx++) {
+ switch (indx) {
+ case UA_SENSOR_BT:
+ if (bitmask & UAM_SENSOR_BITMASK_BT)
+ REF(ref_count[UA_SENSOR_BT]);
+ break;
+ case UA_SENSOR_BLE:
+ if (bitmask & UAM_SENSOR_BITMASK_BLE)
+ REF(ref_count[UA_SENSOR_BLE]);
+ break;
+ case UA_SENSOR_WIFI:
+ if (bitmask & UAM_SENSOR_BITMASK_WIFI)
+ REF(ref_count[UA_SENSOR_WIFI]);
+ break;
+ case UA_SENSOR_MOTION:
+ if (bitmask & UAM_SENSOR_BITMASK_MOTION)
+ REF(ref_count[UA_SENSOR_MOTION]);
+ break;
+ case UA_SENSOR_BRIGHTNESS:
+ if (bitmask & UAM_SENSOR_BITMASK_BRIGHTNESS)
+ REF(ref_count[UA_SENSOR_BRIGHTNESS]);
+ break;
+ case UA_SENSOR_AUDIO:
+ if (bitmask & UAM_SENSOR_BITMASK_AUDIO)
+ REF(ref_count[UA_SENSOR_AUDIO]);
+ break;
+ default:
+ UA_WARN("Unsupported sensor [%d]", indx);
+ }
+ }
FUNC_EXIT;
return UA_ERROR_NONE;
@@ -118,20 +410,36 @@ int ua_monitor_start_presence_detection(
void *user_data)
{
FUNC_ENTRY;
+ int ret;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+ ua_detection_type_e detect = UA_PRESENCE_DETECTION;
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(TRUE == monitor->presence_detection_started, UA_ERROR_NOW_IN_PROGRESS);
+ retv_if(UA_DETECT_MODE_INVALID == mode, UA_ERROR_INVALID_PARAMETER);
+ retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_SENSOR_DATA);
-int ua_monitor_stop_presence_detection(ua_monitor_h handle)
-{
- FUNC_ENTRY;
+ UA_INITIALIZE();
+ /* 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, detect);
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
+ monitor->presence_mode = mode;
+ monitor->presence_cb = callback;
+ monitor->user_data = user_data;
+ monitor->presence_detection_started = TRUE;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-#ifndef VD_REQ
int ua_monitor_start_absence_detection(
ua_monitor_h handle,
ua_detection_mode_e mode,
@@ -139,26 +447,181 @@ int ua_monitor_start_absence_detection(
void *user_data)
{
FUNC_ENTRY;
+ int ret;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+ ua_detection_type_e detect = UA_ABSENCE_DETECTION;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(TRUE == monitor->absence_detection_started, UA_ERROR_NOW_IN_PROGRESS);
+ retv_if(UA_DETECT_MODE_INVALID == mode, UA_ERROR_INVALID_PARAMETER);
+ retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_SENSOR_DATA);
+
+ UA_INITIALIZE();
+ /* 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, detect);
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
+ monitor->absence_mode = mode;
+ monitor->absence_cb = callback;
+ monitor->user_data = user_data;
+ monitor->absence_detection_started = TRUE;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-int ua_monitor_stop_absence_detection(ua_monitor_h handle)
+static int __ua_stop_monitoring(unsigned int bitmask, ua_detection_type_e detect)
{
FUNC_ENTRY;
+ int ret;
+ int indx;
+ unsigned int sensors = bitmask;
+
+ for (indx = 1; indx < UA_SENSOR_MAX; indx++) {
+ switch (indx) {
+ case UA_SENSOR_BT:
+ if (!(bitmask & UAM_SENSOR_BITMASK_BT))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_BT]: %d",
+ ref_count[UA_SENSOR_BT]);
+ if (0 < ref_count[UA_SENSOR_BT])
+ sensors &= ~UAM_SENSOR_BITMASK_BT;
+ break;
+ case UA_SENSOR_BLE:
+ if (!(bitmask & UAM_SENSOR_BITMASK_BLE))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_BLE]: %d",
+ ref_count[UA_SENSOR_BLE]);
+ if (0 < ref_count[UA_SENSOR_BLE])
+ sensors &= ~UAM_SENSOR_BITMASK_BLE;
+ break;
+ case UA_SENSOR_WIFI:
+ if (!(bitmask & UAM_SENSOR_BITMASK_WIFI))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_WIFI]: %d",
+ ref_count[UA_SENSOR_WIFI]);
+ if (0 < ref_count[UA_SENSOR_WIFI])
+ sensors &= ~UAM_SENSOR_BITMASK_WIFI;
+ break;
+ case UA_SENSOR_MOTION:
+ if (!(bitmask & UAM_SENSOR_BITMASK_MOTION))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_MOTION]: %d",
+ ref_count[UA_SENSOR_MOTION]);
+ if (0 < ref_count[UA_SENSOR_MOTION])
+ sensors &= ~UAM_SENSOR_BITMASK_MOTION;
+ break;
+ case UA_SENSOR_BRIGHTNESS:
+ if (!(bitmask & UAM_SENSOR_BITMASK_BRIGHTNESS))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_BRIGHTNESS]: %d",
+ ref_count[UA_SENSOR_BRIGHTNESS]);
+ if (0 < ref_count[UA_SENSOR_BRIGHTNESS])
+ sensors &= ~UAM_SENSOR_BITMASK_BRIGHTNESS;
+ break;
+ case UA_SENSOR_AUDIO:
+ if (!(bitmask & UAM_SENSOR_BITMASK_AUDIO))
+ break;
+
+ UA_DBG("ref_count[UA_SENSOR_AUDIO]: %d",
+ ref_count[UA_SENSOR_AUDIO]);
+ if (0 < ref_count[UA_SENSOR_AUDIO])
+ sensors &= ~UAM_SENSOR_BITMASK_AUDIO;
+ break;
+ default:
+ UA_WARN("Unsupported sensor [%d]", indx);
+ }
+ }
+
+ if (detect == UA_PRESENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_stop_presence_detection(bitmask));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("_ua_stop_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+ } else if (detect == UA_ABSENCE_DETECTION) {
+ ret = _ua_get_error_code(_uam_stop_absence_detection(bitmask));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("_ua_stop_presence_detection failed with %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+ } else
+ UA_ERR("invalid detection type");
+
+ /* Stop detection success, decrease ref count */
+ for (indx = 0; indx < UA_SENSOR_MAX; indx++) {
+ switch (indx) {
+ case UA_SENSOR_BT:
+ if (bitmask & UAM_SENSOR_BITMASK_BT)
+ UNREF(ref_count[UA_SENSOR_BT]);
+ break;
+ case UA_SENSOR_BLE:
+ if (bitmask & UAM_SENSOR_BITMASK_BLE)
+ UNREF(ref_count[UA_SENSOR_BLE]);
+ break;
+ case UA_SENSOR_WIFI:
+ if (bitmask & UAM_SENSOR_BITMASK_WIFI)
+ UNREF(ref_count[UA_SENSOR_WIFI]);
+ break;
+ case UA_SENSOR_MOTION:
+ if (bitmask & UAM_SENSOR_BITMASK_MOTION)
+ UNREF(ref_count[UA_SENSOR_MOTION]);
+ break;
+ case UA_SENSOR_BRIGHTNESS:
+ if (bitmask & UAM_SENSOR_BITMASK_BRIGHTNESS)
+ UNREF(ref_count[UA_SENSOR_BRIGHTNESS]);
+ break;
+ case UA_SENSOR_AUDIO:
+ if (bitmask & UAM_SENSOR_BITMASK_AUDIO)
+ UNREF(ref_count[UA_SENSOR_AUDIO]);
+ break;
+ default:
+ UA_WARN("Unsupported sensor [%d]", indx);
+ }
+ }
FUNC_EXIT;
return UA_ERROR_NONE;
}
-#else
-int ua_monitor_start_absence_detection(
- ua_monitor_h handle,
- ua_detection_mode_e mode,
- ua_absence_detected_cb callback,
- void *user_data)
+
+int ua_monitor_stop_presence_detection(ua_monitor_h handle)
{
FUNC_ENTRY;
+ int ret;
+ ua_monitor_t *monitor = (ua_monitor_t *)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);
+ retv_if(NULL == monitor->presence_cb, UA_ERROR_NOT_IN_PROGRESS);
+ UA_INITIALIZE();
+
+ ret = __ua_stop_monitoring(monitor->sensor_bitmask, detect);
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
+ monitor->presence_mode = UA_DETECT_MODE_INVALID;
+ monitor->presence_cb = NULL;
+ monitor->user_data = NULL;
+ monitor->presence_detection_started = FALSE;
FUNC_EXIT;
return UA_ERROR_NONE;
@@ -167,15 +630,354 @@ int ua_monitor_start_absence_detection(
int ua_monitor_stop_absence_detection(ua_monitor_h handle)
{
FUNC_ENTRY;
+ int ret;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+ ua_detection_type_e detect = UA_ABSENCE_DETECTION;
+
+ 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_INITIALIZE();
+
+ ret = __ua_stop_monitoring(monitor->sensor_bitmask, detect);
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
+ monitor->absence_mode = UA_DETECT_MODE_INVALID;
+ monitor->absence_cb = NULL;
+ monitor->user_data = NULL;
+ monitor->absence_detection_started = FALSE;
FUNC_EXIT;
return UA_ERROR_NONE;
}
-#endif
+
+static gboolean __ua_reset_presence_detected_history(gpointer data)
+{
+ FUNC_ENTRY;
+ ua_monitor_t *monitor = data;
+
+ if (0 < monitor->presence_detected_bitmask)
+ monitor->presence_detected_bitmask = 0;
+
+ FUNC_EXIT;
+ return FALSE;
+}
+
+static void __ua_sensor_send_presence_detected(ua_monitor_t *monitor, unsigned int bitmask, ua_user_info_t *user_info)
+{
+ FUNC_ENTRY;
+ ua_sensor_e sensor_type;
+ sensor_type = __ua_sensor_bitmask_to_type(bitmask);
+ ret_if(NULL == monitor);
+
+ switch (monitor->presence_mode) {
+ case UA_DETECT_MODE_ALL_SENSOR:
+ monitor->presence_detected_bitmask |= bitmask;
+
+ if (user_info && user_info->account)
+ _ua_mark_user_info_state_db(user_info->account, UA_PRESENCE_STATE_ACTIVATE);
+
+ if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) {
+ UA_DBG("Presence detected by all sensors, invoke callback");
+ if (user_info) {
+ if (_ua_add_user_info_to_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail to add in local db");
+
+ /*
+ * 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.
+ */
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, user_info->user_handle, monitor->user_data);
+
+ if (_ua_remove_user_info_from_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail to remove from local db");
+ } else
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, NULL, monitor->user_data);
+
+ monitor->presence_detected_bitmask = 0;
+ /* Remove presence timer if timer is running */
+ if (0 < monitor->presence_detection_timer) {
+ g_source_remove(monitor->presence_detection_timer);
+ monitor->presence_detection_timer = 0;
+ }
+ } else {
+ /*
+ * Do not invoke presence detected callback until user is detected by all the sensors.
+ * Wait for at most UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME for all sensor to report
+ * user presence detected event. If all sensors do not detect the users by said time, then
+ * user presence detected by few sensors will be ignored and detection history is cleared.
+ */
+ monitor->presence_detection_timer = g_timeout_add_seconds(
+ UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME,
+ __ua_reset_presence_detected_history, monitor);
+ }
+ break;
+
+ case UA_DETECT_MODE_ANY_SENSOR:
+ /* First add user info to local users list and then invoke callback */
+ if (user_info) {
+ if (_ua_add_user_info_to_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail _ua_add_user_info_to_local_db");
+
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, user_info->user_handle, monitor->user_data);
+
+ if (user_info->account)
+ _ua_mark_user_info_state_db(user_info->account, UA_PRESENCE_STATE_ACTIVATE);
+
+ if (_ua_remove_user_info_from_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail to remove from local db");
+ } else
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, NULL, monitor->user_data);
+
+ break;
+
+ default:
+ UA_WARN("Unexpected detection mode: %d", monitor->presence_mode);
+ }
+
+ FUNC_EXIT;
+}
+
+static gboolean __ua_reset_absence_detected_history(gpointer data)
+{
+ FUNC_ENTRY;
+ ua_monitor_t *monitor = data;
+
+ if (0 < monitor->absence_detected_bitmask)
+ monitor->absence_detected_bitmask = 0;
+
+ FUNC_EXIT;
+ return FALSE;
+}
+
+static void __ua_sensor_send_absence_detected(ua_monitor_t *monitor, unsigned int bitmask, ua_user_info_t *user_info)
+{
+ FUNC_ENTRY;
+ ua_sensor_e sensor_type;
+ bool all_absence;
+ sensor_type = __ua_sensor_bitmask_to_type(bitmask);
+ ret_if(NULL == monitor);
+
+ switch (monitor->absence_mode) {
+ case UA_DETECT_MODE_ALL_SENSOR:
+ monitor->absence_detected_bitmask |= bitmask;
+
+ if (user_info && user_info->account)
+ _ua_mark_user_info_state_db(user_info->account, UA_PRESENCE_STATE_INACTIVATE);
+
+ if (monitor->sensor_bitmask == monitor->absence_detected_bitmask) {
+ UA_DBG("Absence detected by all sensors one user [%s]", user_info->account);
+ if (user_info) {
+ all_absence = _ua_check_all_users_absence();
+
+ /*
+ * Sends absence if it is detected by all sensors irrespective of device/user i.e if
+ * absence will be detected 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 (all_absence) {
+ if (_ua_add_user_info_to_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail _ua_add_user_info_to_local_db");
+
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, user_info->user_handle, monitor->user_data);
+
+ if (_ua_remove_user_info_from_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail to remove from local db");
+ }
+ } else
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, NULL, monitor->user_data);
+
+ monitor->absence_detected_bitmask = 0;
+ /* Remove absence timer if timer is running */
+ if (0 < monitor->absence_detection_timer) {
+ g_source_remove(monitor->absence_detection_timer);
+ monitor->absence_detection_timer = 0;
+ }
+ } else {
+ /*
+ * Do not invoke presence detected callback until user is detected by all the sensors.
+ * Wait for at most UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME for all sensor to report
+ * user presence detected event. If all sensors do not detect the users by said time, then
+ * user presence detected by few sensors will be ignored and detection history is cleared.
+ */
+ monitor->absence_detection_timer = g_timeout_add_seconds(
+ UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME,
+ __ua_reset_absence_detected_history, monitor);
+ }
+ break;
+
+ case UA_DETECT_MODE_ANY_SENSOR:
+ /* First add user info to local users list and then invoke callback */
+ if (user_info) {
+ if (user_info->account)
+ _ua_mark_user_info_state_db(user_info->account, UA_PRESENCE_STATE_INACTIVATE);
+
+ all_absence = _ua_check_all_users_absence();
+
+ if (all_absence) {
+ if (_ua_add_user_info_to_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail _ua_add_user_info_to_local_db");
+
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, user_info->user_handle, monitor->user_data);
+
+ if (_ua_remove_user_info_from_local_db(user_info) != UA_ERROR_NONE)
+ UA_DBG("Fail to remove from local db");
+ }
+ } else
+ monitor->absence_cb(UA_ERROR_NONE, monitor,
+ sensor_type, NULL, monitor->user_data);
+
+ break;
+
+ default:
+ UA_WARN("Unexpected detection mode: %d", monitor->absence_mode);
+ }
+
+ FUNC_EXIT;
+}
void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, ua_user_info_t *user_info)
{
FUNC_ENTRY;
+ GSList *l;
+
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_t *monitor = l->data;
+
+ if (!monitor || !monitor->presence_detection_started)
+ continue;
+
+ if (0 == (bitmask & monitor->sensor_bitmask))
+ continue;
+
+ if (monitor->presence_cb) {
+ /* Presence detection ongoing */
+ __ua_sensor_send_presence_detected(monitor, bitmask, user_info);
+ } else {
+ UA_WARN("Unexpected, detection started but callbacks are NULL");
+ }
+ }
+
+ FUNC_EXIT;
+}
+
+void _ua_monitor_handle_user_absence_detected(unsigned int bitmask, ua_user_info_t *user_info)
+{
+ FUNC_ENTRY;
+ GSList *l;
+
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_t *monitor = l->data;
+
+ if (!monitor || !monitor->absence_detection_started)
+ continue;
+
+ if (0 == (bitmask & monitor->sensor_bitmask))
+ continue;
+
+ if (monitor->absence_cb) {
+ /* Absence detection ongoing */
+ __ua_sensor_send_absence_detected(monitor, bitmask, user_info);
+ } else {
+ UA_WARN("Unexpected, detection started but callbacks are NULL");
+ }
+ }
+
+ FUNC_EXIT;
+}
+
+static void __ua_remove_sensor(ua_monitor_t *monitor, ua_sensor_e sensor_type)
+{
+ 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->presence_cb;
+ absence_user_data = monitor->user_data;
+ mode_absence = monitor->absence_mode;
+
+ ret = ua_monitor_stop_presence_detection(monitor);
+ UA_INFO("ua_monitor_stop_presence_detection returned %s",
+ _ua_get_error_string(ret));
+
+ is_absence = 1;
+ } else {
+ UA_WARN("Unexpected, detection started but cbs are NULL");
+ }
+ }
+
+ 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, 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, 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;
}
@@ -183,13 +985,43 @@ void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, ua_user_inf
void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready)
{
FUNC_ENTRY;
+ ua_sensor_e sensor_type;
+ GSList *l;
+ sensor_type = __ua_sensor_bitmask_to_type(bitmask);
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_t *monitor = l->data;
+
+ if (!monitor)
+ continue;
+
+ if (!ready && (bitmask & monitor->sensor_bitmask))
+ __ua_remove_sensor(monitor, sensor_type);
+
+ 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;
}
-int ua_sensor_is_ready(ua_sensor_e sensor, bool *is_ready)
+int ua_monitor_set_brightness_threshold(ua_monitor_h handle, int presence_threshold, int absence_threshold)
{
FUNC_ENTRY;
+ int ret;
+ ua_monitor_t *monitor = (ua_monitor_t *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_SENSOR_DATA);
+ UA_INITIALIZE();
+
+ ret = _ua_get_error_code(_uam_request_set_detection_threshold(monitor->sensor_bitmask, presence_threshold, absence_threshold));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Set failed");
+ return ret;
+ }
FUNC_EXIT;
return UA_ERROR_NONE;
diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c
index 2e45115..c6f6669 100644
--- a/src/user-awareness-users.c
+++ b/src/user-awareness-users.c
@@ -32,10 +32,493 @@ static GSList *ua_devices_list;
static GSList *ua_users_db_list;
static GSList *ua_devices_db_list;
-ua_user_h _ua_user_add_to_list(ua_user_info_t *user)
+void _ua_free_ua_device_info_t(ua_dev_info_t *device)
{
FUNC_ENTRY;
+ ret_if(NULL == device);
+
+ if (device->mac)
+ g_free(device->mac);
+
+ if (device->bssid)
+ g_free(device->bssid);
+
+ if (device->ipv4)
+ g_free(device->ipv4);
+
+ if (device->ipv6)
+ g_free(device->ipv6);
+
+ if (device->mobile_id)
+ g_free(device->mobile_id);
+
+ g_free(device);
+
+ FUNC_EXIT;
+}
+
+void _ua_free_ua_user_info_t(ua_user_info_t *user)
+{
+ FUNC_ENTRY;
+
+ ret_if(NULL == user);
+
+ if (user->account)
+ g_free(user->account);
+
+ if (user->name)
+ g_free(user->name);
+
+ g_free(user);
+
+ FUNC_EXIT;
+}
+
+int _ua_add_user_info_to_local_db(ua_user_info_t* user_info)
+{
+ FUNC_ENTRY;
+ UA_VALIDATE_INPUT_PARAMETER(user_info);
+ ua_users_db_list = g_slist_append(ua_users_db_list, user_info);
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+int _ua_mark_user_info_state_db(char* account, int state)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_user_info_t *u;
+ UA_VALIDATE_INPUT_PARAMETER(account);
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ u = (ua_user_info_t *)l->data;
+
+ if (!g_strcmp0(account, u->account)) {
+ UA_INFO("User found [%s]", u->account);
+ u->state = state;
+ break;
+ }
+ }
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+bool _ua_check_all_users_absence()
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_user_info_t *u;
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ u = (ua_user_info_t *)l->data;
+
+ if (u->state == UA_PRESENCE_STATE_ACTIVATE) {
+ UA_INFO("User found [%s]", u->account);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+int _ua_remove_user_info_from_local_db(ua_user_info_t* user_info)
+{
+ FUNC_ENTRY;
+ UA_VALIDATE_INPUT_PARAMETER(user_info);
+ ua_users_db_list = g_slist_remove(ua_users_db_list, user_info);
+ _ua_free_ua_user_info_t(user_info);
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+int _ua_is_user_exist(char* account, gboolean* is_exist)
+{
+ GSList *l;
+ UA_VALIDATE_INPUT_PARAMETER(account);
+ ua_user_info_t *user_info;
+ *is_exist = false;
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ user_info = (ua_user_info_t *)l->data;
+
+ if (!g_strcmp0(account, user_info->account)) {
+ UA_INFO("User found [%s]", user_info->account);
+ *is_exist = true;
+ }
+ }
+
+ return UA_ERROR_NONE;
+}
+
+int _ua_is_device_exist(char* mobile_id, char* mac, ua_mac_type_e type, gboolean* is_exist)
+{
+ GSList *l;
+ UA_VALIDATE_INPUT_PARAMETER(is_exist);
+ ua_dev_info_t *dev;
+ *is_exist = false;
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_t *)l->data;
+
+ if ((int)type == (int)dev->type) {
+ if (mobile_id && !g_strcmp0(mobile_id, dev->mobile_id)) {
+ UA_INFO("Device found, mobile id[%s]", dev->mobile_id);
+ *is_exist = true;
+ }
+
+ if (mac && !g_strcmp0(mac, dev->mac)) {
+ UA_INFO("Device found, mac address[%s]", dev->mac);
+ *is_exist = true;
+ }
+ }
+ }
+
+ return UA_ERROR_NONE;
+}
+
+int _ua_add_user_info_to_list_from_uapi_data(uam_user_info_t* uam_info)
+{
+ FUNC_ENTRY;
+ ua_user_info_t* user_info;
+ gboolean status = false;
+ UA_VALIDATE_INPUT_PARAMETER(uam_info);
+ int ret;
+
+ ret = _ua_is_user_exist(uam_info->account, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
+
+ user_info = g_malloc0(sizeof(ua_user_info_t));
+
+ if (!user_info) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ user_info->account = strndup(uam_info->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+
+ if (user_info->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ user_info->name = strndup(uam_info->name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ if (user_info->name == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+
+ /* Set user state by default INACTIVATE as this field will be use
+ * during absence detection where by default all users and in INACTIVATE state
+ * user will go in ACTIVATE state after presence is detected for thst user.
+ */
+ user_info->state = UA_PRESENCE_STATE_INACTIVATE;
+ ua_users_list = g_slist_append(ua_users_list, user_info);
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+int _ua_add_user_info_to_list(ua_user_info_t* ua_info)
+{
+ FUNC_ENTRY;
+ ua_user_info_t* user_info;
+ gboolean status = false;
+ UA_VALIDATE_INPUT_PARAMETER(ua_info);
+ int ret;
+
+ ret = _ua_is_user_exist(ua_info->account, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
+
+ user_info = g_malloc0(sizeof(ua_user_info_t));
+
+ if (!user_info) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ user_info->account = strndup(ua_info->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+
+ if (user_info->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ user_info->name = strndup(ua_info->name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ if (user_info->name == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+
+ /* Set user state by default INACTIVATE as this field will be use
+ * during absence detection where by default all users and in INACTIVATE state
+ * user will go in ACTIVATE state after presence is detected for thst user.
+ */
+ user_info->state = UA_PRESENCE_STATE_INACTIVATE;
+ ua_users_list = g_slist_append(ua_users_list, user_info);
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+int _ua_remove_user_info_from_list(char* account)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ GSList *m;
+ ua_user_info_t *u;
+ ua_dev_info_t *dev;
+ UA_VALIDATE_INPUT_PARAMETER(account);
+
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ u = (ua_user_info_t *)l->data;
+
+ if (!g_strcmp0(account, u->account)) {
+ if (u->create_by_app == false) {
+ UA_INFO("User found [%s]", u->account);
+
+ for (m = ua_devices_list; m; m = g_slist_next(l)) {
+ dev = (ua_dev_info_t *)m->data;
+ if (u == dev->user) {
+ dev->user = NULL;
+ break;
+ }
+ }
+
+ ua_users_list = g_slist_remove(ua_users_list, u);
+ _ua_free_ua_user_info_t(u);
+ break;
+ } else {
+ UA_INFO("User created by APP");
+ u->isadded = false;
+ }
+ }
+ }
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+int _ua_add_device_info_to_list(uam_device_info_t* uam_info)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_dev_info_t* dev;
+ UA_VALIDATE_INPUT_PARAMETER(uam_info);
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_t *)l->data;
+
+ if ((int)uam_info->type == (int)dev->type) {
+ if (!g_strcmp0(uam_info->device_id, dev->mobile_id)) {
+ UA_INFO("Device found, mobile id[%s]", dev->mobile_id);
+ return UA_ERROR_ALREADY_DONE;
+ }
+
+ if (!g_strcmp0(uam_info->mac, dev->mac)) {
+ UA_INFO("Device found, mac address[%s]", dev->mac);
+ return UA_ERROR_ALREADY_DONE;
+ }
+ }
+ }
+
+ dev = g_malloc0(sizeof(ua_dev_info_t));
+ if (!dev) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ dev->user = NULL;
+ dev->bssid = NULL;
+ dev->ipv6 = NULL;
+
+ dev->mac = strndup(uam_info->mac, UA_MAC_ADDRESS_STRING_SIZE);
+ if (dev->mac == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t(dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->ipv4 = strndup(uam_info->ipv4_addr, UA_IPV4_ADDRESS_STRING_SIZE);
+ if (dev->ipv4 == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t(dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ dev->mobile_id = strndup(uam_info->device_id, UA_MOBILE_ID_STRING_SIZE);
+ if (dev->mobile_id == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_device_info_t(dev);
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+ dev->type = uam_info->type;;
+ dev->pairing_required = FALSE;
+ dev->os = uam_info->operating_system;
+ 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);
+
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+int _ua_remove_device_info_from_list(uam_device_info_t* uam_info)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_dev_info_t *u;
+ UA_VALIDATE_INPUT_PARAMETER(uam_info);
+
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ u = (ua_dev_info_t *)l->data;
+
+ if ((int)uam_info->type == (int)u->type) {
+ if (!g_strcmp0(uam_info->device_id, u->mobile_id)) {
+ if (u->create_by_app == false) {
+ UA_INFO("Device found, mobile id[%s]", u->mobile_id);
+ ua_devices_list = g_slist_remove(ua_devices_list, u);
+ _ua_free_ua_device_info_t(u);
+ break;
+ } else {
+ UA_INFO("Device created by APP");
+ u->isadded = false;
+ }
+ }
+
+ if (!g_strcmp0(uam_info->mac, u->mac)) {
+ if (u->create_by_app == false) {
+ UA_INFO("Device found, mac address[%s]", u->mac);
+ ua_devices_list = g_slist_remove(ua_devices_list, u);
+ _ua_free_ua_device_info_t(u);
+ break;
+ } else {
+ UA_INFO("Device created by APP");
+ u->isadded = false;
+ }
+ }
+ }
+ }
+ return UA_ERROR_NONE;
+ FUNC_EXIT;
+}
+
+ua_user_h _ua_make_user_handle_from_uapi_data(uam_user_info_t *ptr)
+{
+ ua_user_info_t *user_info;
+ user_info = g_malloc0(sizeof(ua_user_info_t));
+
+ if (!user_info) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return NULL;
+ }
+
+ user_info->account = strndup(ptr->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+
+ if (user_info->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return NULL;
+ }
+
+ user_info->name = strndup(ptr->name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ if (user_info->name == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return NULL;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+ user_info->state = ptr->presence_state;
+ ua_users_db_list = g_slist_append(ua_users_db_list, user_info);
+
+ return (user_info->user_handle);
+}
+
+ua_user_h _ua_make_user_handle_from_local_data(ua_user_info_t *ptr)
+{
+ ua_user_info_t *user_info;
+ user_info = g_malloc0(sizeof(ua_user_info_t));
+
+ if (!user_info) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return NULL;
+ }
+
+ user_info->account = strndup(ptr->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+
+ if (user_info->account == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return NULL;
+ }
+
+ user_info->name = strndup(ptr->name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ if (user_info->name == NULL) {
+ UA_ERR("g_malloc0 failed");
+ _ua_free_ua_user_info_t(user_info);
+ return NULL;
+ }
+
+ user_info->isadded = true;
+ user_info->user_handle = (ua_user_h)user_info;
+ user_info->state = ptr->state;
+ ua_users_db_list = g_slist_append(ua_users_db_list, user_info);
+
+ return (user_info->user_handle);
+}
+
+ua_user_h _ua_get_user_handle_by_account(char* account)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_user_info_t *u;
+
+ if (account == NULL) {
+ UA_INFO("Account is NULL");
+ return NULL;
+ }
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ u = (ua_user_info_t *)l->data;
+
+ if (!g_strcmp0(account, u->account)) {
+ UA_INFO("User found [%s]", u->account);
+ return (u->user_handle);
+ }
+ }
+
FUNC_EXIT;
return NULL;
}
@@ -46,9 +529,18 @@ int ua_create_user(const char* account, ua_user_h *user_handle)
int ret;
ua_user_info_t *user = NULL;
uam_user_info_t uam_user;
+ gboolean status = false;
UA_VALIDATE_INPUT_PARAMETER(user_handle);
UA_VALIDATE_INPUT_PARAMETER(account);
+ UA_INITIALIZE();
+
+ ret = _ua_is_user_exist((char *)account, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
user = g_malloc0(sizeof(ua_user_info_t));
if (!user) {
@@ -66,7 +558,10 @@ int ua_create_user(const char* account, ua_user_h *user_handle)
g_strlcpy(user->account, account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
- UA_INITIALIZE();
+ /* TODO : We can remove this call(_uam_request_get_user_by_account) as all users
+ * list are updated in foreach during init and during add_user and remove_user
+ * events from us daemon
+ */
ret = _ua_get_error_code(_uam_request_get_user_by_account(user->account, &uam_user));
@@ -84,6 +579,7 @@ int ua_create_user(const char* account, ua_user_h *user_handle)
/* Add monitor to list of monitors */
*user_handle = (ua_user_h)user;
user->user_handle = (ua_user_h)user;
+ user->create_by_app = true;
ua_users_list = g_slist_append(ua_users_list, user);
FUNC_EXIT;
@@ -99,11 +595,10 @@ int ua_add_user(ua_user_h user_handle)
UA_VALIDATE_INPUT_PARAMETER(user_handle);
UA_VALIDATE_HANDLE(user_handle, ua_users_list);
+ UA_INITIALIZE();
retv_if(NULL == user->account, UA_ERROR_INVALID_PARAMETER);
- UA_INITIALIZE();
-
memset(&uam_user, 0, sizeof(uam_user_info_t));
g_strlcpy(uam_user.account, user->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
@@ -118,7 +613,6 @@ int ua_add_user(ua_user_h user_handle)
}
user->isadded = true;
-
FUNC_EXIT;
return UA_ERROR_NONE;
}
@@ -158,9 +652,20 @@ int ua_get_default_user(ua_user_h* user_handle)
int ret;
uam_user_info_t uam_user;
ua_user_info_t *user = NULL;
+ GSList *l;
UA_VALIDATE_INPUT_PARAMETER(user_handle);
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ user = (ua_user_info_t *)l->data;
+
+ if (user->default_user == true) {
+ UA_INFO("User found [%s]", user->account);
+ *user_handle = (ua_user_h)user;
+ return UA_ERROR_NONE;
+ }
+ }
+
UA_INITIALIZE();
ret = _ua_get_error_code(_uam_get_default_user(&uam_user));
@@ -186,6 +691,9 @@ int ua_get_default_user(ua_user_h* user_handle)
user->user_handle = (ua_user_h)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;
return UA_ERROR_NONE;
}
@@ -200,6 +708,7 @@ int ua_user_get_account(
UA_VALIDATE_INPUT_PARAMETER(user_handle);
UA_VALIDATE_HANDLE(user_handle, ua_users_list);
UA_VALIDATE_INPUT_PARAMETER(account);
+ UA_INITIALIZE();
*account = strndup(user->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
@@ -222,6 +731,7 @@ int ua_user_get_name(
UA_VALIDATE_INPUT_PARAMETER(user_handle);
UA_VALIDATE_HANDLE(user_handle, ua_users_list);
UA_VALIDATE_INPUT_PARAMETER(name);
+ UA_INITIALIZE();
retv_if(NULL == user->name, UA_ERROR_INVALID_PARAMETER);
@@ -246,6 +756,7 @@ int ua_user_set_name(
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_INPUT_PARAMETER(name);
UA_VALIDATE_HANDLE(handle, ua_users_list);
+ UA_INITIALIZE();
retv_if(user->isadded, UA_ERROR_INVALID_PARAMETER);
retv_if((strlen(name) > UAM_USER_NAME_MAX_STRING_SIZE), UA_ERROR_INVALID_PARAMETER);
@@ -263,61 +774,29 @@ int ua_user_set_name(
return UA_ERROR_NONE;
}
-static void __ua_free_ua_device_info_t(ua_dev_info_t *device)
-{
- FUNC_ENTRY;
-
- ret_if(NULL == device);
-
- if (device->mac)
- g_free(device->mac);
-
- if (device->bssid)
- g_free(device->bssid);
-
- if (device->ipv4)
- g_free(device->ipv4);
-
- if (device->ipv6)
- g_free(device->ipv6);
-
- if (device->mobile_id)
- g_free(device->mobile_id);
-
- g_free(device);
-
- FUNC_EXIT;
-}
-
-static void __ua_free_ua_user_info_t(ua_user_info_t *user)
-{
- FUNC_ENTRY;
-
- ret_if(NULL == user);
-
- if (user->account)
- g_free(user->account);
-
- if (user->name)
- g_free(user->name);
-
- g_free(user);
-
- FUNC_EXIT;
-}
-
int ua_destroy_user(ua_user_h user_handle)
{
FUNC_ENTRY;
ua_user_info_t *user = (ua_user_info_t *)user_handle;
+ ua_dev_info_t* dev;
+ GSList *l;
UA_VALIDATE_INPUT_PARAMETER(user_handle);
UA_VALIDATE_HANDLE(user_handle, ua_users_list);
+ UA_INITIALIZE();
+
+ for (l = ua_devices_list; l; l = g_slist_next(l)) {
+ dev = (ua_dev_info_t *)l->data;
+
+ if (dev->user == user_handle) {
+ UA_INFO("User found in device handle");
+ dev->user = NULL;
+ }
+ }
ua_users_list = g_slist_remove(ua_users_list, user);
- __ua_free_ua_user_info_t(user);
+ _ua_free_ua_user_info_t(user);
- //TODO mark NULL as user handle in device handle
FUNC_EXIT;
return UA_ERROR_NONE;
}
@@ -329,6 +808,7 @@ int ua_create_device(ua_mac_type_e mac_type, ua_device_h *device_handle)
retv_if(mac_type, UA_MAC_TYPE_INVALID);
UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_INITIALIZE();
device = g_malloc0(sizeof(ua_dev_info_t));
if (!device) {
@@ -351,6 +831,7 @@ int ua_create_device(ua_mac_type_e mac_type, ua_device_h *device_handle)
/* 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;
@@ -364,9 +845,10 @@ int ua_destroy_device(ua_device_h device_handle)
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
+ UA_INITIALIZE();
ua_devices_list = g_slist_remove(ua_devices_list, device);
- __ua_free_ua_device_info_t(device);
+ _ua_free_ua_device_info_t(device);
FUNC_EXIT;
return UA_ERROR_NONE;
@@ -377,13 +859,28 @@ int ua_device_set_mac_address(
const char* mac_address)
{
FUNC_ENTRY;
+ int ret;
+ gboolean status = false;
ua_dev_info_t *device = (ua_dev_info_t *)handle;
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_INPUT_PARAMETER(mac_address);
UA_VALIDATE_HANDLE(handle, ua_devices_list);
+ UA_INITIALIZE();
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_SIZE -1)), UA_ERROR_INVALID_PARAMETER);
device->mac = g_malloc0(UA_MAC_ADDRESS_STRING_SIZE);
@@ -408,6 +905,7 @@ int ua_device_set_os_info(
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_HANDLE(handle, ua_devices_list);
+ UA_INITIALIZE();
retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
@@ -428,12 +926,26 @@ int ua_device_set_wifi_mobile_id(
{
FUNC_ENTRY;
ua_dev_info_t *device = (ua_dev_info_t *)handle;
+ int ret;
+ gboolean status = false;
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_INPUT_PARAMETER(mobile_id);
UA_VALIDATE_HANDLE(handle, ua_devices_list);
+ UA_INITIALIZE();
retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
+ /* This code will check if app try to add mobile 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 mobile id is suppose to same for one device.
+ */
+ ret = _ua_is_device_exist((char*)mobile_id, NULL, device->type, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
+
retv_if((strlen(mobile_id) != (UA_MOBILE_ID_STRING_SIZE -1)), UA_ERROR_INVALID_PARAMETER);
device->mobile_id = g_malloc0(UA_MOBILE_ID_STRING_SIZE);
@@ -459,6 +971,7 @@ int ua_device_set_wifi_bssid(
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_INPUT_PARAMETER(bssid);
UA_VALIDATE_HANDLE(handle, ua_devices_list);
+ UA_INITIALIZE();
retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
retv_if((strlen(bssid) != (UA_MAC_ADDRESS_STRING_SIZE -1)), UA_ERROR_INVALID_PARAMETER);
@@ -486,6 +999,7 @@ int ua_device_set_wifi_ipv4_address(
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_INPUT_PARAMETER(ipv4_address);
UA_VALIDATE_HANDLE(handle, ua_devices_list);
+ UA_INITIALIZE();
retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER);
retv_if((strlen(ipv4_address) != (UA_IPV4_ADDRESS_STRING_SIZE -1)), UA_ERROR_INVALID_PARAMETER);
@@ -503,16 +1017,6 @@ int ua_device_set_wifi_ipv4_address(
return UA_ERROR_NONE;
}
-int ua_user_get_dev_info(
- ua_user_h handle,
- ua_dev_info_t *dev_info)
-{
- FUNC_ENTRY;
-
- FUNC_EXIT;
- return UA_ERROR_NONE;
-}
-
int ua_device_get_mac_address(
ua_device_h device_handle,
char** mac_address)
@@ -523,6 +1027,7 @@ int ua_device_get_mac_address(
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
UA_VALIDATE_INPUT_PARAMETER(mac_address);
+ UA_INITIALIZE();
if (!device->mac) {
*mac_address = NULL;
@@ -541,6 +1046,24 @@ done:
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_t *device = (ua_dev_info_t *)device_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(device_handle);
+ UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
+ UA_VALIDATE_INPUT_PARAMETER(os_info);
+ UA_INITIALIZE();
+
+ *os_info = device->os;
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
int ua_device_get_wifi_mobile_id(
ua_device_h device_handle,
char** mobile_id)
@@ -551,6 +1074,7 @@ int ua_device_get_wifi_mobile_id(
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
UA_VALIDATE_INPUT_PARAMETER(mobile_id);
+ UA_INITIALIZE();
if (!device->mobile_id) {
*mobile_id = NULL;
@@ -579,6 +1103,7 @@ int ua_device_get_wifi_bssid(
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
UA_VALIDATE_INPUT_PARAMETER(bssid);
+ UA_INITIALIZE();
if (!device->bssid) {
*bssid = NULL;
@@ -607,6 +1132,7 @@ int ua_device_get_wifi_ipv4_address(
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
UA_VALIDATE_INPUT_PARAMETER(ipv4_address);
+ UA_INITIALIZE();
if (!device->ipv4) {
*ipv4_address = NULL;
@@ -672,7 +1198,7 @@ int ua_device_get_handle_by_mac_address(
if (dev->mac == NULL) {
UA_ERR("g_malloc0 failed");
*device_handle = NULL;
- __ua_free_ua_device_info_t(dev);
+ _ua_free_ua_device_info_t(dev);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -681,7 +1207,7 @@ int ua_device_get_handle_by_mac_address(
if (dev->ipv4 == NULL) {
UA_ERR("g_malloc0 failed");
*device_handle = NULL;
- __ua_free_ua_device_info_t(dev);
+ _ua_free_ua_device_info_t(dev);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -690,7 +1216,7 @@ int ua_device_get_handle_by_mac_address(
if (dev->mobile_id == NULL) {
UA_ERR("g_malloc0 failed");
*device_handle = NULL;
- __ua_free_ua_device_info_t(dev);
+ _ua_free_ua_device_info_t(dev);
return UA_ERROR_OUT_OF_MEMORY;
}
dev->type = uam_dev.type;;
@@ -727,7 +1253,7 @@ int ua_device_get_handle_by_mobile_id(
for (l = ua_devices_list; l; l = g_slist_next(l)) {
dev = (ua_dev_info_t *)l->data;
- if (!g_strcmp0(mobile_id, dev->mobile_id)) {
+ if ((mac_type == dev->type) && !g_strcmp0(mobile_id, dev->mobile_id)) {
UA_INFO("Mobile ID found [%s]", dev->mobile_id);
*device_handle = (ua_device_h)dev;
goto done;
@@ -760,7 +1286,7 @@ int ua_device_get_handle_by_mobile_id(
if (dev->mac == NULL) {
UA_ERR("g_malloc0 failed");
*device_handle = NULL;
- __ua_free_ua_device_info_t(dev);
+ _ua_free_ua_device_info_t(dev);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -769,7 +1295,7 @@ int ua_device_get_handle_by_mobile_id(
if (dev->ipv4 == NULL) {
UA_ERR("g_malloc0 failed");
*device_handle = NULL;
- __ua_free_ua_device_info_t(dev);
+ _ua_free_ua_device_info_t(dev);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -778,7 +1304,7 @@ int ua_device_get_handle_by_mobile_id(
if (dev->mobile_id == NULL) {
UA_ERR("g_malloc0 failed");
*device_handle = NULL;
- __ua_free_ua_device_info_t(dev);
+ _ua_free_ua_device_info_t(dev);
return UA_ERROR_OUT_OF_MEMORY;
}
dev->type = uam_dev.type;;
@@ -801,11 +1327,32 @@ int ua_foreach_registered_users(
void *user_data)
{
FUNC_ENTRY;
+ GSList *l;
+ ua_user_info_t *u;
+
+ UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
+ UA_INITIALIZE();
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ u = (ua_user_info_t *)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_t *ptr;
- GSList *l;
UA_VALIDATE_INPUT_PARAMETER(foreach_cb);
UA_INITIALIZE();
@@ -830,7 +1377,7 @@ int ua_foreach_registered_users(
if (!user_info) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_user_info_t(user_info);
+ _ua_free_ua_user_info_t(user_info);
goto done;
}
@@ -839,7 +1386,7 @@ int ua_foreach_registered_users(
if (user_info->account == NULL) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_user_info_t(user_info);
+ _ua_free_ua_user_info_t(user_info);
goto done;
}
@@ -848,14 +1395,18 @@ int ua_foreach_registered_users(
if (user_info->name == NULL) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_user_info_t(user_info);
+ _ua_free_ua_user_info_t(user_info);
goto done;
}
user_info->isadded = true;
user_info->user_handle = (ua_user_h)user_info;
user_info->state = ptr->presence_state;
- ua_users_db_list = g_slist_append(ua_users_db_list, 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 {
UA_ERR("OPERATION_FAILED(0x%08x)",
UA_ERROR_OPERATION_FAILED);
@@ -864,27 +1415,7 @@ int ua_foreach_registered_users(
}
}
- for (l = ua_users_db_list; l; l = g_slist_next(l)) {
- ua_user_info_t *u = l->data;
-
- if (NULL == u)
- continue;
-
- if (!foreach_cb(u->user_handle, user_data))
- break;
- }
-
done:
- for (l = ua_users_db_list; l; l = g_slist_next(l)) {
- ua_user_info_t *u = l->data;
-
- if (NULL == u)
- continue;
-
- ua_users_list = g_slist_remove(ua_users_db_list, u);
- __ua_free_ua_user_info_t(u);
- }
-
g_ptr_array_foreach(user_list, (GFunc)g_free, NULL);
g_ptr_array_free(user_list, TRUE);
@@ -902,6 +1433,8 @@ int ua_user_clone(ua_user_h *cloned,
UA_VALIDATE_INPUT_PARAMETER(cloned);
UA_VALIDATE_INPUT_PARAMETER(origin);
UA_VALIDATE_HANDLE(origin, ua_users_db_list);
+ UA_EXIST_HANDLE(origin, ua_users_list);
+ UA_INITIALIZE();
user = g_malloc0(sizeof(ua_user_info_t));
@@ -915,7 +1448,7 @@ int ua_user_clone(ua_user_h *cloned,
if (user->account == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_user_info_t(user);
+ _ua_free_ua_user_info_t(user);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -923,7 +1456,7 @@ int ua_user_clone(ua_user_h *cloned,
if (user->name == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_user_info_t(user);
+ _ua_free_ua_user_info_t(user);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -932,6 +1465,7 @@ int ua_user_clone(ua_user_h *cloned,
/* Add user to list of users */
*cloned = (ua_user_h)user;
user->user_handle = (ua_user_h)user;
+ user->create_by_app = true;
ua_users_list = g_slist_append(ua_users_list, user);
FUNC_EXIT;
@@ -943,6 +1477,7 @@ int ua_device_clone(ua_device_h *cloned,
{
FUNC_ENTRY;
int ret;
+ gboolean status = false;
ua_dev_info_t *device = NULL;
uam_user_info_t uam_user;
ua_dev_info_t *org_device = (ua_dev_info_t *)origin;
@@ -950,6 +1485,16 @@ int ua_device_clone(ua_device_h *cloned,
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);
+
+ ret = _ua_is_device_exist(org_device->mobile_id, org_device->mac, org_device->type, &status);
+ if (ret == UA_ERROR_NONE) {
+ if (status)
+ return UA_ERROR_ALREADY_DONE;
+ } else
+ return ret;
+
+ UA_INITIALIZE();
device = g_malloc0(sizeof(ua_dev_info_t));
if (!device) {
@@ -960,21 +1505,21 @@ int ua_device_clone(ua_device_h *cloned,
device->mac = strndup(org_device->mac, UA_MAC_ADDRESS_STRING_SIZE);
if (device->mac == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device);
+ _ua_free_ua_device_info_t(device);
return UA_ERROR_OUT_OF_MEMORY;
}
device->ipv4 = strndup(org_device->ipv4, UA_IPV4_ADDRESS_STRING_SIZE);
if (device->ipv4 == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device);
+ _ua_free_ua_device_info_t(device);
return UA_ERROR_OUT_OF_MEMORY;
}
device->mobile_id = strndup(org_device->mobile_id, UA_MOBILE_ID_STRING_SIZE);
if (device->mobile_id == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device);
+ _ua_free_ua_device_info_t(device);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -984,32 +1529,33 @@ int ua_device_clone(ua_device_h *cloned,
if (!device->user) {
UA_INITIALIZE();
+ /* Currently user info will be create and store at this point */
ret = _ua_get_error_code(_uam_request_get_user_by_deviceid(device->mobile_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(device);
+ _ua_free_ua_device_info_t(device);
return ret;
} else {
ua_user_info_t* user = g_malloc0(sizeof(ua_user_info_t));
if (!user) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device);
+ _ua_free_ua_device_info_t(device);
return UA_ERROR_OUT_OF_MEMORY;
} else {
user->account = strndup(uam_user.account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
if (user->account == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device);
- __ua_free_ua_user_info_t(user);
+ _ua_free_ua_device_info_t(device);
+ _ua_free_ua_user_info_t(user);
return UA_ERROR_OUT_OF_MEMORY;
}
user->name = strndup(uam_user.name, UAM_USER_NAME_MAX_STRING_SIZE);
if (user->name == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device);
- __ua_free_ua_user_info_t(user);
+ _ua_free_ua_device_info_t(device);
+ _ua_free_ua_user_info_t(user);
return UA_ERROR_OUT_OF_MEMORY;
}
@@ -1026,6 +1572,7 @@ int ua_device_clone(ua_device_h *cloned,
/* Add user to list of users */
*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;
@@ -1037,15 +1584,16 @@ int ua_user_add_device(ua_user_h user_handle, ua_device_h device_handle)
FUNC_ENTRY;
int ret;
ua_user_h handle = NULL;
+ ua_user_h temp_handle = NULL;
ua_dev_info_t *device = (ua_dev_info_t *) device_handle;
- uam_user_info_t uam_user;
ua_user_info_t* user = NULL;
uam_device_info_t uam_device;
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
- retv_if(device->mobile_id, UA_ERROR_INVALID_PARAMETER);
+ retv_if((((device->mobile_id == NULL) && (device->mac == NULL)) || (UA_MAC_TYPE_INVALID == device->type)), UA_ERROR_INVALID_PARAMETER);
+ temp_handle = device->user;
if (user_handle == NULL) {
ret = ua_get_default_user(&handle);
if (ret != UA_ERROR_NONE) {
@@ -1061,11 +1609,6 @@ int ua_user_add_device(ua_user_h user_handle, ua_device_h device_handle)
user = (ua_user_info_t *)device->user;
memset(&uam_device, 0, sizeof(uam_device_info_t));
- memset(&uam_user, 0, sizeof(uam_user_info_t));
- g_strlcpy(uam_user.account, user->account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
-
- if (user->name)
- g_strlcpy(uam_user.name, user->name, UAM_USER_NAME_MAX_STRING_SIZE);
uam_device.operating_system = device->os;
uam_device.type = device->type;
@@ -1080,11 +1623,12 @@ int ua_user_add_device(ua_user_h user_handle, ua_device_h device_handle)
UA_INITIALIZE();
- ret = _ua_get_error_code(_uam_request_add_device(&uam_user, &uam_device));
+ ret = _ua_get_error_code(_uam_request_add_device(user->account, &uam_device));
if (UA_ERROR_NONE != ret) {
UA_ERR("Failed with error: %s(0x%X)",
_ua_get_error_string(ret), ret);
+ device->user = temp_handle;
return ret;
}
@@ -1104,7 +1648,7 @@ int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle)
UA_VALIDATE_INPUT_PARAMETER(device_handle);
UA_VALIDATE_HANDLE(device_handle, ua_devices_list);
- retv_if(device->mobile_id, UA_ERROR_INVALID_PARAMETER);
+ retv_if((((device->mobile_id == NULL) && (device->mac == NULL)) || (UA_MAC_TYPE_INVALID == device->type)), UA_ERROR_INVALID_PARAMETER);
if (user_handle == NULL) {
ret = ua_get_default_user(&handle);
@@ -1157,6 +1701,7 @@ int ua_remove_device_by_address(const char* mac)
int found = 0;
UA_VALIDATE_INPUT_PARAMETER(mac);
+ UA_INITIALIZE();
for (l = ua_devices_list; l; l = g_slist_next(l)) {
device = (ua_dev_info_t *)l->data;
@@ -1169,8 +1714,6 @@ int ua_remove_device_by_address(const char* mac)
}
if (found) {
- UA_INITIALIZE();
-
ret = _ua_get_error_code(_uam_request_remove_device_by_mac(mac));
if (UA_ERROR_NONE != ret) {
@@ -1196,6 +1739,7 @@ int ua_remove_device_by_mobile_id(const char* mobile_id, ua_mac_type_e mac_type)
int found = 0;
UA_VALIDATE_INPUT_PARAMETER(mobile_id);
+ UA_INITIALIZE();
retv_if(mac_type, UA_MAC_TYPE_INVALID);
for (l = ua_devices_list; l; l = g_slist_next(l)) {
@@ -1209,8 +1753,6 @@ int ua_remove_device_by_mobile_id(const char* mobile_id, ua_mac_type_e mac_type)
}
if (found) {
- UA_INITIALIZE();
-
ret = _ua_get_error_code(_uam_request_remove_device_by_deviceid(mobile_id, mac_type));
if (UA_ERROR_NONE != ret) {
@@ -1266,7 +1808,7 @@ int ua_foreach_all_registered_dev_info(
device_info->mac = strndup(ptr->mac, UA_MAC_ADDRESS_STRING_SIZE);
if (device_info->mac == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device_info);
+ _ua_free_ua_device_info_t(device_info);
ret = UA_ERROR_OUT_OF_MEMORY;
goto done;
}
@@ -1274,7 +1816,7 @@ int ua_foreach_all_registered_dev_info(
device_info->ipv4 = strndup(ptr->ipv4_addr, UA_IPV4_ADDRESS_STRING_SIZE);
if (device_info->ipv4 == NULL) {
UA_ERR("g_malloc0 failed");
- __ua_free_ua_device_info_t(device_info);
+ _ua_free_ua_device_info_t(device_info);
ret = UA_ERROR_OUT_OF_MEMORY;
goto done;
}
@@ -1283,7 +1825,7 @@ int ua_foreach_all_registered_dev_info(
if (device_info->mobile_id == NULL) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_device_info_t(device_info);
+ _ua_free_ua_device_info_t(device_info);
goto done;
}
@@ -1317,8 +1859,8 @@ done:
if (NULL == u)
continue;
- ua_devices_list = g_slist_remove(ua_devices_db_list, u);
- __ua_free_ua_device_info_t(u);
+ ua_devices_db_list = g_slist_remove(ua_devices_db_list, u);
+ _ua_free_ua_device_info_t(u);
}
g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL);
@@ -1372,7 +1914,7 @@ int ua_foreach_registered_dev_info_by_user(
if (device_info->mac == NULL) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_device_info_t(device_info);
+ _ua_free_ua_device_info_t(device_info);
goto done;
}
@@ -1380,7 +1922,7 @@ int ua_foreach_registered_dev_info_by_user(
if (device_info->ipv4 == NULL) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_device_info_t(device_info);
+ _ua_free_ua_device_info_t(device_info);
goto done;
}
@@ -1388,7 +1930,7 @@ int ua_foreach_registered_dev_info_by_user(
if (device_info->mobile_id == NULL) {
UA_ERR("g_malloc0 failed");
ret = UA_ERROR_OUT_OF_MEMORY;
- __ua_free_ua_device_info_t(device_info);
+ _ua_free_ua_device_info_t(device_info);
goto done;
}
@@ -1423,8 +1965,8 @@ done:
if (NULL == u)
continue;
- ua_devices_list = g_slist_remove(ua_devices_db_list, u);
- __ua_free_ua_device_info_t(u);
+ ua_devices_db_list = g_slist_remove(ua_devices_db_list, u);
+ _ua_free_ua_device_info_t(u);
}
g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL);
@@ -1434,12 +1976,104 @@ done:
return ret;
}
-int ua_user_get_is_pairing_required(
- ua_user_h handle,
+int ua_device_get_pairing_required(
+ ua_device_h handle,
bool *pairing_required)
{
FUNC_ENTRY;
+ int ret;
+ ua_dev_info_t *device = (ua_dev_info_t *)handle;
+ gboolean is_registered = FALSE;
+ uam_device_info_t uam_device;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_devices_list);
+ UA_VALIDATE_INPUT_PARAMETER(pairing_required);
+ retv_if((((device->mobile_id == NULL) && (device->mac == NULL)) || (UA_MAC_TYPE_INVALID == device->type)), UA_ERROR_INVALID_PARAMETER);
+
+ memset(&uam_device, 0, sizeof(uam_device_info_t));
+
+ uam_device.operating_system = device->os;
+ uam_device.type = device->type;
+
+ if (device->mac)
+ g_strlcpy(uam_device.mac, device->mac, UAM_MAC_ADDRESS_STRING_SIZE);
+
+ if (device->mobile_id)
+ g_strlcpy(uam_device.device_id, device->mobile_id, UA_MOBILE_ID_STRING_SIZE);
+
+ if (device->ipv4)
+ g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_SIZE);
+
+ UA_INITIALIZE();
+
+ ret = _ua_get_error_code(_uam_is_device_registered(&uam_device, &is_registered));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ 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()
+{
+ FUNC_ENTRY;
+ int ret;
+ uam_user_info_t uam_user;
+ ua_user_info_t *user = NULL;
+ GSList *l;
+
+ ret = _ua_get_error_code(_uam_get_default_user(&uam_user));
+ if (UA_ERROR_NONE != ret) {
+ UA_ERR("Failed with error: %s(0x%X)",
+ _ua_get_error_string(ret), ret);
+ return ret;
+ }
+
+ for (l = ua_users_list; l; l = g_slist_next(l)) {
+ user = (ua_user_info_t *)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;
+ }
+ }
+
+ user = g_malloc0(sizeof(ua_user_info_t));
+
+ if (!user) {
+ UA_ERR("g_malloc0 failed");
+ return UA_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_strlcpy(user->account, uam_user.account, UAM_USER_ACCOUNT_MAX_STRING_SIZE);
+ g_strlcpy(user->name, uam_user.name, UAM_USER_NAME_MAX_STRING_SIZE);
+
+ user->state = uam_user.presence_state;
+ 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;
return UA_ERROR_NONE;
}
diff --git a/test/user-awareness-test.c b/test/user-awareness-test.c
index 878c18d..0efbba8 100644
--- a/test/user-awareness-test.c
+++ b/test/user-awareness-test.c
@@ -36,8 +36,9 @@
#define TC_PRT(format, args...) PRT(format"\n", ##args)
GMainLoop *main_loop = NULL;
-ua_monitor_h monitor;
-ua_user_h user;
+ua_monitor_h monitor = NULL;
+ua_user_h user = NULL;
+ua_device_h device = NULL;
static int test_id = -1;
static gboolean need_to_set_params = FALSE;
static ua_tc_params_t test_param;
@@ -50,12 +51,14 @@ ua_tc_table_t tc_main[] = {
, UA_TEST_FUNCTION_DESTROY_MONITOR},
{"Set sensor state changed callback"
, UA_TEST_FUNCTION_SET_SENSOR_STATE_CB},
+ {"Unset sensor state changed callback"
+ , UA_TEST_FUNCTION_UNSET_SENSOR_STATE_CB},
{"Add sensor"
, UA_TEST_FUNCTION_ADD_SENSOR},
{"Remove sensor"
, UA_TEST_FUNCTION_REMOVE_SENSOR},
- {"Set sensor absence period"
- , UA_TEST_FUNCTION_SET_ABSENCE_PERIOD},
+ {"Set brightness sensor threshold"
+ , UA_TEST_FUNCTION_SET_BRIGHTNESS_THRESHOLD},
{"Start user presence detection"
, UA_TEST_FUNCTION_START_PRESENCE_DETECTION},
{"Stop user presence detection"
@@ -64,29 +67,65 @@ ua_tc_table_t tc_main[] = {
, UA_TEST_FUNCTION_START_ABSENCE_DETECTION},
{"Stop user absence detection"
, UA_TEST_FUNCTION_STOP_ABSENCE_DETECTION},
- {"Start Headless Monitoring"
- , UA_TEST_FUNCTION_START_HEADLESS_MONITORING},
- {"Stop Headless Monitoring"
- , UA_TEST_FUNCTION_STOP_HEADLESS_MONITORING},
+ {"Is sensor available"
+ , UA_TEST_FUNCTION_IS_SENSOR_AVAILABLE},
{"Creater User handle"
, UA_TEST_FUNCTION_CREATE_USER},
{"Destroy User handle"
, UA_TEST_FUNCTION_DESTROY_USER},
- {"Set OS info for user"
+ {"Add User"
+ , UA_TEST_FUNCTION_ADD_USER},
+ {"Remove User"
+ , UA_TEST_FUNCTION_REMOVE_USER},
+ {"Get default user"
+ , UA_TEST_FUNCTION_GET_DEFAULT_USER},
+ {"Creater Device handle"
+ , UA_TEST_FUNCTION_CREATE_DEVICE},
+ {"Destroy Device handle"
+ , UA_TEST_FUNCTION_DESTROY_DEVICE},
+ {"User get account"
+ , UA_TEST_FUNCTION_GET_USER_ACCOUNT},
+ {"User set name"
+ , UA_TEST_FUNCTION_SET_USER_NAME},
+ {"User get name"
+ , UA_TEST_FUNCTION_GET_USER_NAME},
+ {"User set os info"
, UA_TEST_FUNCTION_SET_OS_INFO},
- {"Set MAC info for user"
- , UA_TEST_FUNCTION_SET_MAC_INFO},
- {"Get device info"
- , UA_TEST_FUNCTION_GET_DEVICE_INFO},
+ {"User get os info"
+ , UA_TEST_FUNCTION_GET_OS_INFO},
+ {"User set mac address"
+ , UA_TEST_FUNCTION_SET_MAC_ADDRESS},
+ {"User get mac address"
+ , UA_TEST_FUNCTION_GET_MAC_ADDRESS},
+ {"User set mobile id"
+ , UA_TEST_FUNCTION_SET_MOBILE_ID},
+ {"User get mobile id"
+ , UA_TEST_FUNCTION_GET_MOBILE_ID},
+ {"User set ipv4 address"
+ , UA_TEST_FUNCTION_SET_IPV4_ADDRESS},
+ {"User get ipv4 address"
+ , UA_TEST_FUNCTION_GET_IPV4_ADDRESS},
+ {"User get device handle by mac address"
+ , UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MAC_ADDRESS},
+ {"User get device handle by mobile id"
+ , UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MOBILE_ID},
+ {"User user add device"
+ , UA_TEST_FUNCTION_USER_ADD_DEVICE},
+ {"User user remove device"
+ , UA_TEST_FUNCTION_USER_REMOVE_DEVICE},
+ {"User remove device by mac address"
+ , UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MAC_ADDRESS},
+ {"User remove device by mobile id"
+ , UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MOBILE_ID},
{"Foreach registered devices"
, UA_TEST_FUNCTION_GET_REGISTERED_DEVICES},
+ {"Foreach registered devices by user"
+ , UA_TEST_FUNCTION_GET_REGISTERED_DEVICES_BY_USERS},
+ {"Foreach registered users"
+ , UA_TEST_FUNCTION_GET_REGISTERED_USERS},
{"Get is pairing required"
, UA_TEST_FUNCTION_IS_PAIRING_REQUIRED},
- {"Enable Ambient mode"
- , UA_TEST_FUNCTION_ENABLE_AMBIENT_MODE},
- {"Disable Ambient mode"
- , UA_TEST_FUNCTION_DISABLE_AMBIENT_MODE},
{"Set function parameters"
, UA_TEST_FUNCTION_SET_PARAMETERS},
@@ -169,60 +208,89 @@ static void __sensor_state_changed_cb(bool ready,
}
static void __presence_detected_cb(int result, ua_monitor_h monitor,
- ua_sensor_e sensor, ua_user_h user_handle, void *user_data)
+ ua_sensor_e sensor, ua_user_h user_handle, void *user_data)
{
TC_PRT("result : %s", __ua_get_error_string(result));
TC_PRT("sensor: 0x%2.2X", sensor);
if (user_handle) {
int ret;
- ua_dev_info_t dev_info;
+ char* account = NULL;
- ret = ua_user_get_dev_info(user_handle, &dev_info);
- TC_PRT("ua_user_get_dev_info returned : %s", __ua_get_error_string(ret));
+ ret = ua_user_get_account(user_handle, &account);
+ TC_PRT("ua_user_get_account returned : %s", __ua_get_error_string(ret));
if (UA_ERROR_NONE == ret) {
- TC_PRT("Device Operating System: 0x%2.2X", dev_info.os);
- TC_PRT("Device MAC type: 0x%2.2X", dev_info.type);
- TC_PRT("Device MAC Address: %s", dev_info.mac);
+ TC_PRT("User account info %s", account);
+ free(account);
}
- ret = ua_destroy_user(user_handle);
- TC_PRT("ua_destroy_user returned : %s", __ua_get_error_string(ret));
}
}
static void __absence_detected_cb(int result, ua_monitor_h monitor,
- ua_sensor_e sensor, void *user_data)
+ ua_sensor_e sensor, ua_user_h user_handle, void *user_data)
{
TC_PRT("result : %s", __ua_get_error_string(result));
TC_PRT("sensor: 0x%2.2X", sensor);
+ if (user_handle) {
+ int ret;
+ char* account = NULL;
+
+ ret = ua_user_get_account(user_handle, &account);
+ TC_PRT("ua_user_get_account returned : %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("User account info %s", account);
+ free(account);
+ }
+ }
}
static bool __foreach_registered_dev_cb(
- ua_dev_info_t *dev_info, void *user_data)
+ ua_device_h device_handle, void *user_data)
{
- TC_PRT("Device Operating System: 0x%2.2X", dev_info->os);
- TC_PRT("Device MAC type: 0x%2.2X", dev_info->type);
- TC_PRT("Device MAC Address: %s", dev_info->mac);
+ int ret, ret_temp;
+ if (device_handle) {
+ ua_device_h handle = NULL;
+
+ ret = ua_device_clone(&handle, device_handle);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ char* mac = NULL;
+ char* mobile_id = NULL;
+ ret_temp = ua_device_get_mac_address(handle, &mac);
+ if (UA_ERROR_NONE == ret_temp) {
+ TC_PRT("Device MAC Address : %s", mac);
+ free(mac);
+ }
+
+ ret_temp = ua_device_get_wifi_mobile_id(handle, &mobile_id);
+ if (UA_ERROR_NONE == ret_temp) {
+ TC_PRT("Device Mobile ID : %s", mobile_id);
+ free(mobile_id);
+ }
+
+ /* TODO : Whether to destroy this device handle */
+ }
+ }
return true;
}
-static void __ambient_mode_cb(int result,
- bool enable, ua_user_h user_handle, void *user_data)
+static bool __foreach_registered_user_cb(
+ ua_user_h user_handle, void *user_data)
{
- TC_PRT("Result: %s", __ua_get_error_string(result));
- TC_PRT("Ambient mode %s", (enable ? "enabled" : "disabled"));
+ /* TODO: No need to clone user handle */
if (user_handle) {
int ret;
- ua_dev_info_t dev_info;
+ char* account = NULL;
- ret = ua_user_get_dev_info(user_handle, &dev_info);
- TC_PRT("ua_user_get_dev_info returned : %s", __ua_get_error_string(ret));
+ ret = ua_user_get_account(user_handle, &account);
+ TC_PRT("ua_user_get_account returned : %s", __ua_get_error_string(ret));
if (UA_ERROR_NONE == ret) {
- TC_PRT("Device Operating System: 0x%2.2X", dev_info.os);
- TC_PRT("Device MAC type: 0x%2.2X", dev_info.type);
- TC_PRT("Device MAC Address: %s", dev_info.mac);
+ TC_PRT("User account info %s", account);
+ free(account);
}
}
+
+ return true;
}
int test_input_callback(void *data)
@@ -250,18 +318,21 @@ int test_input_callback(void *data)
TC_PRT("returns %s", __ua_get_error_string(ret));
break;
}
+ case UA_TEST_FUNCTION_UNSET_SENSOR_STATE_CB: {
+ ret = ua_monitor_unset_sensor_state_cb(monitor);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ break;
+ }
case UA_TEST_FUNCTION_ADD_SENSOR: {
int sensor_type;
- unsigned int absence_period;
- if (test_param.param_count < 2) {
+ if (test_param.param_count < 1) {
TC_PRT("Input parameters first");
break;
}
sensor_type = atoi(test_param.params[0]);
- absence_period = atoi(test_param.params[1]);
- ret = ua_monitor_add_sensor(monitor, sensor_type, absence_period);
+ ret = ua_monitor_add_sensor(monitor, sensor_type);
TC_PRT("returns %s", __ua_get_error_string(ret));
__ua_free_test_param(&test_param);
break;
@@ -280,9 +351,9 @@ int test_input_callback(void *data)
__ua_free_test_param(&test_param);
break;
}
- case UA_TEST_FUNCTION_SET_ABSENCE_PERIOD: {
- int sensor_type;
- unsigned int absence_period;
+ case UA_TEST_FUNCTION_SET_BRIGHTNESS_THRESHOLD: {
+ unsigned int presence_threshold;
+ unsigned int absence_threshold;
if (!monitor) {
TC_PRT("Create monitor first");
@@ -294,9 +365,9 @@ int test_input_callback(void *data)
break;
}
- sensor_type = atoi(test_param.params[0]);
- absence_period = atoi(test_param.params[1]);
- ret = ua_monitor_set_absence_period(monitor, sensor_type, absence_period);
+ presence_threshold = atoi(test_param.params[0]);
+ absence_threshold = atoi(test_param.params[1]);
+ ret = ua_monitor_set_brightness_threshold(monitor, presence_threshold, absence_threshold);
TC_PRT("returns %s", __ua_get_error_string(ret));
__ua_free_test_param(&test_param);
break;
@@ -337,27 +408,44 @@ int test_input_callback(void *data)
break;
}
case UA_TEST_FUNCTION_STOP_ABSENCE_DETECTION: {
- ret = ua_monitor_stop_absence_detection(monitor);
- TC_PRT("returns %s", __ua_get_error_string(ret));
- break;
- }
- case UA_TEST_FUNCTION_START_HEADLESS_MONITORING: {
- ret = ua_start_headless_monitoring(monitor);
+ int ret = ua_monitor_stop_absence_detection(monitor);
TC_PRT("returns %s", __ua_get_error_string(ret));
break;
}
- case UA_TEST_FUNCTION_STOP_HEADLESS_MONITORING: {
- ret = ua_stop_headless_monitoring(monitor);
+ case UA_TEST_FUNCTION_IS_SENSOR_AVAILABLE: {
+ int sensor_type;
+ bool is_available;
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ sensor_type = atoi(test_param.params[0]);
+ ret = ua_sensor_is_available(sensor_type, &is_available);
TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ if (is_available)
+ TC_PRT("sensor is available");
+ else
+ TC_PRT("sensor is not available");
+ }
+
+ __ua_free_test_param(&test_param);
break;
}
case UA_TEST_FUNCTION_CREATE_USER: {
+ char account[UA_USER_ACCOUNT_MAX_STRING_SIZE];
if (user)
ua_destroy_user(user);
- ret = ua_create_user(&user);
+ g_strlcpy(account, test_param.params[0],
+ UA_USER_ACCOUNT_MAX_STRING_SIZE);
+ ret = ua_create_user(account, &user);
TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ __ua_free_test_param(&test_param);
break;
}
case UA_TEST_FUNCTION_DESTROY_USER: {
@@ -366,22 +454,231 @@ int test_input_callback(void *data)
TC_PRT("returns %s", __ua_get_error_string(ret));
break;
}
+ case UA_TEST_FUNCTION_ADD_USER: {
+ ret = ua_add_user(user);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ break;
+ }
+ case UA_TEST_FUNCTION_REMOVE_USER: {
+ ret = ua_remove_user(user);
+ user = NULL;
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_DEFAULT_USER: {
+ ua_user_h default_user = NULL;
+ ret = ua_get_default_user(default_user);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ if (UA_ERROR_NONE == ret) {
+ char* account = NULL;
+ int ret_temp;
+ ret_temp = ua_user_get_account(default_user, &account);
+ TC_PRT("ua_user_get_account returned : %s", __ua_get_error_string(ret_temp));
+ if (UA_ERROR_NONE == ret_temp) {
+ TC_PRT("User account info %s", account);
+ free(account);
+ }
+ }
+ break;
+ }
+ case UA_TEST_FUNCTION_CREATE_DEVICE: {
+ int mac_type;
+
+ if (device)
+ ua_destroy_device(device);
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ mac_type = atoi(test_param.params[0]);
+ ret = ua_create_device(mac_type, &device);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_DESTROY_DEVICE: {
+ ret = ua_destroy_device(device);
+ user = NULL;
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_USER_ACCOUNT: {
+ char* account = NULL;
+
+ ret = ua_user_get_account(user, &account);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("Account info : %s", account);
+ free(account);
+ }
+ break;
+ }
+ case UA_TEST_FUNCTION_SET_USER_NAME: {
+ char name[UA_USER_NAME_MAX_STRING_SIZE];
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ g_strlcpy(name, test_param.params[0],
+ UA_USER_NAME_MAX_STRING_SIZE);
+ ret = ua_user_set_name(user, name);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_USER_NAME: {
+ char* name = NULL;
+
+ ret = ua_user_get_name(user, &name);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("User name info : %s", name);
+ free(name);
+ }
+ break;
+ }
case UA_TEST_FUNCTION_SET_OS_INFO: {
- int os;
+ int os_info;
if (test_param.param_count < 1) {
TC_PRT("Input parameters first");
break;
}
- os = atoi(test_param.params[0]);
- ret = ua_user_set_os_info(user, os);
+ os_info = atoi(test_param.params[0]);
+ ret = ua_device_set_os_info(device, os_info);
TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ __ua_free_test_param(&test_param);
break;
}
- case UA_TEST_FUNCTION_SET_MAC_INFO: {
- int mac_type;
+ case UA_TEST_FUNCTION_GET_OS_INFO: {
+ ua_os_type_e os_info;
+
+ ret = ua_device_get_os_info(device, &os_info);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret)
+ TC_PRT("OS info : 0x%2.2X", os_info);
+ break;
+ }
+ case UA_TEST_FUNCTION_SET_MAC_ADDRESS: {
+ char mac[UA_MAC_ADDRESS_STRING_SIZE];
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ g_strlcpy(mac, test_param.params[0],
+ UA_MAC_ADDRESS_STRING_SIZE);
+ ret = ua_device_set_mac_address(device, mac);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_MAC_ADDRESS: {
+ char* mac = NULL;
+
+ ret = ua_device_get_mac_address(device, &mac);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("Mac info : %s", mac);
+ free(mac);
+ }
+ break;
+ }
+ case UA_TEST_FUNCTION_SET_MOBILE_ID: {
+ char mobile_id[UA_MOBILE_ID_STRING_SIZE];
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ g_strlcpy(mobile_id, test_param.params[0],
+ UA_MOBILE_ID_STRING_SIZE);
+ ret = ua_device_set_wifi_mobile_id(device, mobile_id);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_MOBILE_ID: {
+ char* mobile_id = NULL;
+
+ ret = ua_device_get_wifi_mobile_id(device, &mobile_id);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("Mobile ID : %s", mobile_id);
+ free(mobile_id);
+ }
+ break;
+ }
+ case UA_TEST_FUNCTION_SET_IPV4_ADDRESS: {
+ char ipv4_address[UA_IPV4_ADDRESS_STRING_SIZE];
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ g_strlcpy(ipv4_address, test_param.params[0],
+ UA_IPV4_ADDRESS_STRING_SIZE);
+ ret = ua_device_set_wifi_ipv4_address(device, ipv4_address);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_IPV4_ADDRESS: {
+ char* ipv4_address = NULL;
+
+ ret = ua_device_get_wifi_ipv4_address(device, &ipv4_address);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("IPV4 address : %s", ipv4_address);
+ free(ipv4_address);
+ }
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MAC_ADDRESS: {
char mac[UA_MAC_ADDRESS_STRING_SIZE];
+ ua_device_h device_handle = NULL;
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ g_strlcpy(mac, test_param.params[0],
+ UA_MAC_ADDRESS_STRING_SIZE);
+ ret = ua_device_get_handle_by_mac_address(mac, &device_handle);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ char* mobile_id = NULL;
+ TC_PRT("Get device handle successful for mac = %s", mac);
+ ret = ua_device_get_wifi_mobile_id(device_handle, &mobile_id);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("Mobile ID for this device : %s", mobile_id);
+ free(mobile_id);
+ }
+ /* TODO : Whether to destroy this device handle */
+ }
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MOBILE_ID: {
+ char mobile_id[UA_MOBILE_ID_STRING_SIZE];
+ ua_device_h device_handle = NULL;
+ int mac_type;
if (test_param.param_count < 2) {
TC_PRT("Input parameters first");
@@ -389,46 +686,95 @@ int test_input_callback(void *data)
}
mac_type = atoi(test_param.params[0]);
- g_strlcpy(mac, test_param.params[1],
+ g_strlcpy(mobile_id, test_param.params[1],
+ UA_MOBILE_ID_STRING_SIZE);
+ ret = ua_device_get_handle_by_mobile_id(mobile_id, mac_type, &device_handle);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ char* mac = NULL;
+ TC_PRT("Get device handle successful for mobile id = %s", mobile_id);
+ ret = ua_device_get_mac_address(device_handle, &mac);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret) {
+ TC_PRT("MAC address for this device : %s", mac);
+ free(mac);
+ }
+ /* TODO : Whether to destroy this device handle */
+ }
+ __ua_free_test_param(&test_param);
+ break;
+ }
+ case UA_TEST_FUNCTION_USER_ADD_DEVICE: {
+ ret = ua_user_add_device(user, device);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ break;
+ }
+ case UA_TEST_FUNCTION_USER_REMOVE_DEVICE: {
+ ret = ua_user_remove_device(user, device);
+ TC_PRT("returns %s", __ua_get_error_string(ret));
+ break;
+ }
+ case UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MAC_ADDRESS: {
+ char mac[UA_MAC_ADDRESS_STRING_SIZE];
+
+ if (test_param.param_count < 1) {
+ TC_PRT("Input parameters first");
+ break;
+ }
+
+ g_strlcpy(mac, test_param.params[0],
UA_MAC_ADDRESS_STRING_SIZE);
- ret = ua_user_set_mac_addr_info(user, mac_type, mac);
+ ret = ua_remove_device_by_address(mac);
TC_PRT("returns %s", __ua_get_error_string(ret));
+ if (UA_ERROR_NONE == ret)
+ TC_PRT("Device removed for mac : %s", mac);
+ __ua_free_test_param(&test_param);
break;
}
- case UA_TEST_FUNCTION_GET_DEVICE_INFO: {
- ua_dev_info_t dev_info;
+ case UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MOBILE_ID: {
+ char mobile_id[UA_MOBILE_ID_STRING_SIZE];
+ int mac_type;
+
+ if (test_param.param_count < 2) {
+ TC_PRT("Input parameters first");
+ break;
+ }
- ret = ua_user_get_dev_info(user, &dev_info);
+ mac_type = atoi(test_param.params[0]);
+ g_strlcpy(mobile_id, test_param.params[1],
+ UA_MOBILE_ID_STRING_SIZE);
+ ret = ua_remove_device_by_mobile_id(mobile_id, mac_type);
TC_PRT("returns %s", __ua_get_error_string(ret));
if (UA_ERROR_NONE == ret)
- TC_PRT("OS: 0x%2.2X, MAC type: 0x%2.2X, MAC: %s",
- dev_info.os, dev_info.type, dev_info.mac);
+ TC_PRT("Device removed for mobile id : %s", mobile_id);
+
+ __ua_free_test_param(&test_param);
break;
}
case UA_TEST_FUNCTION_GET_REGISTERED_DEVICES: {
- ret = ua_foreach_registered_dev_info(
+ ret = ua_foreach_all_registered_dev_info(
__foreach_registered_dev_cb, NULL);
TC_PRT("returns %s", __ua_get_error_string(ret));
break;
}
- case UA_TEST_FUNCTION_IS_PAIRING_REQUIRED: {
- bool required = false;
- ret = ua_user_get_is_pairing_required(user, &required);
+ case UA_TEST_FUNCTION_GET_REGISTERED_DEVICES_BY_USERS: {
+ ret = ua_foreach_registered_dev_info_by_user(user,
+ __foreach_registered_dev_cb, NULL);
TC_PRT("returns %s", __ua_get_error_string(ret));
- TC_PRT("Pairing %s required", (required ? "is" : "not"));
break;
}
- case UA_TEST_FUNCTION_ENABLE_AMBIENT_MODE: {
- ret = ua_user_enable_ambient_mode(
- user, __ambient_mode_cb, NULL);
+ case UA_TEST_FUNCTION_GET_REGISTERED_USERS: {
+ ret = ua_foreach_registered_users(
+ __foreach_registered_user_cb, NULL);
TC_PRT("returns %s", __ua_get_error_string(ret));
break;
}
- case UA_TEST_FUNCTION_DISABLE_AMBIENT_MODE: {
- ret = ua_user_disable_ambient_mode(
- user, __ambient_mode_cb, NULL);
+ case UA_TEST_FUNCTION_IS_PAIRING_REQUIRED: {
+ bool required = false;
+ ret = ua_device_get_pairing_required(device, &required);
TC_PRT("returns %s", __ua_get_error_string(ret));
+ TC_PRT("Pairing %s required", (required ? "is" : "not"));
break;
}
case UA_TEST_FUNCTION_SET_PARAMETERS: {
@@ -451,7 +797,7 @@ void tc_usage_print(void)
while (tc_table[i].tc_name) {
TC_PRT("Key %d : usage %s", tc_table[i].tc_code,
- tc_table[i].tc_name);
+ tc_table[i].tc_name);
i++;
}
@@ -468,17 +814,17 @@ void test_set_params(char *buf)
switch (test_id) {
case UA_TEST_FUNCTION_ADD_SENSOR:
- param_count = 2;
+ param_count = 1;
switch (param_index) {
case 0:
TC_PRT("Input Sensor type:"
- "\n1 - UA_SENSOR_LIGHT"
- "\n2 - UA_SENSOR_MOTION"
- "\n3 - UA_SENSOR_BLE");
- break;
- case 1:
- TC_PRT("Input Absence period");
+ "\n1 - UA_SENSOR_BT"
+ "\n2 - UA_SENSOR_BLE"
+ "\n3 - UA_SENSOR_WIFI"
+ "\n4 - UA_SENSOR_MOTION"
+ "\n5 - UA_SENSOR_BRIGHTNESS"
+ "\n6 - UA_SENSOR_AUDIO");
break;
}
break;
@@ -488,24 +834,24 @@ void test_set_params(char *buf)
switch (param_index) {
case 0:
TC_PRT("Input Sensor type:"
- "\n1 - UA_SENSOR_LIGHT"
- "\n2 - UA_SENSOR_MOTION"
- "\n3 - UA_SENSOR_BLE");
+ "\n1 - UA_SENSOR_BT"
+ "\n2 - UA_SENSOR_BLE"
+ "\n3 - UA_SENSOR_WIFI"
+ "\n4 - UA_SENSOR_MOTION"
+ "\n5 - UA_SENSOR_BRIGHTNESS"
+ "\n6 - UA_SENSOR_AUDIO");
break;
}
break;
- case UA_TEST_FUNCTION_SET_ABSENCE_PERIOD:
+ case UA_TEST_FUNCTION_SET_BRIGHTNESS_THRESHOLD:
param_count = 2;
switch (param_index) {
case 0:
- TC_PRT("Input Sensor type:"
- "\n1 - UA_SENSOR_LIGHT"
- "\n2 - UA_SENSOR_MOTION"
- "\n3 - UA_SENSOR_BLE");
+ TC_PRT("Input Presence threshold: <x>");
break;
case 1:
- TC_PRT("Input Absence period");
+ TC_PRT("Input Absence threshold: <x>");
break;
}
break;
@@ -515,8 +861,8 @@ void test_set_params(char *buf)
switch (param_index) {
case 0:
TC_PRT("Input detection mode:"
- "\n1 - UA_DETECT_MODE_ALL_SENSOR"
- "\n2 - UA_DETECT_MODE_ANY_SENSOR");
+ "\n1 - UA_DETECT_MODE_ALL_SENSOR"
+ "\n2 - UA_DETECT_MODE_ANY_SENSOR");
break;
}
break;
@@ -526,8 +872,53 @@ void test_set_params(char *buf)
switch (param_index) {
case 0:
TC_PRT("Input detection mode:"
- "\n1 - UA_DETECT_MODE_ALL_SENSOR"
- "\n2 - UA_DETECT_MODE_ANY_SENSOR");
+ "\n1 - UA_DETECT_MODE_ALL_SENSOR"
+ "\n2 - UA_DETECT_MODE_ANY_SENSOR");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_IS_SENSOR_AVAILABLE:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input Sensor type:"
+ "\n1 - UA_SENSOR_BT"
+ "\n2 - UA_SENSOR_BLE"
+ "\n3 - UA_SENSOR_WIFI"
+ "\n4 - UA_SENSOR_MOTION"
+ "\n5 - UA_SENSOR_BRIGHTNESS"
+ "\n6 - UA_SENSOR_AUDIO");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_CREATE_USER:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input account: <xxxx@xxxx.com>");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_CREATE_DEVICE:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input MAC type:"
+ "\n0 - UA_MAC_TYPE_BT"
+ "\n1 - UA_MAC_TYPE_WIFI"
+ "\n2 - UA_SENSOR_P2P");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_SET_USER_NAME:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input User name: <xxxxxxx>");
break;
}
break;
@@ -537,25 +928,84 @@ void test_set_params(char *buf)
switch (param_index) {
case 0:
TC_PRT("Input Device OS:"
- "\n0 - UA_OS_TYPE_ANDROID"
- "\n1 - UA_OS_TYPE_IOS"
- "\n2 - UA_OS_TYPE_TIZEN");
+ "\n1 - UA_OS_TYPE_TIZEN"
+ "\n2 - UA_OS_TYPE_ANDROID"
+ "\n3 - UA_OS_TYPE_IOS");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_SET_MAC_ADDRESS:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input MAC: <XX:XX:XX:XX:XX:XX>");
break;
}
break;
- case UA_TEST_FUNCTION_SET_MAC_INFO:
+ case UA_TEST_FUNCTION_SET_MOBILE_ID:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input Mobile ID: <XX:XX:XX:XX:XX:XX>");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_SET_IPV4_ADDRESS:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input IPV4 address: <XXX:XXX:XXX:XXX>");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MAC_ADDRESS:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input MAC address: <XXX:XXX:XXX:XXX>");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MOBILE_ID:
param_count = 2;
switch (param_index) {
case 0:
TC_PRT("Input MAC type:"
"\n0 - UA_MAC_TYPE_BT"
- "\n1 - UA_MAC_TYPE_BLE"
- "\n2 - UA_MAC_TYPE_WIFI"
- "\n3 - UA_MAC_TYPE_P2P");
+ "\n1 - UA_MAC_TYPE_WIFI"
+ "\n2 - UA_SENSOR_P2P");
break;
case 1:
- TC_PRT("Input MAC: <XX:XX:XX:XX:XX:XX>");
+ TC_PRT("Input Mobile ID: <XXX:XXX:XXX:XXX>");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MAC_ADDRESS:
+ param_count = 1;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input MAC address: <XXX:XXX:XXX:XXX>");
+ break;
+ }
+ break;
+ case UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MOBILE_ID:
+ param_count = 2;
+
+ switch (param_index) {
+ case 0:
+ TC_PRT("Input MAC type:"
+ "\n0 - UA_MAC_TYPE_BT"
+ "\n1 - UA_MAC_TYPE_WIFI"
+ "\n2 - UA_SENSOR_P2P");
+ break;
+ case 1:
+ TC_PRT("Input Mobile ID: <XXX:XXX:XXX:XXX>");
break;
}
break;
@@ -594,8 +1044,8 @@ done:
}
static gboolean key_event_cb(GIOChannel *chan,
- GIOCondition cond,
- gpointer data)
+ GIOCondition cond,
+ gpointer data)
{
char buf[BUFFER_LEN] = { 0 };
unsigned int len = 0;
diff --git a/test/user-awareness-test.h b/test/user-awareness-test.h
index 20e343b..cc5763a 100644
--- a/test/user-awareness-test.h
+++ b/test/user-awareness-test.h
@@ -33,25 +33,46 @@ typedef enum {
UA_TEST_FUNCTION_CREATE_MONITOR = 0x01,
UA_TEST_FUNCTION_DESTROY_MONITOR,
UA_TEST_FUNCTION_SET_SENSOR_STATE_CB,
+ UA_TEST_FUNCTION_UNSET_SENSOR_STATE_CB,
UA_TEST_FUNCTION_ADD_SENSOR,
UA_TEST_FUNCTION_REMOVE_SENSOR,
- UA_TEST_FUNCTION_SET_ABSENCE_PERIOD,
+ UA_TEST_FUNCTION_SET_BRIGHTNESS_THRESHOLD,
UA_TEST_FUNCTION_START_PRESENCE_DETECTION,
UA_TEST_FUNCTION_STOP_PRESENCE_DETECTION,
UA_TEST_FUNCTION_START_ABSENCE_DETECTION,
UA_TEST_FUNCTION_STOP_ABSENCE_DETECTION,
UA_TEST_FUNCTION_START_HEADLESS_MONITORING,
UA_TEST_FUNCTION_STOP_HEADLESS_MONITORING,
+ UA_TEST_FUNCTION_IS_SENSOR_AVAILABLE,
UA_TEST_FUNCTION_CREATE_USER,
UA_TEST_FUNCTION_DESTROY_USER,
+ UA_TEST_FUNCTION_ADD_USER,
+ UA_TEST_FUNCTION_REMOVE_USER,
+ UA_TEST_FUNCTION_GET_DEFAULT_USER,
+ UA_TEST_FUNCTION_CREATE_DEVICE,
+ UA_TEST_FUNCTION_DESTROY_DEVICE,
+ UA_TEST_FUNCTION_GET_USER_ACCOUNT,
+ UA_TEST_FUNCTION_SET_USER_NAME,
+ UA_TEST_FUNCTION_GET_USER_NAME,
UA_TEST_FUNCTION_SET_OS_INFO,
- UA_TEST_FUNCTION_SET_MAC_INFO,
- UA_TEST_FUNCTION_GET_DEVICE_INFO,
+ UA_TEST_FUNCTION_GET_OS_INFO,
+ UA_TEST_FUNCTION_SET_MAC_ADDRESS,
+ UA_TEST_FUNCTION_GET_MAC_ADDRESS,
+ UA_TEST_FUNCTION_SET_MOBILE_ID,
+ UA_TEST_FUNCTION_GET_MOBILE_ID,
+ UA_TEST_FUNCTION_SET_IPV4_ADDRESS,
+ UA_TEST_FUNCTION_GET_IPV4_ADDRESS,
+ UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MAC_ADDRESS,
+ UA_TEST_FUNCTION_GET_DEVICE_HANDLE_BY_MOBILE_ID,
+ UA_TEST_FUNCTION_USER_ADD_DEVICE,
+ UA_TEST_FUNCTION_USER_REMOVE_DEVICE,
+ UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MAC_ADDRESS,
+ UA_TEST_FUNCTION_REMOVE_DEVICE_BY_MOBILE_ID,
UA_TEST_FUNCTION_GET_REGISTERED_DEVICES,
+ UA_TEST_FUNCTION_GET_REGISTERED_DEVICES_BY_USERS,
+ UA_TEST_FUNCTION_GET_REGISTERED_USERS,
UA_TEST_FUNCTION_IS_PAIRING_REQUIRED,
- UA_TEST_FUNCTION_ENABLE_AMBIENT_MODE,
- UA_TEST_FUNCTION_DISABLE_AMBIENT_MODE,
UA_TEST_FUNCTION_SET_PARAMETERS
} ua_test_function_e;