diff options
author | Abhay Agarwal <ay.agarwal@samsung.com> | 2021-01-22 09:57:48 +0530 |
---|---|---|
committer | Abhay Agarwal <ay.agarwal@samsung.com> | 2021-01-27 10:03:59 +0530 |
commit | 3d0dceb08a27b8837427c9e8e5f4c751c344c0c4 (patch) | |
tree | 1817cf9dc7efc1decd367430d196484aad5954e9 | |
parent | 3861ad10d8debe36e97ef1a688791610397d49cc (diff) | |
download | user-awareness-3d0dceb08a27b8837427c9e8e5f4c751c344c0c4.tar.gz user-awareness-3d0dceb08a27b8837427c9e8e5f4c751c344c0c4.tar.bz2 user-awareness-3d0dceb08a27b8837427c9e8e5f4c751c344c0c4.zip |
Modify monitor API's
This patch modifies monitor based API's and callbacks
(renames/parameter modifications)
New API's to be used in place of deprecated API's
- ua_monitor_start_scan_devices()
=> ua_monitor_start_scan()
- ua_monitor_stop_scan_devices()
=> ua_monitor_stop_scan()
- Added service_handle in ua_presence_detected_cb
- Added service_handle in ua_absence_detected_cb
Change-Id: I603952908ce2d7ece527e0ee15cfb1aeca7945ea
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rwxr-xr-x | include/user-awareness.h | 22 | ||||
-rwxr-xr-x | src/user-awareness-monitors.c | 79 | ||||
-rwxr-xr-x | test/uat-common.h | 6 | ||||
-rwxr-xr-x | test/uat-detections.c | 44 |
4 files changed, 109 insertions, 42 deletions
diff --git a/include/user-awareness.h b/include/user-awareness.h index 5bc3987..e0eac15 100755 --- a/include/user-awareness.h +++ b/include/user-awareness.h @@ -328,13 +328,13 @@ typedef bool (*ua_monitor_foreach_sensor_cb)( * @param[in] handle The monitor handle * @param[in] device_handle The device handle to detected device's information. When scan * is complete, it is set to NULL. - * @param[in] user_data The user data passed in ua_monitor_start_scan_devices() + * @param[in] user_data The user data passed in ua_monitor_start_scan() * * @exception * @pre * @post * - * @see ua_monitor_start_scan_devices() + * @see ua_monitor_start_scan() */ typedef void (*ua_scan_completed_cb)( ua_active_scan_type_e type, @@ -359,6 +359,7 @@ typedef void (*ua_scan_completed_cb)( * @param[in] sensor Sensor type, In case monitor has more than one sensor and detection * mode is not #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to last sensor which * reported user presence before invoking callback. + * @param[in] service_handle The service handle with which presence detection start was invoked. * @param[in] device_handle The first device handle on which sensor is detected. * @param[in] sensor_handle The sensor handle for the detected sensor. * @param[in] user_data The user data passed in ua_monitor_start_presence_detection() @@ -373,6 +374,7 @@ typedef void (*ua_presence_detected_cb)( int result, ua_monitor_h handle, ua_sensor_e sensor, + ua_service_h service_handle, ua_device_h device_handle, ua_sensor_h sensor_handle, void *user_data); @@ -388,8 +390,9 @@ typedef void (*ua_presence_detected_cb)( * @remarks The @a sensor_handle can be used only in the callback. * * @param[in] result The result of the requested operation. - * @param[in] handle The monitor handle with which absence detection start was invoked. \n - * @param[in] sensor Sensor type by which absence was detected. \n + * @param[in] handle The monitor handle with which absence detection start was invoked. + * @param[in] service_handle The service handle with which absence detection start was invoked. + * @param[in] sensor Sensor type by which absence was detected. * In case monitor has more than one sensor and detection mode is not * #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to #UA_SENSOR_MAX before * invoking callback. @@ -405,6 +408,7 @@ typedef void (*ua_presence_detected_cb)( typedef void (*ua_absence_detected_cb)( int result, ua_monitor_h handle, + ua_service_h service_handle, ua_sensor_e sensor, ua_sensor_h sensor_handle, void *user_data); @@ -769,9 +773,9 @@ int ua_monitor_unset_sensor_status_cb( * * @see UA_SCAN_TIME_MULTIPLIER * @see ua_scan_completed_cb() - * @see ua_monitor_stop_scan_devices() + * @see ua_monitor_stop_scan() */ -int ua_monitor_start_scan_devices( +int ua_monitor_start_scan( ua_monitor_h handle, int scan_time_multiplier, ua_scan_completed_cb callback, @@ -779,7 +783,7 @@ int ua_monitor_start_scan_devices( /** * @ingroup CAPI_NETWORK_UA_MODULE - * @brief Stops ua_monitor_start_scan_devices(). + * @brief Stops ua_monitor_start_scan(). * @since_tizen 6.5 * * @param[in] monitor UA monitor's handle @@ -794,9 +798,9 @@ int ua_monitor_start_scan_devices( * @pre * @post * - * @see ua_monitor_start_scan_devices() + * @see ua_monitor_start_scan() */ -int ua_monitor_stop_scan_devices(ua_monitor_h monitor); +int ua_monitor_stop_scan(ua_monitor_h monitor); /** diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index b542588..466c3de 100755 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -406,17 +406,32 @@ static void __ua_send_presence_detection(char *svc_name) for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) { ua_monitor_s *monitor = l->data; + ua_service_info_s *service = NULL; + ua_service_h service_handle = NULL; if (!monitor || g_strcmp0(monitor->service, svc_name)) continue; if (monitor->presence_mode != UA_DETECT_MODE_ANY_SENSOR) { - UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->presence_detected_bitmask: 0x%8.8X", - monitor->sensor_bitmask, monitor->presence_detected_bitmask); - if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) { - if (monitor->presence_cb) + /* Send callbacks for 'ALL' mode */ + UA_INFO("monitor->sensor_bitmask: 0x%8.8X, " \ + "monitor->presence_detected_bitmask: 0x%8.8X", + monitor->sensor_bitmask, + monitor->presence_detected_bitmask); + + if (monitor->sensor_bitmask + == monitor->presence_detected_bitmask) { + if (monitor->presence_cb) { + service = __ua_get_service_from_list( + monitor->service); + if (service) + service_handle = service->service_handle; + monitor->presence_cb(UA_ERROR_NONE, monitor, - monitor->presence_detected_bitmask, NULL, NULL, monitor->user_data); + monitor->presence_detected_bitmask, + service_handle, NULL, NULL, + monitor->user_data); + } } } @@ -446,6 +461,8 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, FUNC_ENTRY; ua_sensor_e bitmask = sensor_info->bitmask; ua_sensor_h sensor_handle; + ua_service_info_s *service = NULL; + ua_service_h service_handle = NULL; int ret; ret = ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle); @@ -465,9 +482,12 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, UA_INFO("UA_DETECT_MODE_ALL_SENSOR [%d][%d]", bitmask, monitor->presence_detected_bitmask); - if (((bitmask == UA_SENSOR_BLE) && (monitor->sensor_bitmask & UA_SENSOR_WIFI)) - || ((bitmask == UA_SENSOR_WIFI) && (monitor->sensor_bitmask & UA_SENSOR_BLE))) - monitor->presence_detected_bitmask |= (UA_SENSOR_BLE | UA_SENSOR_WIFI); + if (((bitmask == UA_SENSOR_BLE) + && (monitor->sensor_bitmask & UA_SENSOR_WIFI)) + || ((bitmask == UA_SENSOR_WIFI) + && (monitor->sensor_bitmask & UA_SENSOR_BLE))) + monitor->presence_detected_bitmask |= + (UA_SENSOR_BLE | UA_SENSOR_WIFI); else monitor->presence_detected_bitmask |= bitmask; @@ -485,9 +505,14 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, UA_INFO("UA_DETECT_MODE_ANY_SENSOR [%d][%d]", bitmask, monitor->presence_detected_bitmask); - if (monitor->presence_cb) + if (monitor->presence_cb) { + service = __ua_get_service_from_list(monitor->service); + if (service) + service_handle = service->service_handle; monitor->presence_cb(UA_ERROR_NONE, monitor, - bitmask, device_handle, sensor_handle, monitor->user_data); + bitmask, service_handle, device_handle, + sensor_handle, monitor->user_data); + } } break; @@ -660,6 +685,8 @@ static void __ua_send_absence_detection(char *svc_name) for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) { ua_monitor_s *monitor = l->data; + ua_service_info_s *service = NULL; + ua_service_h service_handle = NULL; if (!monitor || g_strcmp0(monitor->service, svc_name)) continue; @@ -682,13 +709,18 @@ static void __ua_send_absence_detection(char *svc_name) monitor->sensor_bitmask, monitor->absence_detected_bitmask); if (monitor->sensor_bitmask == monitor->absence_detected_bitmask) { - if (monitor->absence_cb) - monitor->absence_cb(UA_ERROR_NONE, monitor, - monitor->absence_detected_bitmask, NULL, monitor->user_data); + if (monitor->absence_cb) { + service = __ua_get_service_from_list(monitor->service); + if (service) + service_handle = service->service_handle; + + monitor->absence_cb(UA_ERROR_NONE, monitor, + service_handle, monitor->absence_detected_bitmask, + NULL, monitor->user_data); + } } } - if (monitor->absence_user_cb.callback) { for (l1 = monitor->user_state; NULL != l1; l1 = g_slist_next(l1)) { ua_user_state_info_s *user_state = l1->data; @@ -719,6 +751,8 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor, ua_sensor_e bitmask = sensor_info->bitmask; ret_if(NULL == monitor); ua_sensor_h sensor_handle; + ua_service_info_s *service = NULL; + ua_service_h service_handle = NULL; if (account) { for (l = monitor->user_state; l; l = g_slist_next(l)) { @@ -750,23 +784,30 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor, _ua_get_error_string(ret)); } + service = __ua_get_service_from_list(monitor->service); + if (service) + service_handle = service->service_handle; + switch (monitor->absence_mode) { case UA_DETECT_MODE_ALL_SENSOR: break; case UA_DETECT_MODE_ANY_SENSOR: /* First add user info to local users list and then invoke callback */ if (account) { - all_absence = __ua_check_all_users_absence_state(monitor->user_state, bitmask); + all_absence = __ua_check_all_users_absence_state( + monitor->user_state, bitmask); if (all_absence) { if (monitor->absence_cb) monitor->absence_cb(UA_ERROR_NONE, monitor, - bitmask, sensor_handle, monitor->user_data); + service_handle, bitmask, sensor_handle, + monitor->user_data); } } else { if (monitor->absence_cb) monitor->absence_cb(UA_ERROR_NONE, monitor, - bitmask, sensor_handle, monitor->user_data); + service_handle, bitmask, sensor_handle, + monitor->user_data); } break; @@ -1318,7 +1359,7 @@ int ua_monitor_foreach_sensor( return UA_ERROR_NONE; } -int ua_monitor_start_scan_devices( +int ua_monitor_start_scan( ua_monitor_h handle, int scan_time, ua_scan_completed_cb callback, @@ -1357,7 +1398,7 @@ int ua_monitor_start_scan_devices( return UA_ERROR_NONE; } -int ua_monitor_stop_scan_devices(ua_monitor_h handle) +int ua_monitor_stop_scan(ua_monitor_h handle) { FUNC_ENTRY; int ret; diff --git a/test/uat-common.h b/test/uat-common.h index e7792d7..818f1a9 100755 --- a/test/uat-common.h +++ b/test/uat-common.h @@ -75,10 +75,12 @@ int _uat_monitor_set_sensor_status_cb(); void _print_device_info(ua_device_h handle); void _sensor_presence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_device_h device_handle, ua_sensor_h sensor_handle, + ua_sensor_e sensor, ua_service_h service_handle, + ua_device_h device_handle, ua_sensor_h sensor_handle, void *user_data); void _sensor_absence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_sensor_h sensor_handle, void *user_data); + ua_service_h service_handle, ua_sensor_e sensor, + ua_sensor_h sensor_handle, void *user_data); bool _foreach_registered_user_cb( ua_user_h user_handle, void *user_data); bool _foreach_added_service_cb( diff --git a/test/uat-detections.c b/test/uat-detections.c index ae4aa44..3061d5b 100755 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -87,12 +87,22 @@ static void __sensor_detected_sensor_info(int type, } void _sensor_presence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_device_h device_handle, ua_sensor_h sensor_handle, + ua_sensor_e sensor, ua_service_h service_handle, + ua_device_h device_handle, ua_sensor_h sensor_handle, void *user_data) { char *pbuf = uat_get_time(); msgb("\n[%s]", pbuf); free(pbuf); + int ret; + char *service_name = NULL; + + ret = ua_service_get_name(g_service_h, &service_name); + if (UA_ERROR_NONE != ret) { + msg(" - ua_service_get_name() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + msgb("Presence detected for service [%s]", service_name); if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) { msgb("[%s] PRESENCE detected [%s]", @@ -120,11 +130,21 @@ void _sensor_presence_detected_cb(int result, ua_monitor_h monitor, } void _sensor_absence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_sensor_h sensor_handle, void *user_data) + ua_service_h service_handle, ua_sensor_e sensor, + ua_sensor_h sensor_handle, void *user_data) { char *pbuf = uat_get_time(); msgp("\n[%s]", pbuf); free(pbuf); + int ret; + char *service_name = NULL; + + ret = ua_service_get_name(g_service_h, &service_name); + if (UA_ERROR_NONE != ret) { + msg(" - ua_service_get_name() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + msgb("Absence detected for service [%s]", service_name); if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) { msgp("[%s] ABSENCE detected [%s]", @@ -343,20 +363,20 @@ static int run_ua_monitor_stop_absence_detection( return RET_SUCCESS; } -static int run_ua_monitor_start_scan_devices( +static int run_ua_monitor_start_scan( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; unsigned int scantimemultiplier = 0; - msg("ua_monitor_start_scan_devices"); + msg("ua_monitor_start_scan"); check_if(NULL == g_ua_mon_h); if (strlen(g_scan_time_multiplier)) scantimemultiplier = (unsigned int)strtol(g_scan_time_multiplier, NULL, 10); - ret = ua_monitor_start_scan_devices(g_ua_mon_h, scantimemultiplier, + ret = ua_monitor_start_scan(g_ua_mon_h, scantimemultiplier, __ua_test_scan_completed_cb, NULL); msg(" - ua_monitor_stop_absence_detection() ret: [0x%X] [%s]", @@ -365,18 +385,18 @@ static int run_ua_monitor_start_scan_devices( return RET_SUCCESS; } -static int run_ua_monitor_stop_scan_devices( +static int run_ua_monitor_stop_scan( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; - msg("ua_monitor_stop_scan_devices,"); + msg("ua_monitor_stop_scan,"); check_if(NULL == g_ua_mon_h); - ret = ua_monitor_stop_scan_devices(g_ua_mon_h); + ret = ua_monitor_stop_scan(g_ua_mon_h); - msg("ua_monitor_stop_scan_devices,() ret: [0x%X] [%s]", + msg("ua_monitor_stop_scan,() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; @@ -583,7 +603,7 @@ static struct menu_data menu_ua_set_detection_window[] = { static struct menu_data menu_start_device_scan[] = { { "1", "Device scan time multiplier", NULL, NULL, g_scan_time_multiplier}, - { "2", "run", NULL, run_ua_monitor_start_scan_devices, NULL }, + { "2", "run", NULL, run_ua_monitor_start_scan, NULL }, { NULL, NULL, }, }; @@ -652,8 +672,8 @@ struct menu_data menu_ua_detections[] = { { "8", "ua_monitor_start_device_scan", menu_start_device_scan, NULL, NULL }, - { "9", "ua_monitor_stop_scan_devices", - NULL, run_ua_monitor_stop_scan_devices, NULL }, + { "9", "ua_monitor_stop_scan", + NULL, run_ua_monitor_stop_scan, NULL }, { "10", "ua_enable_low_power_mode", NULL, run_ua_enable_low_power_mode, NULL }, |