* @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #UA_ERROR_NOT_INITIALIZED Not initialized yet
*/
-int ua_location_get_position(ua_location_h location_handle, int *x, int *y, int *z);
+int ua_location_get_position(ua_location_h location_handle,
+ int *x, int *y, int *z);
+
+/**
+ * @internal
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sets the location period.
+ * @since_tizen 6.5
+ *
+ * @param[in] monitor handle
+ * @param[out] location period
+ *
+ * @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_INITIALIZED Not initialized yet
+ */
+int ua_monitor_set_location_period(
+ ua_monitor_h monitor_handle, unsigned int location_period);
/* Deprecated API's */
*/
#define UA_BLE_PAYLOAD_DEVICE_UID_MAX_LEN 17
+/**
+ * @brief Default location callback period (in msec).
+ * @since_tizen 6.5
+ */
+#define UA_LOCATION_PERIOD_DEFAULT 1000
+
/**
* @brief Wifi location sensor.
* @since_tizen 6.5
unsigned int location_detected_bitmask; /**< Detected Location bitmask */
gboolean location_detection_started; /**< Is location detection started */
ua_location_detected_cb location_cb; /**< Location detection callback */
+ unsigned int location_period; /**< Location callback period */
} ua_monitor_s;
/**
* @since_tizen 6.5
*/
typedef struct {
+ ua_monitor_h monitor_handle; /**< Monitor handle */
+ ua_service_h service_handle; /**< Service handle */
+ ua_monitor_h device_handle; /**< Device handle */
+ ua_monitor_h user_handle; /**< User handle */
+ ua_sensor_h sensor_handle; /**< Sensor handle */
+ ua_sensor_type_e bitmask; /**< Sensor bitmask */
unsigned int distance; /**< Device distance in mm */
unsigned int x; /**< Device x coordinate */
unsigned int y; /**< Device y coordinate */
*/
void _ua_clear_sensor_list(void);
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Updates location info.
+ * @since_tizen 6.5
+ *
+ * @param[in] location_info The location information to be updated.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+int _ua_update_location_info(ua_location_info_s *location_info);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sends location callback.
+ * @since_tizen 6.5
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+gboolean _ua_monitor_send_location_cb(gpointer data);
+
#ifdef __cplusplus
}
#endif
static GSList *ua_monitor_list;
static ua_monitor_h scanning_monitor = NULL;
+static guint location_cb_timer = 0;
static gboolean __ua_monitor_is_only_env_in_conditions(
ua_monitor_s *monitor)
FUNC_EXIT;
}
-static void __ua_monitor_send_location_cb(ua_monitor_s *monitor,
- ua_device_h device_handle, ua_sensor_info_s *sensor_info,
- char* account, ua_location_info_s *location_info)
+static void __ua_sensor_location_detected(ua_monitor_s *monitor,
+ ua_sensor_info_s *sensor_info, char *account,
+ ua_location_info_s *location_info, char *device_id)
{
FUNC_ENTRY;
- ua_sensor_type_e bitmask = sensor_info->bitmask;
+
+ int ret = UA_ERROR_NONE;
+ ua_device_h device_handle = NULL;
ua_sensor_h sensor_handle;
ua_service_info_s *service = NULL;
ua_service_h service_handle = NULL;
ua_service_h user_handle = NULL;
- ua_location_h location_handle = NULL;
- int ret;
+ ua_sensor_type_e bitmask = sensor_info->bitmask;
+
+ ret_if(NULL == monitor);
+
+ /* Get device handle */
+ ret = ua_device_get_by_device_id(device_id,
+ _ua_sensor_to_dev_type(bitmask), &device_handle);
+ UA_INFO("ua_device_get_by_device_id returned %s",
+ _ua_get_error_string(ret));
/* Get sensor handle */
ret = _ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle);
- if (UA_ERROR_NONE != ret) {
+ if (UA_ERROR_NONE != ret)
UA_INFO("_ua_sensor_get_by_sensor_info returned %s",
_ua_get_error_string(ret));
- }
/* Get service handle */
service = __ua_get_service_from_list(monitor->service);
if (account)
user_handle = _ua_get_user_handle_by_account(account);
- /* Get location handle */
- location_handle = (ua_location_h)location_info;
-
- /* Send location callback */
- monitor->location_cb(UA_ERROR_NONE, monitor,
- service_handle, bitmask, sensor_handle,
- device_handle, user_handle, location_handle,
- monitor->user_data);
-
- FUNC_EXIT;
- return;
-}
-
-static void __ua_sensor_location_detected(ua_monitor_s *monitor,
- ua_sensor_info_s *sensor_info, char *account,
- ua_location_info_s *location_info, char *device_id)
-{
- FUNC_ENTRY;
+ location_info->service_handle = service_handle;
+ location_info->bitmask = bitmask;
+ location_info->sensor_handle = sensor_handle;
+ location_info->device_handle = device_handle;
+ location_info->user_handle = user_handle;
+ location_info->monitor_handle = (ua_monitor_h *)monitor;
- int ret = UA_ERROR_NONE;
- ua_device_h device_handle = NULL;
- ua_sensor_type_e bitmask = sensor_info->bitmask;
-
- ret_if(NULL == monitor);
-
- if (!monitor->location_detection_started) {
- FUNC_EXIT;
- return;
- }
-
- /* Get device */
- ret = ua_device_get_by_device_id(device_id,
- _ua_sensor_to_dev_type(bitmask), &device_handle);
- UA_INFO("ua_device_get_by_device_id returned %s",
+ /* Update location */
+ ret = _ua_update_location_info(location_info);
+ if (UA_ERROR_NONE != ret) {
+ UA_INFO("_ua_update_location_info returned %s",
_ua_get_error_string(ret));
-
- __ua_monitor_send_location_cb(monitor, device_handle,
- sensor_info, account, location_info);
+ }
+ UA_INFO("location updated");
FUNC_EXIT;
}
monitor->presence_bitmask_or = (available_sensors & UA_SENSOR_BLE) | (available_sensors & UA_SENSOR_WIFI);
monitor->absence_bitmask_and = (available_sensors & UA_SENSOR_BLE) | (available_sensors & UA_SENSOR_WIFI);
monitor->absence_bitmask_or = 0;
+ monitor->location_period = UA_LOCATION_PERIOD_DEFAULT;
*handle = (ua_monitor_h)monitor;
_uam_get_available_sensors(&available_sensors)))
UA_WARN("_uam_get_available_sensors failed");
+ UA_INFO("Starting location detection on %s service",
+ monitor->service);
ret = __ua_start_monitoring(monitor->sensor_bitmask,
monitor->service, detect);
if (UA_ERROR_NONE != ret) {
g_free(service);
+ /* Start timer */
+ if (0 == location_cb_timer) {
+ UA_INFO("Location detection started, start timer of %d seconds",
+ (monitor->location_period)/1000);
+ location_cb_timer = g_timeout_add_seconds(
+ (monitor->location_period)/1000,
+ _ua_monitor_send_location_cb, service_handle);
+ }
+
FUNC_EXIT;
return UA_ERROR_NONE;
}
monitor->location_detection_started = FALSE;
monitor->location_detected_bitmask = 0;
+ if (location_cb_timer)
+ g_source_remove(location_cb_timer);
+
FUNC_EXIT;
return UA_ERROR_NONE;
}
}
+int ua_monitor_set_location_period(
+ ua_monitor_h handle,
+ unsigned int location_period)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+
+ UA_CHECK_INIT_STATUS();
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->location_period = location_period;
+ UA_INFO("monitor location period set to %d milliseconds",
+ monitor->location_period);
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+
int ua_monitor_set_brightness_threshold(ua_monitor_h handle,
int presence_threshold, int absence_threshold)
{
#include <user-awareness-private.h>
static GSList *ua_sensors_list = NULL; /* ua_sensor_info_s */
+static GSList *ua_location_list = NULL; /* ua_location_info_s */
static ua_feature_table_t feature_table[] = {
{"tizen.org/feature/user_awareness", FALSE, FALSE}, /* UA_FEATURE_COMMON */
return location_info;
}
+static ua_location_info_s *__ua_get_location_info_from_list(
+ ua_service_h svc_h, ua_device_h dev_h)
+{
+ GSList *l;
+ ua_location_info_s *location;
+
+ for (l = ua_location_list; NULL != l; l = g_slist_next(l)) {
+ location = (ua_location_info_s *)l->data;
+
+ if (svc_h == location->service_handle &&
+ dev_h == location->device_handle) {
+ UA_INFO("Location info found for service and device");
+ return location;
+ }
+ }
+
+ return NULL;
+}
+
+static int __ua_update_location_info(
+ ua_location_info_s *location,
+ ua_location_info_s *info)
+{
+ FUNC_ENTRY;
+
+ UA_VALIDATE_INPUT_PARAMETER(location);
+ UA_VALIDATE_INPUT_PARAMETER(info);
+
+ location->distance = info->distance;
+ location->x = info->x;
+ location->y = info->y;
+ location->z = info->z;
+ location->bitmask = info->bitmask;
+ location->service_handle = info->service_handle;
+ location->device_handle = info->device_handle;
+ location->user_handle = info->user_handle;
+ location->monitor_handle = info->monitor_handle;
+ location->sensor_handle = info->sensor_handle;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int _ua_update_location_info(
+ ua_location_info_s *info)
+{
+ FUNC_ENTRY;
+ int ret = UA_ERROR_NONE;
+ ua_location_info_s *location;
+
+ UA_VALIDATE_INPUT_PARAMETER(info);
+
+ location = __ua_get_location_info_from_list(
+ info->service_handle, info->device_handle);
+
+ if (location) {
+ ret = __ua_update_location_info(location, info);
+ goto done;
+ }
+
+ location = __ua_allocate_ua_location_info();
+ if (!location)
+ return UA_ERROR_OUT_OF_MEMORY;
+
+ ret = __ua_update_location_info(location, info);
+ ua_location_list = g_slist_append(ua_location_list, location);
+
+done:
+ FUNC_EXIT;
+ return ret;
+}
+
+static void __send_location_cb(gpointer data, gpointer user_data)
+{
+ FUNC_ENTRY;
+ ua_location_h location_handle = NULL;
+ ua_location_info_s *location_info = data;
+ ua_service_h service_handle = user_data;
+
+ ret_if(!location_info);
+ ret_if(!service_handle);
+
+ ua_monitor_s *monitor = (ua_monitor_s *)(location_info->monitor_handle);
+
+ if (!monitor || !(monitor->location_cb))
+ return;
+
+ if (!(location_info->service_handle == service_handle))
+ return;
+
+ /* Get location handle */
+ location_handle = (ua_location_h)location_info;
+
+ /* Send location callback */
+ monitor->location_cb(UA_ERROR_NONE, monitor,
+ location_info->service_handle, location_info->bitmask,
+ location_info->sensor_handle, location_info->device_handle,
+ location_info->user_handle, location_handle,
+ monitor->user_data);
+
+ return;
+}
+
+gboolean _ua_monitor_send_location_cb(gpointer data)
+{
+ FUNC_ENTRY;
+
+ g_slist_foreach(ua_location_list, __send_location_cb, data);
+
+ FUNC_EXIT;
+ return TRUE;
+}
check_if(NULL == g_ua_mon_h);
+ ret = ua_monitor_set_location_period(g_ua_mon_h, 1000);
+ msg(" - ua_monitor_set_location_period() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+
ret = ua_monitor_start_location_detection(g_ua_mon_h,
(g_service_str[0] == '\0' ? NULL : g_service_h),
_sensor_location_detected_cb, g_ua_mon_h);