return NULL;
}
-static unsigned int __uam_get_active_sesors(uam_pm_detection_mode_e mode)
+static unsigned int __uam_get_active_sensors(uam_pm_detection_mode_e mode)
{
FUNC_ENTRY;
unsigned int sensors = 0;
return UAM_ERROR_NONE;
}
-int _uam_core_start_presence_detection(char *sender, unsigned int sensors)
+static int __uam_core_start_detection(int detection_type, char *sender, unsigned int sensors)
{
FUNC_ENTRY;
int ret;
retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM);
- monitor = __uam_find_monitor(sender, UAM_DETECT_PRESENCE);
+ monitor = __uam_find_monitor(sender, detection_type);
if (!monitor) {
monitor = g_malloc0(sizeof(uam_monitor_info_t));
monitor->name = g_strdup(sender);
- monitor->mode = UAM_DETECT_PRESENCE;
+ monitor->mode = detection_type;
}
/* Find sensors which are already monitoring */
- active_sensors = __uam_get_active_sesors(UAM_DETECT_PRESENCE);
+ active_sensors = __uam_get_active_sensors(detection_type);
UAM_DBG("sensors: 0x%8.8X, active_sensors: 0x%8.8X", sensors, active_sensors);
inactive_sensors = (sensors & ~active_sensors);
}
/* Start monitoring only for sensors which aren't already active */
- ret = _uam_pm_start_detection(inactive_sensors, UAM_DETECT_PRESENCE);
+ ret = _uam_pm_start_detection(detection_type, inactive_sensors);
if (UAM_ERROR_NONE != ret) {
UAM_ERR("Failed with error: %s (0x%4.4X)",
_uam_manager_error_to_str(ret), ret);
return UAM_ERROR_NONE;
}
-int _uam_core_stop_presence_detection(char *sender, unsigned int sensors)
+static int __uam_core_stop_detection(int detection_type, char *sender, unsigned int sensors)
{
FUNC_ENTRY;
int ret;
retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM);
- monitor = __uam_find_monitor(sender, UAM_DETECT_PRESENCE);
+ monitor = __uam_find_monitor(sender, detection_type);
retv_if(NULL == monitor, UAM_ERROR_NOT_IN_OPERATION);
/* Find sensors which are already monitoring */
- active_sensors = __uam_get_active_sesors(UAM_DETECT_PRESENCE);
+ active_sensors = __uam_get_active_sensors(detection_type);
UAM_DBG("sensors: 0x%8.8X, Active sensors: 0x%8.8X",
sensors, active_sensors);
}
/* Find sensors which are already monitoring */
- remaining_sensors = __uam_get_active_sesors(UAM_DETECT_PRESENCE);
+ remaining_sensors = __uam_get_active_sensors(detection_type);
UAM_DBG("Remaining sensors: 0x%8.8X", remaining_sensors);
if (active_sensors == remaining_sensors) {
/* Stop monitoring only for sensors which aren't required anymore */
sensors = (active_sensors & ~remaining_sensors);
- ret = _uam_pm_stop_detection(sensors, UAM_DETECT_PRESENCE);
+ ret = _uam_pm_stop_detection(detection_type, sensors);
if (UAM_ERROR_NONE != ret)
UAM_ERR("Failed with error: %s (0x%4.4X)",
_uam_manager_error_to_str(ret), ret);
return UAM_ERROR_NONE;
}
-int _uam_core_start_absence_detection(char *sender, unsigned int sensors)
+int _uam_core_start_presence_detection(char *sender, unsigned int sensors)
{
FUNC_ENTRY;
int ret;
- int active_sensors;
- int inactive_sensors;
- uam_monitor_info_t *monitor;
- retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM);
+ ret = __uam_core_start_detection(UAM_DETECT_PRESENCE, sender, sensors);
- monitor = __uam_find_monitor(sender, UAM_DETECT_ABSENCE);
- if (!monitor) {
- monitor = g_malloc0(sizeof(uam_monitor_info_t));
- monitor->name = g_strdup(sender);
- monitor->mode = UAM_DETECT_ABSENCE;
- }
+ FUNC_EXIT;
+ return ret;
+}
- /* Find sensors which are already monitoring */
- active_sensors = __uam_get_active_sesors(UAM_DETECT_ABSENCE);
- UAM_DBG("sensors: 0x%8.8X, active_sensors: 0x%8.8X", sensors, active_sensors);
+int _uam_core_stop_presence_detection(char *sender, unsigned int sensors)
+{
+ FUNC_ENTRY;
+ int ret;
- inactive_sensors = (sensors & ~active_sensors);
- /*
- * If all requested sensors are already active, just update
- * monitor info for current application and return success.
- */
- if (0 == inactive_sensors) {
- UAM_DBG("All sensors are already monitoring");
- goto done;
- }
+ ret = __uam_core_stop_detection(UAM_DETECT_PRESENCE, sender, sensors);
- /* Start monitoring only for sensors which aren't already active */
- ret = _uam_pm_start_detection(inactive_sensors, UAM_DETECT_ABSENCE);
- if (UAM_ERROR_NONE != ret) {
- UAM_ERR("Failed with error: %s (0x%4.4X)",
- _uam_manager_error_to_str(ret), ret);
- g_free(monitor->name);
- g_free(monitor);
- return ret;
- }
+ FUNC_EXIT;
+ return ret;
+}
- monitors = g_slist_append(monitors, monitor);
+int _uam_core_start_absence_detection(char *sender, unsigned int sensors)
+{
+ FUNC_ENTRY;
+ int ret;
-done:
- monitor->sensors |= sensors;
+ ret = __uam_core_start_detection(UAM_DETECT_ABSENCE, sender, sensors);
FUNC_EXIT;
- return UAM_ERROR_NONE;
+ return ret;
}
int _uam_core_stop_absence_detection(char *sender, unsigned int sensors)
{
FUNC_ENTRY;
int ret;
- unsigned int remaining_sensors;
- unsigned int active_sensors;
- uam_monitor_info_t *monitor;
-
- retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM);
-
- monitor = __uam_find_monitor(sender, UAM_DETECT_ABSENCE);
- retv_if(NULL == monitor, UAM_ERROR_NOT_IN_OPERATION);
-
- /* Find sensors which are already monitoring */
- active_sensors = __uam_get_active_sesors(UAM_DETECT_ABSENCE);
- UAM_DBG("sensors: 0x%8.8X, Active sensors: 0x%8.8X",
- sensors, active_sensors);
-
- /* Update monitor info for application */
- monitor->sensors &= ~sensors;
- if (0 == monitor->sensors) {
- /*
- * App requested to stop monitoring for all of its active sensors,
- * remove its monitor info from list.
- */
- monitors = g_slist_remove(monitors, monitor);
- g_free(monitor->name);
- g_free(monitor);
- }
- /* Find sensors which are already monitoring */
- remaining_sensors = __uam_get_active_sesors(UAM_DETECT_ABSENCE);
- UAM_DBG("Remaining sensors: 0x%8.8X", remaining_sensors);
-
- if (active_sensors == remaining_sensors) {
- UAM_INFO("NO need to stop monitoring");
- return UAM_ERROR_NONE;
- }
-
- /* Stop monitoring only for sensors which aren't required anymore */
- sensors = (active_sensors & ~remaining_sensors);
- ret = _uam_pm_stop_detection(sensors, UAM_DETECT_ABSENCE);
- if (UAM_ERROR_NONE != ret)
- UAM_ERR("Failed with error: %s (0x%4.4X)",
- _uam_manager_error_to_str(ret), ret);
+ ret = __uam_core_stop_detection(UAM_DETECT_ABSENCE, sender, sensors);
FUNC_EXIT;
- return UAM_ERROR_NONE;
+ return ret;
}
static void __uam_core_add_dev_to_db(uam_db_user_info_t *user, const uam_device_info_t *dev_info)