Sending timestamp for Presence and Absence event of user. 17/210517/1
authorNishant Chaprana <n.chaprana@samsung.com>
Fri, 19 Jul 2019 11:39:32 +0000 (17:09 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 22 Jul 2019 05:31:25 +0000 (14:31 +0900)
Change-Id: I1832053850e9afd8f84f05ee93093138bc1c0f72
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/ua-api.h
ua-api/src/ua-event-handler.c
ua-daemon/include/ua-manager-core.h
ua-daemon/include/ua-manager-database.h
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-device-db.c

index a26c026..0b414ae 100644 (file)
@@ -468,6 +468,7 @@ typedef struct {
        unsigned int sensor_bitmask; /**< Detecting sensor's bitmask */
        char account[UAM_USER_ACCOUNT_MAX_STRING_LEN]; /**< User account */
        char service[UAM_SERVICE_MAX_STRING_LEN]; /**< Service name */
+       long timestamp; /**< Timestamp of detection */
 } uam_detection_event_data_s;
 
 /**
index aa041c2..74b5367 100644 (file)
@@ -76,8 +76,10 @@ static void __uam_event_handler(GDBusConnection *connection,
                unsigned int sensor_bitmask;
                char *account = NULL;
                char *service = NULL;
+               long timestamp;
 
-               g_variant_get(parameters, "(u&s&s)", &sensor_bitmask, &account, &service);
+               g_variant_get(parameters, "(u&s&sx)", &sensor_bitmask, &account,
+                             &service, &timestamp);
 
                UAM_DBG("Sensor: 0x%8.8X, User: %s", sensor_bitmask, account);
                event = UAM_EVENT_USER_PRESENCE_DETECTED;
@@ -85,6 +87,7 @@ static void __uam_event_handler(GDBusConnection *connection,
                g_strlcpy(event_data.account, account,
                                UAM_USER_ACCOUNT_MAX_STRING_LEN);
                g_strlcpy(event_data.service, service, UAM_SERVICE_MAX_STRING_LEN);
+               event_data.timestamp = timestamp;
 
                __uam_send_event(event, result, &event_data,
                                event_info->cb, event_info->user_data);
@@ -93,8 +96,10 @@ static void __uam_event_handler(GDBusConnection *connection,
                unsigned int sensor_bitmask;
                char *account = NULL;
                char *service = NULL;
+               long timestamp;
 
-               g_variant_get(parameters, "(u&s&s)", &sensor_bitmask, &account, &service);
+               g_variant_get(parameters, "(u&s&sx)", &sensor_bitmask, &account,
+                             &service, &timestamp);
 
                UAM_DBG("Sensor: 0x%8.8X, User: %s", sensor_bitmask, account);
                event = UAM_EVENT_USER_ABSENCE_DETECTED;
@@ -102,6 +107,7 @@ static void __uam_event_handler(GDBusConnection *connection,
                g_strlcpy(event_data.account, account,
                                UAM_USER_ACCOUNT_MAX_STRING_LEN);
                g_strlcpy(event_data.service, service, UAM_SERVICE_MAX_STRING_LEN);
+               event_data.timestamp = timestamp;
 
                __uam_send_event(event, result, &event_data,
                                event_info->cb, event_info->user_data);
index 7a2b8ac..fdd2291 100644 (file)
@@ -61,7 +61,7 @@ typedef struct {
        uam_tech_type_e tech_type;
        GSList *addresses;
        int presence_state;
-       long long int timestamp;
+       long timestamp;
        struct uam_db_device_info *device;
        GSList *svc_list;
 } uam_db_tech_info_t;
@@ -72,7 +72,7 @@ typedef struct uam_db_device_info {
        GSList *tech_list;
        unsigned int supported_techs;
 //     int presence_state;
-//     long long int timestamp;
+//     long timestamp;
        struct uam_db_user_info *user;
 } uam_db_device_info_t;
 
@@ -82,7 +82,7 @@ typedef struct uam_db_user_info {
        char *account;
        GSList *devices;
 //     int presence_state;
-//     long long int timestamp;
+       long timestamp;
 } uam_db_user_info_t;
 
 
index 0fb8fb3..c86384e 100644 (file)
@@ -54,7 +54,7 @@ typedef struct {
        int user_id;
        uam_device_info_s dev_info;
        int presence_state;
-       long long timestamp;
+       long timestamp;
 } db_device_info_t;
 
 /* db init/deinit */
@@ -73,11 +73,11 @@ int _ua_device_db_delete_device_info(const char *device_id, int tech_type, const
 
 /* insert */
 int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_info,
-               int presence_state, long long timestamp);
+               int presence_state, long timestamp);
 
 /* update */
-int _ua_device_db_update_device_timestamp(char *device_id, int tech_type, char *address,
-               unsigned long long timestamp);
+int _ua_device_db_update_device_timestamp(char *device_id, int tech_type,
+                                         char *address, long timestamp);
 int _ua_device_db_update_device_presence(char *device_id, int tech_type, char *address,
                int presence_state);
 int _ua_device_db_update_device_ip_address(char *device_id, int tech_type, char *address,
index 3c71d63..6aee071 100644 (file)
@@ -2171,13 +2171,17 @@ void __send_user_presence_event(uam_db_tech_info_t *tech, unsigned int sensor)
                        if (UAM_DETECT_PRESENCE != mon->mode)
                                continue;
 
+                       user->timestamp = (long) time(NULL);
                        _uam_manager_send_event(mon->name,
                                        UAM_EVENT_USER_PRESENCE_DETECTED,
-                                       g_variant_new("(uss)", sensor,
-                                               user->account, svc->name));
+                                       g_variant_new("(ussx)", sensor,
+                                               user->account, svc->name,
+                                               user->timestamp));
                        UAM_DBG("Sent UAM_EVENT_USER_PRESENCE_DETECTED to %s"
-                                       " for 0x%8.8X, User: %s Service: %s",
-                                       mon->name, sensor, user->account, svc->name);
+                                       " for 0x%8.8X, User: %s Service: %s"
+                                       " timestamp [%ld]",
+                                       mon->name, sensor, user->account,
+                                       svc->name, user->timestamp);
                }
        }
 
@@ -2357,13 +2361,17 @@ static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
                                if (!user)
                                        continue;
 
+                               user->timestamp = (long) time(NULL);
                                _uam_manager_send_event(mon->name,
                                                UAM_EVENT_USER_ABSENCE_DETECTED,
-                                               g_variant_new("(uss)", sensor,
-                                                       user->account, svc->name));
+                                               g_variant_new("(ussx)", sensor,
+                                                       user->account, svc->name,
+                                                       user->timestamp));
                                UAM_DBG("Sent UAM_EVENT_USER_ABSENCE_DETECTED to %s"
-                                               " for 0x%8.8X, User: %s Service: %s",
-                                               mon->name, sensor, user->account, svc->name);
+                                               " for 0x%8.8X, User: %s Service: %s"
+                                               " timestamp [%ld]",
+                                               mon->name, sensor, user->account,
+                                               svc->name, user->timestamp);
                        }
                }
 
index c78db5d..108ea4c 100644 (file)
@@ -484,8 +484,8 @@ handle_error:
        return error_code;
 }
 
-int _ua_device_db_update_device_timestamp(char *device_id, int tech_type, char *address,
-               unsigned long long timestamp)
+int _ua_device_db_update_device_timestamp(char *device_id, int tech_type,
+                                         char *address, long timestamp)
 {
        int error_code = UAM_ERROR_NONE;
        sqlite3_stmt *stmt = update_timestamp;
@@ -506,7 +506,7 @@ int _ua_device_db_update_device_timestamp(char *device_id, int tech_type, char *
                goto handle_error;
        }
 
-       UAM_DBG("Device timestamp updated [%lld]", timestamp);
+       UAM_DBG("Device timestamp updated [%ld]", timestamp);
 
 handle_error:
        sqlite3_reset(stmt);
@@ -514,7 +514,7 @@ handle_error:
 }
 
 int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_info,
-               int presence_state, long long timestamp)
+                                    int presence_state, long timestamp)
 {
        FUNC_ENTRY;
        int error_code = UAM_ERROR_NONE;
@@ -522,7 +522,7 @@ int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_i
 
        retv_if(NULL == dev_info, UAM_ERROR_INVALID_PARAMETER);
 
-       UAM_INFO("%s-%d-%s-%s-%lld-%d-%d-%d", dev_info->device_id,
+       UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d", dev_info->device_id,
                        dev_info->type, dev_info->mac, dev_info->ipv4_addr,
                        timestamp, presence_state, dev_info->operating_system, user_id);
 
@@ -608,7 +608,7 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address,
                info->dev_info.operating_system = sqlite3_column_int(stmt, 6);
                info->user_id = sqlite3_column_int(stmt, 7);
 
-               UAM_INFO("%s-%d-%s-%s-%lld-%d-%d-%d", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac,
+               UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac,
                                info->dev_info.ipv4_addr, info->timestamp, info->presence_state,
                                info->dev_info.operating_system, info->user_id);
        }
@@ -684,7 +684,7 @@ GSList *_ua_device_db_get_all_devices(void)
                        info->dev_info.operating_system = sqlite3_column_int(stmt, 6);
                        info->user_id = sqlite3_column_int(stmt, 7);
 
-                       UAM_INFO("%s-%d-%s-%s-%lld-%d-%d-%d", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac,
+                       UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac,
                                        info->dev_info.ipv4_addr, info->timestamp, info->presence_state,
                                        info->dev_info.operating_system, info->user_id);