summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Chaprana <n.chaprana@samsung.com>2019-07-19 17:08:33 +0530
committersaerome.kim <saerome.kim@samsung.com>2019-07-23 10:57:15 +0900
commit69815930ff0cfabcd49e20b76c9621a3a0387eba (patch)
treeb7f870defce68d2f774d8c454890a33bd13a2a5f
parentbca05cc06f23cda183d9df5e2a0de3803aa80677 (diff)
downloaduser-awareness-69815930ff0cfabcd49e20b76c9621a3a0387eba.tar.gz
user-awareness-69815930ff0cfabcd49e20b76c9621a3a0387eba.tar.bz2
user-awareness-69815930ff0cfabcd49e20b76c9621a3a0387eba.zip
Add ua_user_get_last_presence() API for getting last presence timestamp.
Change-Id: I7432790b93b280623c6cf01e688230b27625fab4 Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
-rw-r--r--include/user-awareness-private.h22
-rw-r--r--include/user-awareness.h19
-rw-r--r--src/user-awareness-event-handler.c10
-rw-r--r--src/user-awareness-monitors.c21
-rw-r--r--src/user-awareness-users.c35
-rw-r--r--test/uat-users.c6
6 files changed, 100 insertions, 13 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h
index dfa9f77..a858a7a 100644
--- a/include/user-awareness-private.h
+++ b/include/user-awareness-private.h
@@ -198,6 +198,7 @@ typedef struct {
gboolean isadded; /**< Is the user addition completed? */
gboolean default_user; /**< Is it a default user? */
gboolean create_by_app; /**< Did app add this user information? */
+ long last_presence_timestamp; /**< timestamp of last presence */
} ua_user_info_s;
/**
@@ -281,8 +282,9 @@ void _ua_monitor_handle_scan_complete(int result);
* @pre
* @post
*/
-void _ua_monitor_handle_user_presence_detected(
- unsigned int bitmask, char *service, char *account);
+void _ua_monitor_handle_user_presence_detected(unsigned int bitmask,
+ char *service, char *account,
+ long timestamp);
/**
* @brief Stops monitoring detection.
@@ -583,6 +585,22 @@ int _ua_intr_get_default_user(void);
ua_user_h _ua_get_user_handle_by_account(const char *account);
/**
+ * @brief set last presence timestamp in user handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] user_handle User handle.
+ * @param[in] timestamp The timestamp to be updated in user handle.
+ *
+ * @return not null on success, otherwise error
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+void _ua_set_user_last_presence_timestamp(ua_user_h user_handle,
+ long timestamp);
+
+/**
* @brief Checks whether a device exists in device list.
* @since_tizen 5.5
*
diff --git a/include/user-awareness.h b/include/user-awareness.h
index 69cbeb7..8c409c4 100644
--- a/include/user-awareness.h
+++ b/include/user-awareness.h
@@ -1274,6 +1274,25 @@ int ua_user_get_name(
/**
* @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets last presence timestamp info for user handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] user_handle The user handle.
+ * @param[out] timestamp The last presence timestamp information for UA user.
+ *
+ * @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_user_get_last_presence(ua_user_h user_handle, long *timestamp);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
* @brief Gets user handle by account.
* @since_tizen 5.5
*
diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c
index ff7d922..1b87e8c 100644
--- a/src/user-awareness-event-handler.c
+++ b/src/user-awareness-event-handler.c
@@ -48,9 +48,11 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u
ret_if(NULL == event_data);
ret_if(NULL == event_data->service);
ret_if(NULL == event_data->account);
+ ret_if(0 == event_data->timestamp);
_ua_monitor_handle_user_presence_detected(
- event_data->sensor_bitmask, event_data->service, event_data->account);
+ event_data->sensor_bitmask, event_data->service,
+ event_data->account, event_data->timestamp);
break;
}
@@ -63,7 +65,8 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u
ret_if(NULL == event_data->account);
_ua_monitor_handle_user_absence_detected(
- event_data->sensor_bitmask, event_data->service, event_data->account);
+ event_data->sensor_bitmask, event_data->service,
+ event_data->account);
break;
}
@@ -72,7 +75,8 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u
ret_if(NULL == sensor_bitmask);
- _ua_monitor_handle_user_presence_detected(*sensor_bitmask, NULL, NULL);
+ _ua_monitor_handle_user_presence_detected(*sensor_bitmask, NULL,
+ NULL, 0);
break;
}
case UAM_EVENT_ABSENCE_DETECTED: {
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index 76a7f26..1d8a780 100644
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -857,7 +857,9 @@ static ua_user_state_info_s* __ua_monitor_user_state_create(char *account)
return user_state;
}
-static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bitmask, char *account)
+static void __ua_sensor_presence_detected(ua_monitor_s *monitor,
+ unsigned int bitmask, char *account,
+ long timestamp)
{
FUNC_ENTRY;
@@ -888,16 +890,17 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bi
monitor->user_state = g_slist_append(monitor->user_state, user_state);
}
- if (user_state->sensor_bitmask == 0 && monitor->presence_user_cb.callback
- && monitor->presence_detection_started) {
- ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
+ ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account);
- if (user_handle)
- ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
+ if (user_handle && user_state->sensor_bitmask == 0 &&
+ monitor->presence_user_cb.callback && monitor->presence_detection_started) {
+
+ ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
UA_ERROR_NONE, monitor, user_handle,
monitor->presence_user_cb.user_data);
}
+ _ua_set_user_last_presence_timestamp(user_handle, timestamp);
user_state->sensor_bitmask |= bitmask;
}
@@ -1117,7 +1120,8 @@ void _ua_monitor_handle_scan_complete(int result)
FUNC_EXIT;
}
-void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, char *service, char *account)
+void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, char *service,
+ char *account, long timestamp)
{
FUNC_ENTRY;
GSList *l;
@@ -1133,7 +1137,8 @@ void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, char *servi
if (!service || !g_strcmp0(service, monitor->service)) {
/* Presence detection ongoing */
- __ua_sensor_presence_detected(monitor, bitmask, account);
+ __ua_sensor_presence_detected(monitor, bitmask, account,
+ timestamp);
}
}
diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c
index e606e87..39c6162 100644
--- a/src/user-awareness-users.c
+++ b/src/user-awareness-users.c
@@ -575,6 +575,23 @@ ua_user_h _ua_get_user_handle_by_account(const char *account)
FUNC_EXIT;
return NULL;
}
+
+void _ua_set_user_last_presence_timestamp(ua_user_h user_handle,
+ long timestamp)
+{
+ FUNC_ENTRY;
+ ua_user_info_s *user = (ua_user_info_s *)user_handle;
+
+ if (user == NULL) {
+ UA_INFO("user_handle is NULL");
+ FUNC_EXIT;
+ return;
+ }
+
+ user->last_presence_timestamp = timestamp;
+
+ FUNC_EXIT;
+}
/* LCOV_EXCL_STOP */
int ua_user_create(ua_user_h *user_handle)
@@ -593,6 +610,7 @@ int ua_user_create(ua_user_h *user_handle)
}
user->state = UA_PRSENCE_STATE_INVALID;
user->account = NULL;
+ user->last_presence_timestamp = 0;
/* Add monitor to list of monitors */
*user_handle = (ua_user_h)user;
@@ -792,6 +810,23 @@ int ua_user_get_name(
return UA_ERROR_NONE;
}
+int ua_user_get_last_presence(ua_user_h user_handle, long *timestamp)
+{
+ FUNC_ENTRY;
+ ua_user_info_s *user = (ua_user_info_s *)user_handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(user_handle);
+ UA_VALIDATE_HANDLE(user_handle, ua_users_list);
+ UA_VALIDATE_INPUT_PARAMETER(timestamp);
+
+ /* update user list from uam_api */
+
+ *timestamp = user->last_presence_timestamp;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
int ua_user_set_name(
ua_device_h handle,
const char *name)
diff --git a/test/uat-users.c b/test/uat-users.c
index 235a60c..6d3b8c8 100644
--- a/test/uat-users.c
+++ b/test/uat-users.c
@@ -89,6 +89,7 @@ static bool __foreach_registered_user_cb(
char *account = NULL;
char *name = NULL;
+ long timestamp = 0;
if (user_handle) {
@@ -101,11 +102,16 @@ static bool __foreach_registered_user_cb(
msgb("User account info %s", account);
g_free(account);
}
+
ret = ua_user_get_name(user_handle, &name);
if (UA_ERROR_NONE == ret) {
msgb("User Name : %s", name);
g_free(name);
}
+
+ ret = ua_user_get_last_presence(user_handle, &timestamp);
+ if (UA_ERROR_NONE == ret)
+ msgb("last present at %ld", timestamp);
}
return true;