summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Chaprana <n.chaprana@samsung.com>2019-07-10 18:53:48 +0530
committersaerome kim <saerome.kim@samsung.com>2019-07-11 08:25:10 +0900
commit59f32dc02532b96e0400ee55c622aa7c7f65b968 (patch)
treeb4a2179e0f8397fbbd40e2d911babb8c1231148a
parent8f335edf3369ec9fcf194a92bd7947733a75978e (diff)
downloaduser-awareness-59f32dc02532b96e0400ee55c622aa7c7f65b968.tar.gz
user-awareness-59f32dc02532b96e0400ee55c622aa7c7f65b968.tar.bz2
user-awareness-59f32dc02532b96e0400ee55c622aa7c7f65b968.zip
Update ref count mechanism to start/stop internal presence monitoring
This patch updates internal logic. It handles the cases to start and stop internal presence monitoring when application only registers absence monitoring callback or application registers user absence detection callback. Note: Internal presence monitoring is required to get presence events for user from ua-manager which will be consumed internally and not passed to application. Change-Id: I094873378d387de03c646df202286d28fb56428e Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
-rw-r--r--src/user-awareness-monitors.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index ea3217c..b9b2f66 100644
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -297,14 +297,19 @@ int ua_monitor_set_user_absence_detected_cb(ua_monitor_h handle,
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ if (monitor->absence_user_cb.callback != NULL) {
+ FUNC_EXIT;
+ return UA_ERROR_INVALID_PARAMETER;
+ }
+
monitor->absence_user_cb.callback = callback;
monitor->absence_user_cb.user_data = user_data;
- if(monitor->absence_detection_started) {
- if(!monitor->presence_detection_started && !monitor->internal_presence_started)
- __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
- __ua_monitor_internal_presence_ref(monitor);
- }
+ if (monitor->absence_detection_started && !monitor->internal_presence_started &&
+ !monitor->presence_detection_started)
+ __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+
+ __ua_monitor_internal_presence_ref(monitor);
FUNC_EXIT;
return UA_ERROR_NONE;
@@ -335,14 +340,18 @@ int ua_monitor_unset_user_absence_detected_cb(ua_monitor_h handle)
UA_VALIDATE_INPUT_PARAMETER(handle);
UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+ if (monitor->absence_user_cb.callback == NULL) {
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+ }
+
monitor->absence_user_cb.callback = NULL;
monitor->absence_user_cb.user_data = NULL;
- if(monitor->internal_presence_started) {
- if(!monitor->presence_detection_started)
- __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
- __ua_monitor_internal_presence_unref(monitor);
- }
+ __ua_monitor_internal_presence_unref(monitor);
+
+ if (!monitor->internal_presence_started && !monitor->presence_detection_started)
+ __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
FUNC_EXIT;
return UA_ERROR_NONE;
@@ -544,7 +553,7 @@ int ua_monitor_start_presence_detection(
/* TODO: Check if we have to check is_sensor_ready at this point and remove sensor
* from monitor if sensor is not ready
*/
- if(!monitor->internal_presence_started) {
+ if(!monitor->internal_presence_started || !monitor->absence_detection_started) {
ret = __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, detect);
if (UA_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
@@ -599,13 +608,13 @@ int ua_monitor_start_absence_detection(
* from monitor if sensor is not ready.
*/
ret = __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, detect);
- if (monitor->absence_user_cb.callback ||
- mode == UA_DETECT_MODE_ALL_SENSOR) {
- if (!monitor->presence_detection_started)
- __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+
+ if (mode == UA_DETECT_MODE_ALL_SENSOR)
__ua_monitor_internal_presence_ref(monitor);
- }
+ if (monitor->internal_presence_started)
+ if (!monitor->presence_detection_started)
+ __ua_start_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
if (UA_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
@@ -665,7 +674,7 @@ int ua_monitor_stop_presence_detection(ua_monitor_h handle)
UA_VALIDATE_HANDLE(handle, ua_monitor_list);
retv_if(FALSE == monitor->presence_detection_started, UA_ERROR_NOT_IN_PROGRESS);
- if(!monitor->internal_presence_started) {
+ if (!monitor->internal_presence_started || !monitor->absence_detection_started) {
ret = __ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, detect);
if (UA_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
@@ -713,14 +722,16 @@ int ua_monitor_stop_absence_detection(ua_monitor_h handle)
/* LCOV_EXCL_STOP */
}
- if(!monitor->presence_detection_started && monitor->internal_presence_started)
+ if (!monitor->presence_detection_started)
__ua_stop_monitoring(monitor->sensor_bitmask, monitor->service, UA_PRESENCE_DETECTION);
+ if (monitor->absence_mode == UA_DETECT_MODE_ALL_SENSOR)
+ __ua_monitor_internal_presence_unref(monitor);
+
monitor->absence_mode = UA_DETECT_MODE_INVALID;
monitor->absence_cb = NULL;
monitor->user_data = NULL;
monitor->absence_detection_started = FALSE;
- __ua_monitor_internal_presence_unref(monitor);
if(!monitor->presence_detection_started) {
g_free(monitor->service);