summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhay Agarwal <ay.agarwal@samsung.com>2019-10-10 16:51:06 +0900
committersaerome.kim <saerome.kim@samsung.com>2019-10-11 10:27:00 +0900
commit7a79d757145381a859b9733f7e3180593e7fa730 (patch)
tree2e7c439d09dd7c595fcabf837511665bd1af0385
parent6f5d78b42e2a7d171b18ab6a6f1e74a3c1b00eed (diff)
downloaduser-awareness-7a79d757145381a859b9733f7e3180593e7fa730.tar.gz
user-awareness-7a79d757145381a859b9733f7e3180593e7fa730.tar.bz2
user-awareness-7a79d757145381a859b9733f7e3180593e7fa730.zip
Provide user presence callback in case no user information presentsubmit/tizen/20191011.014757accepted/tizen/unified/20191011.080021
AND/OR condition being used to provide user presence callback can get satisfied without user information also with the presence of environmental sensors. This patch also modifies to provide user callback at the end of detection window to provide application with more detection data. Change-Id: I3236762071303e565d689b66dc1261cb98c27bc3 Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rw-r--r--include/user-awareness-private.h1
-rw-r--r--packaging/capi-network-ua.spec2
-rw-r--r--src/user-awareness-monitors.c217
-rw-r--r--src/user-awareness-users.c1
-rw-r--r--test/uat-init.c22
5 files changed, 155 insertions, 88 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h
index 357e7cc..d1ccf18 100644
--- a/include/user-awareness-private.h
+++ b/include/user-awareness-private.h
@@ -192,6 +192,7 @@ typedef struct {
char *service; /**< Service name */
GSList *user_state; /**< User current state i.e presence or absence */
void *user_data; /**< User data */
+ gboolean env_user_cb_sent; /** User presence callback sent or not flag for environmental sensors */
} ua_monitor_s;
/**
diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec
index 008c1b3..5325c95 100644
--- a/packaging/capi-network-ua.spec
+++ b/packaging/capi-network-ua.spec
@@ -1,6 +1,6 @@
Name: capi-network-ua
Summary: User Awareness Framework CAPI
-Version: 0.11.4
+Version: 0.11.5
Release: 1
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index 789f042..2453054 100644
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -163,6 +163,7 @@ static void __ua_user_state_clean()
g_slist_free_full(monitor->user_state, __ua_free_user_state_info_t);
monitor->user_state = NULL;
+ monitor->env_user_cb_sent = FALSE;
}
FUNC_EXIT;
}
@@ -185,36 +186,6 @@ static bool __ua_check_all_users_absence_state(GSList *user_state, unsigned int
return true;
}
-static void __ua_send_presence_detection()
-{
- FUNC_ENTRY;
- GSList *l;
-
- for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
- ua_monitor_s *monitor = l->data;
-
- if (!monitor)
- continue;
-
- if (monitor->presence_mode == UA_DETECT_MODE_ANY_SENSOR) {
- monitor->presence_detected_bitmask = 0;
- continue;
- }
-
- UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->presence_detected_bitmask: 0x%8.8X",
- monitor->sensor_bitmask, monitor->presence_detected_bitmask);
- if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) {
- if (monitor->presence_cb)
- monitor->presence_cb(UA_ERROR_NONE, monitor,
- monitor->presence_detected_bitmask, NULL, NULL, monitor->user_data);
- }
-
- monitor->presence_detected_bitmask = 0;
- }
-
- FUNC_EXIT;
-}
-
static ua_user_state_info_s* __ua_monitor_user_state_create(char *account)
{
ua_user_state_info_s *user_state;
@@ -236,78 +207,103 @@ static ua_user_state_info_s* __ua_monitor_user_state_create(char *account)
return user_state;
}
-static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
- ua_user_state_info_s *user_state)
+static gboolean __ua_monitor_check_presence_and_or_condition(ua_monitor_s *monitor,
+ unsigned int connectivity_bitmask)
{
FUNC_ENTRY;
unsigned int env_presence_bitmask = 0;
- unsigned int user_sensor_bitmask = user_state->sensor_bitmask;
- unsigned int filter_bitmask = 0;
- unsigned int dev_bitmask = 0;
- GSList *l = 0;
- GSList *devices = 0;
gboolean and_condition = 0;
gboolean or_condition = 0;
gboolean condition_result = 0;
- ua_dev_info_s *dev = 0;
- GSList *sensors = 0;
- ret_if(NULL == user_state);
-
- ua_user_h user_handle = _ua_get_user_handle_by_account(
- user_state->account);
env_presence_bitmask = monitor->presence_detected_bitmask
& (UA_SENSOR_MOTION | UA_SENSOR_LIGHT);
- filter_bitmask =
- monitor->presence_bitmask_and | monitor->presence_bitmask_or;
-
- /**
- * Check whether user_handle present or not and also check
- * whether presence has been started or not.
- */
- if (!user_handle || user_state->cb_sent
- || !monitor->presence_user_cb.callback
- || !monitor->presence_detection_started) {
- FUNC_EXIT;
- return;
- }
UA_DBG("Bitmasks: user's sensor [%u], env_pres [%u], " \
"conditions: AND [%u] - OR [%u]",
- user_sensor_bitmask, env_presence_bitmask,
+ connectivity_bitmask , env_presence_bitmask,
monitor->presence_bitmask_and, monitor->presence_bitmask_or);
and_condition = monitor->presence_bitmask_and ==
(monitor->presence_bitmask_and
- & (user_sensor_bitmask | env_presence_bitmask));
+ & (connectivity_bitmask | env_presence_bitmask));
or_condition = !monitor->presence_bitmask_or ||
(monitor->presence_bitmask_or
- & (user_sensor_bitmask | env_presence_bitmask));
+ & (connectivity_bitmask | env_presence_bitmask));
UA_DBG("Conditions': AND[%s] [%s] OR[%s]",
and_condition ? "true" : "false",
monitor->presence_conjunction == UA_OR_OPERATION ? "or" : "and",
or_condition ? "true" : "false");
- if (monitor->presence_conjunction == UA_OR_OPERATION)
+ if (monitor->presence_bitmask_and == 0 || monitor->presence_bitmask_or == 0)
+ condition_result = monitor->presence_bitmask_and ? or_condition : and_condition;
+ else if (monitor->presence_conjunction == UA_OR_OPERATION)
condition_result = and_condition || or_condition;
else
condition_result = and_condition && or_condition;
if (!condition_result) {
UA_DBG("User presence AND/OR conditions failed");
+ }
+
+ FUNC_EXIT;
+ return condition_result;
+}
+
+static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
+ ua_user_state_info_s *user_state)
+{
+ FUNC_ENTRY;
+ unsigned int env_bitmask = 0;
+ unsigned int filter_bitmask = 0;
+ unsigned int dev_bitmask = 0;
+ GSList *l = 0;
+ GSList *devices = 0;
+ ua_dev_info_s *dev = 0;
+ GSList *sensors = 0;
+ gboolean condition_result = 0;
+
+ ret_if(NULL == user_state);
+
+ ua_user_h user_handle = _ua_get_user_handle_by_account(
+ user_state->account);
+ /**
+ * Check whether user_handle present or not and also check
+ * whether presence has been started or not.
+ */
+ if (!user_handle || user_state->cb_sent
+ || !monitor->presence_user_cb.callback
+ || !monitor->presence_detection_started) {
+ FUNC_EXIT;
+ return;
+ }
+
+ /** Check AND/OR condition*/
+ if (user_state->sensor_bitmask)
+ condition_result = __ua_monitor_check_presence_and_or_condition(monitor,
+ user_state->sensor_bitmask);
+ if (!condition_result) {
+ UA_DBG("User presence AND/OR conditions failed");
FUNC_EXIT;
return;
}
+ env_bitmask = monitor->presence_detected_bitmask
+ & (UA_SENSOR_MOTION | UA_SENSOR_LIGHT);
+
/** Get sensor list*/
- sensors = ua_sensor_get_sensor_handle_list(monitor->presence_detected_bitmask);
+ sensors = ua_sensor_get_sensor_handle_list(
+ monitor->presence_detected_bitmask & (user_state->sensor_bitmask | env_bitmask));
/**
* Filter the list of found_devices according to sensors mentioned in
* AND/OR conditions.
*/
+ filter_bitmask =
+ monitor->presence_bitmask_and | monitor->presence_bitmask_or;
+
for (l = user_state->found_devices; l; l = g_slist_next(l)) {
dev = (ua_dev_info_s *)l->data;
if(!dev)
@@ -326,6 +322,7 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
monitor->presence_user_cb.user_data);
user_state->cb_sent = TRUE;
+ monitor->env_user_cb_sent = TRUE;
g_slist_free(devices);
g_slist_free(sensors);
@@ -334,6 +331,81 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
return;
}
+static void __ua_monitor_send_env_user_presence_cb(ua_monitor_s *monitor)
+{
+ FUNC_ENTRY;
+ GSList *sensors = 0;
+ gboolean condition_result = 0;
+
+ if (monitor->env_user_cb_sent) {
+ UA_DBG("Environmental User presence cb already sent");
+ FUNC_EXIT;
+ return;
+ }
+
+ /** Check AND/OR condition*/
+ condition_result = __ua_monitor_check_presence_and_or_condition(monitor, 0);
+ if (!condition_result) {
+ UA_DBG("presence AND/OR conditions failed");
+ FUNC_EXIT;
+ return;
+ }
+
+ /** Get sensor list*/
+ sensors = ua_sensor_get_sensor_handle_list(monitor->presence_detected_bitmask);
+
+ ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
+ UA_ERROR_NONE, monitor, NULL,
+ NULL, sensors,
+ monitor->presence_user_cb.user_data);
+
+ monitor->env_user_cb_sent = TRUE;
+ g_slist_free(sensors);
+
+ FUNC_EXIT;
+ return;
+}
+
+static void __ua_send_presence_detection()
+{
+ FUNC_ENTRY;
+ GSList *l;
+ GSList *l1;
+
+ for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
+
+ if (!monitor)
+ continue;
+
+ if (monitor->presence_mode != UA_DETECT_MODE_ANY_SENSOR) {
+ UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->presence_detected_bitmask: 0x%8.8X",
+ monitor->sensor_bitmask, monitor->presence_detected_bitmask);
+ if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) {
+ if (monitor->presence_cb)
+ monitor->presence_cb(UA_ERROR_NONE, monitor,
+ monitor->presence_detected_bitmask, NULL, NULL, monitor->user_data);
+ }
+ }
+
+ if (monitor->presence_user_cb.callback) {
+ for (l1 = monitor->user_state; NULL != l1; l1 = g_slist_next(l1)) {
+ ua_user_state_info_s *user_state = l1->data;
+
+ if (user_state) {
+ UA_DBG("user_state->account [%s]", user_state->account);
+ __ua_monitor_send_user_presence_cb(monitor, user_state);
+ }
+ }
+ __ua_monitor_send_env_user_presence_cb(monitor);
+ }
+
+ monitor->presence_detected_bitmask = 0;
+ }
+
+ FUNC_EXIT;
+}
+
static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor,
ua_device_h device_handle, ua_sensor_info_s *sensor_info)
{
@@ -395,7 +467,6 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
FUNC_ENTRY;
GSList *l;
- GSList *us;
int found = 0;
int ret = UA_ERROR_NONE;
ua_user_state_info_s *user_state = NULL;
@@ -446,20 +517,6 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
__ua_monitor_send_sensor_presence_cb(monitor, device_handle, sensor_info);
- if (account && user_state) {
- __ua_monitor_send_user_presence_cb(monitor, user_state);
- }
- /* For the case when internal_presence_started is running */
- /* if environmental sensor comes after connectivity sensor */
- if (!account) {
- for (us = monitor->user_state; us; us = g_slist_next(us)) {
- user_state = (ua_user_state_info_s *)us->data;
- UA_DBG("user_state->account [%s]", user_state->account);
-
- __ua_monitor_send_user_presence_cb(monitor, user_state);
- }
- }
-
FUNC_EXIT;
}
@@ -513,7 +570,9 @@ static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
monitor->absence_conjunction == UA_OR_OPERATION ? "or" : "and",
or_condition ? "true" : "false");
- if (monitor->absence_conjunction == UA_OR_OPERATION)
+ if (monitor->absence_bitmask_and == 0 || monitor->absence_bitmask_or == 0)
+ condition_result = monitor->absence_bitmask_and ? or_condition : and_condition;
+ else if (monitor->absence_conjunction == UA_OR_OPERATION)
condition_result = and_condition || or_condition;
else
condition_result = and_condition && or_condition;
@@ -525,7 +584,8 @@ static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
}
/** Get sensor list*/
- sensors = ua_sensor_get_sensor_handle_list(monitor->absence_detected_bitmask);
+ sensors = ua_sensor_get_sensor_handle_list(
+ monitor->absence_detected_bitmask & (user_sensor_bitmask | env_absence_bitmask));
((ua_absence_user_detected_cb)monitor->absence_user_cb.callback)(
UA_ERROR_NONE, monitor, user_handle, sensors,
@@ -1596,6 +1656,7 @@ int ua_monitor_stop_presence_detection(ua_monitor_h handle)
monitor->presence_detection_started = FALSE;
g_slist_free_full(monitor->user_state, __ua_free_user_state_info_t);
monitor->user_state = NULL;
+ monitor->env_user_cb_sent = FALSE;
if (!monitor->absence_detection_started) {
g_free(monitor->service);
diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c
index 0e4ea15..057fefa 100644
--- a/src/user-awareness-users.c
+++ b/src/user-awareness-users.c
@@ -565,7 +565,6 @@ int ua_user_get_default_user(ua_user_h* user_handle)
}
}
-
ret = _ua_get_error_code(_uam_get_default_user(&uam_user));
if (UA_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
diff --git a/test/uat-init.c b/test/uat-init.c
index 9a36364..c91c617 100644
--- a/test/uat-init.c
+++ b/test/uat-init.c
@@ -165,15 +165,21 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
msg("\n[%s]", pbuf);
free(pbuf);
- ret = ua_user_get_account(user_handle, &account);
- if (UA_ERROR_NONE != ret) {
- msg(" - ua_user_get_account() ret: [0x%X] [%s]",
- ret, uat_get_error_str(ret));
+ if (user_handle) {
+ ret = ua_user_get_account(user_handle, &account);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_user_get_account() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+ msgb("[%s] PRESENCE detected [%s]", account, uat_get_error_str(result));
+ g_slist_foreach(device_handles,
+ __user_presence_detected_foreach_devices,
+ account);
+ }
+
+ if (!account) {
+ msgb("[No user information] PRESENCE detected [%s]", uat_get_error_str(result));
}
- msgb("[%s] PRESENCE detected [%s]", account, uat_get_error_str(result));
- g_slist_foreach(device_handles,
- __user_presence_detected_foreach_devices,
- account);
g_slist_foreach(sensor_handles,
__user_detected_foreach_sensors, NULL);