diff options
-rw-r--r-- | src/user-awareness-monitors.c | 49 |
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); |