- Problem: real-time timestamp causes various problems.
- Cause: If the time zone is changed or the system time is initialized,
the wrong timestamp may be generated.
- Solution:
1. Change to use the monotonic timer when creating a timestamp.
2. Add new plugin API that enables the BLE plugin can save real-time
timestamp.
Change-Id: I24c1dbbec39417f6f13ec87dfff8c3239572722c
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
Name: ua-manager
Summary: User awareness manager
-Version: 0.12.18
+Version: 0.12.19
Release: 1
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
size_t _uam_get_file_size(const char* filename);
+unsigned long long _uam_get_timestamp(void);
+
#ifdef __cplusplus
}
#endif
void _uam_core_handle_status_changed(unsigned int sensor, void *info);
+void __send_sensor_absence_event(uam_sensor_info_s *sensor_info, unsigned int sensor);
+
#ifdef __cplusplus
}
#endif
#include <ua-plugin.h>
#include <ua-manager-core.h>
+#include <ua-manager-database.h>
#include <ua-plugin-manager.h>
#include "ua-pm-util.h"
FUNC_EXIT;
}
+void ble_device_update_timestamp_callback(
+ unsigned long long timestamp, uas_device_info_t *device)
+{
+ FUNC_ENTRY;
+
+ int ret;
+ uam_device_info_s *dev_info;
+
+ ret_if(NULL == device);
+
+ dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device);
+ ret_if(NULL == dev_info);
+
+ dev_info->type = UAM_TECH_TYPE_BLE;
+
+ ret = __uam_db_begin_transaction();
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("_uam_device_db_update_device_timestamp failed");
+ g_free(dev_info);
+ return;
+ }
+
+ /* Update database (presence state & timestamp) */
+ ret = _uam_device_db_update_device_timestamp(dev_info->device_id,
+ dev_info->type, dev_info->mac, timestamp);
+
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("_uam_device_db_update_device_timestamp failed");
+ __uam_db_end_transaction(0);
+ }
+
+ __uam_db_end_transaction(1);
+ g_free(dev_info);
+
+ FUNC_EXIT;
+}
+
uas_callbacks_t ble_cbs = {
.state_changed_cb = ble_state_changed_callback,
.detection_state_cb = ble_detection_state_changed_cb,
.detected_cb = ble_lpm_detection_callback,
.device_detected_cb = ble_device_detection_callback,
.device_added_cb = ble_device_added_callback,
- .active_scan_cb = NULL
+ .device_active_scan_cb = NULL,
+ .device_update_timestamp_cb = ble_device_update_timestamp_callback
};
.detected_cb = light_detection_callback,
.device_detected_cb = NULL,
.device_added_cb = NULL,
- .active_scan_cb = NULL,
+ .device_active_scan_cb = NULL,
+ .device_update_timestamp_cb = NULL
};
.detected_cb = motion_detection_callback,
.device_detected_cb = NULL,
.device_added_cb = NULL,
- .active_scan_cb = NULL,
+ .device_active_scan_cb = NULL,
+ .device_update_timestamp_cb = NULL
};
.detected_cb = wifi_lpm_detection_callback,
.device_detected_cb = wifi_device_detection_callback,
.device_added_cb = wifi_device_added_callback,
- .active_scan_cb = wifi_active_scan_callback
+ .device_active_scan_cb = wifi_active_scan_callback,
+ .device_update_timestamp_cb = NULL
};
*/
#include <sys/stat.h>
+#include <sys/time.h>
#include "ua-api.h"
#include "ua-plugin.h"
#include "ua-internal.h"
return size;
}
+
+unsigned long long _uam_get_timestamp(void)
+{
+ int ret;
+ struct timespec t;
+ ret = clock_gettime(CLOCK_MONOTONIC, &t);
+ if (-1 == ret) {
+ UAM_ERR("Failed to call clock_gettime [%d]", ret);
+ return 0;
+ }
+ return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
int user_id, const uam_device_info_s *dev_info)
{
FUNC_ENTRY;
+
GSList *l;
int ret = UAM_ERROR_NONE;
- uam_db_user_info_t *user = NULL;
GSList *svc_list = NULL;
- long timestamp;
+ uam_db_user_info_t *user = NULL;
+ unsigned long long timestamp;
UAM_INFO("[%d]", user_id);
svc_list = g_slist_append(svc_list, service);
}
- timestamp = time(NULL);
- if (-1 == timestamp) {
- UAM_ERR("time() return -1");
- timestamp = 0;
- }
+ timestamp = _uam_get_timestamp();
__uam_core_add_dev_to_list(user, dev_info,
- UAM_PRESENCE_STATE_PRESENT, (unsigned long long)timestamp, svc_list);
+ UAM_PRESENCE_STATE_PRESENT, timestamp, svc_list);
retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_DB_FAILED);
/* Add device to database */
char *device_id)
{
FUNC_ENTRY;
+
GSList *l;
- long timestamp;
uam_db_user_info_t *user;
uam_svc_dev_info_t *svc_dev = NULL;
if (UAM_DETECT_PRESENCE != mon->mode)
continue;
- timestamp =time(NULL);
- if (-1 == timestamp) {
- UAM_ERR("time() return -1");
- user->timestamp = 0;
- } else
- user->timestamp = (unsigned long long)timestamp;
+ user->timestamp = _uam_get_timestamp();
UAM_INFO("sensor [%d]", sensor);
_uam_manager_send_event(mon->name,
int user_id, void *info)
{
FUNC_ENTRY;
- long timestamp;
int ret = UAM_ERROR_NONE;
GSList *l;
tech = l->data;
tech->presence_state = UAM_PRESENCE_STATE_PRESENT;
-
- timestamp = time(NULL);
- if (-1 == timestamp)
- UAM_ERR("time() return -1");
- else
- tech->timestamp = (unsigned long long)timestamp;
+ tech->timestamp = _uam_get_timestamp();
retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_INVALID_PARAMETER);
/* Check if IP address was updated then update in DB */
typedef void (*uas_device_active_scan_callback)(
uas_active_scan_event_e event, const uas_device_info_t *device);
+/*
+ * Callback to be invoked in response to search_active_devices() API
+ *
+ * [Param] timestamp - Timestamp to update.
+ * [Param] device - Device information to update.
+ */
+typedef void (*uas_device_update_timestamp_callback)(unsigned long long timestamp,
+ uas_device_info_t *device);
+
+
/* UA plug-in callback structure */
typedef struct {
uas_state_changed_callback state_changed_cb; /**< 0:Not ready 1:Ready */
uas_detection_callback detected_cb; /**< For environmental sensors */
uas_device_detection_callback device_detected_cb; /**< For connectivity sensors */
uas_device_added_callback device_added_cb; /**< For connectivity sensors */
- uas_device_active_scan_callback active_scan_cb; /**< For connectivity sensors */
+ uas_device_active_scan_callback device_active_scan_cb; /**< For connectivity sensors */
+ uas_device_update_timestamp_callback device_update_timestamp_cb; /**< Update device timestamp */
} uas_callbacks_t;
typedef struct {