UA_AND_OPERATION = 0x01 /**< AND & OR */
} ua_condition_conjunction_e;
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Enumerations for sensor status
+ * @since_tizen 5.5
+ */
+typedef enum {
+ UA_SENSOR_PRESENCE = 0x01, /**< Sensor reports PRESENCE status */
+ UA_SENSOR_ABSENCE = 0x02 /**< Sensor reports ABSENCE status */
+} ua_sensor_status_e;
+
/**
* @ingroup CAPI_NETWORK_UA_MODULE
* @brief The handle of sensor information.
ua_device_h device_handle,
void *user_data);
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Callback to be invoked if a sensor status changed (presence <-> absence)
+ * immediately during detection operation.
+ * @since_tizen 5.5
+ *
+ * @remarks The @a handle should not be released.
+ * @remarks The @a handle can be used only in the callback.
+ * @remarks The @a sensor_handles should not be released.
+ * @remarks The @a sensor_handles can be used only in the callback.
+ *
+ * @param[in] status #UA_SENSOR_PRESENCE is sensor detects presence. \n
+ * #UA_SENSOR_ABSENCE is sensor detects presence.
+ * @param[in] sensor Sensor type for which status was changed.
+ * @param[in] handle The monitor handle for which sensor type was added.
+ * @param[in] sensor_handles The list of sensor handles on which user is not detected.
+ * @param[in] user_data The user data passed in ua_monitor_set_sensor_status_cb().
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_monitor_set_sensor_state_cb()
+ */
+typedef void (*ua_sensor_status_changed_cb)(
+ ua_sensor_status_e status,
+ ua_monitor_h handle,
+ ua_sensor_h sensor_handle,
+ void *user_data);
/**
* @ingroup CAPI_NETWORK_UA_MODULE
* @brief Initializes an user awareness framework.
int ua_monitor_unset_sensor_state_cb(
ua_monitor_h handle);
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sets sensor status changed callback.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The monitor handle
+ * @param[in] callback Sensor status changed callback
+ * @param[in] user_data The user data to be passed in sensor state changed callback.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_monitor_unset_sensor_state_cb()
+ */
+int ua_monitor_set_sensor_status_cb(
+ ua_monitor_h handle,
+ ua_sensor_status_changed_cb callback,
+ void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Unsets sensor status changed callback.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The monitor handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_monitor_set_sensor_state_cb()
+ */
+int ua_monitor_unset_sensor_status_cb(
+ ua_monitor_h handle);
+
/**
* @ingroup CAPI_NETWORK_UA_MODULE
* @brief Sets absence detected callback for all users.
sensors = ua_sensor_get_sensor_handle_list(monitor->presence_detected_bitmask
& filter_bitmask);
- ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
- UA_ERROR_NONE, monitor, NULL,
- NULL, sensors,
- monitor->presence_user_cb.user_data);
+ if (monitor->presence_user_cb.callback) {
+ ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
+ UA_ERROR_NONE, monitor, NULL,
+ NULL, sensors,
+ monitor->presence_user_cb.user_data);
- monitor->env_user_cb_sent = TRUE;
+ monitor->env_user_cb_sent = TRUE;
+ }
g_slist_free(sensors);
FUNC_EXIT;
FUNC_EXIT;
}
+void _ua_monitor_handle_sensor_status_changed(uam_sensor_info_s *info)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_sensor_info_s *sensor_info;
+ ret_if(NULL == info);
+
+ sensor_info = _uam_to_ua_sensor_info(info);
+ ret_if(NULL == sensor_info);
+
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
+
+ if (!monitor || (!monitor->presence_detection_started
+ && !monitor->internal_presence_started)
+ || (!monitor->absence_detection_started))
+ continue;
+
+ if (0 == (sensor_info->bitmask & monitor->sensor_bitmask))
+ continue;
+
+ if (monitor->sensor_status_cb.callback)
+ ((ua_sensor_status_changed_cb)monitor->sensor_status_cb.callback)(
+ sensor_info->status, (ua_monitor_h)monitor, (ua_sensor_h)sensor_info,
+ monitor->sensor_state_cb.user_data);
+ }
+ _ua_free_sensor_info(sensor_info);
+
+ FUNC_EXIT;
+}
+
void _ua_free_ua_monitor_t(gpointer data)
{
FUNC_ENTRY;
return UA_ERROR_NONE;
}
+int ua_monitor_set_sensor_status_cb(ua_monitor_h handle,
+ ua_sensor_status_changed_cb callback, void *user_data)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(callback);
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->sensor_status_cb.callback = callback;
+ monitor->sensor_status_cb.user_data = user_data;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+int ua_monitor_unset_sensor_status_cb(ua_monitor_h handle)
+{
+ FUNC_ENTRY;
+ ua_monitor_s *monitor = (ua_monitor_s *)handle;
+
+ UA_VALIDATE_INPUT_PARAMETER(handle);
+ UA_VALIDATE_HANDLE(handle, ua_monitor_list);
+
+ monitor->sensor_status_cb.callback = NULL;
+ monitor->sensor_status_cb.user_data = NULL;
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
int ua_monitor_add_sensor(
ua_monitor_h handle,
ua_sensor_e sensor_type)
static char g_ibeacon_adv_str[MENU_DATA_SIZE + 1] = {0,}; /**< iBeacon advertising data */
static void __user_detected_foreach_sensors(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
int ret;
char buf[MENU_DATA_SIZE] = {0, };
}
static void __user_presence_detected_foreach_devices(gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
int ret;
ua_device_h device_handle = (ua_device_h)data;
}
static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
- ua_user_h user_handle, GSList *device_handles, GSList *sensor_handles,
- void *user_data)
+ ua_user_h user_handle, GSList *device_handles, GSList *sensor_handles,
+ void *user_data)
{
int ret;
char *account = NULL;
msgb("sensor: %s is %s",
uat_get_sensor_bitmask_str(sensor), (ready ? "Ready" : "Not Ready"));
}
+static void __sensor_status_changed_cb(ua_sensor_status_e status,
+ ua_monitor_h handle, ua_sensor_h sensor_handle, void *user_data)
+{
+ int ret;
+ double *value;
+ GSList *l = 0;
+ long int timestamp;
+ int info_count = 0;
+ ua_sensor_e sensor;
+ GSList *values = NULL;
+ char buf[MENU_DATA_SIZE] = {0, };
+ char final_buf[MENU_DATA_SIZE * 4] = {0, };
+ char *pbuf = uat_get_time();
+
+ msgr("\n[%s] Sensor Status Changed -> %s",
+ pbuf, status == UA_SENSOR_PRESENCE ? "PRESENCE" : "ABSENCE");
+ free(pbuf);
+
+ ret = ua_sensor_get_bitmask(sensor_handle, &sensor);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_sensor_get_bitmask() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+
+ ret = ua_sensor_get_timestamp(sensor_handle, ×tamp);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_sensor_get_timestamp() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+
+ ret = ua_sensor_get_info_count(sensor_handle, &info_count);
+ if (UA_ERROR_NONE != ret) {
+ msg(" - ua_sensor_get_info_count() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+ }
+
+ values = ua_sensor_get_info_values(sensor_handle);
+ if (NULL == values) {
+ msg(" - ua_sensor_get_info_values() failed");
+ }
+
+ for (l = values; l; l = g_slist_next(l)) {
+ value = (double *)l->data;
+ snprintf(buf, MENU_DATA_SIZE, "%lF ", *value);
+ strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
+ memset(buf, 0, MENU_DATA_SIZE);
+ }
+ msgr("[%s] information detected at timestamp [%ld] value [%s]",
+ uat_get_sensor_bitmask_str(sensor), timestamp, final_buf);
+
+ g_slist_free(values);
+}
static int run_ua_monitor_create(MManager *mm, struct menu_data *menu)
{
return RET_SUCCESS;
}
+static int run_ua_monitor_set_sensor_status_cb(
+ MManager *mm, struct menu_data *menu)
+{
+ int ret = UA_ERROR_NONE;
+
+ msg("ua_monitor_set_sensor_status_cb");
+
+ ret = ua_monitor_set_sensor_status_cb(g_ua_mon_h,
+ __sensor_status_changed_cb, g_ua_mon_h);
+
+ msg(" - ua_monitor_set_sensor_status_cb() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+
+ return RET_SUCCESS;
+}
+
static int run_ua_monitor_unset_user_absence_detected_cb(
MManager *mm, struct menu_data *menu)
{
return RET_SUCCESS;
}
+static int run_ua_monitor_unset_sensor_status_cb(
+ MManager *mm, struct menu_data *menu)
+{
+ int ret = UA_ERROR_NONE;
+
+ msg("ua_monitor_unset_sensor_status_cb");
+
+ ret = ua_monitor_unset_user_absence_detected_cb(g_ua_mon_h);
+
+ msg(" - ua_monitor_unset_sensor_status_cb() ret: [0x%X] [%s]",
+ ret, uat_get_error_str(ret));
+
+ return RET_SUCCESS;
+}
+
static int run_ua_set_app_info(MManager *mm, struct menu_data *menu)
{
int ret = UA_ERROR_NONE;
NULL, run_ua_monitor_create, NULL },
{ "2", "ua_monitor_destroy",
NULL, run_ua_monitor_destroy, NULL },
- { "3", "ua_monitor_set_user_sensor_state_cb",
+ { "3", "ua_monitor_set_sensor_state_cb",
NULL, run_ua_monitor_set_sensor_state_cb, NULL },
- { "4", "ua_monitor_unset_user_sensor_state_cb",
+ { "4", "ua_monitor_unset_sensor_state_cb",
NULL, run_ua_monitor_unset_sensor_state_cb, NULL },
- { "5", "ua_monitor_set_user_absence_detected_cb",
+ { "5", "ua_monitor_set_sensor_status_cb",
+ NULL, run_ua_monitor_set_sensor_status_cb, NULL },
+ { "6", "ua_monitor_unset_sensor_status_cb",
+ NULL, run_ua_monitor_unset_sensor_status_cb, NULL },
+ { "7", "ua_monitor_set_user_absence_detected_cb",
NULL, run_ua_monitor_set_user_absence_detected_cb, NULL },
- { "6", "ua_monitor_unset_absence_detected_cb",
+ { "8", "ua_monitor_unset_absence_detected_cb",
NULL, run_ua_monitor_unset_user_absence_detected_cb, NULL },
- { "7", "ua_monitor_set_user_presence_detected_cb",
+ { "9", "ua_monitor_set_user_presence_detected_cb",
NULL, run_ua_monitor_set_user_presence_detected_cb, NULL },
- { "8", "ua_monitor_unset_presence_detected_cb",
+ { "10", "ua_monitor_unset_presence_detected_cb",
NULL, run_ua_monitor_unset_user_presence_detected_cb, NULL },
- { "9", "ua_set_app_info",
+ { "11", "ua_set_app_info",
menu_ua_set_app_info, NULL, NULL},
- { "10", "ua_unset_app_info",
+ { "12", "ua_unset_app_info",
menu_ua_unset_app_info, NULL, NULL},
- { "11", "ua_reset_database",
+ { "13", "ua_reset_database",
NULL, run_ua_reset_database, NULL},
- { "12", "ua_add_ibeacon_adv_data",
+ { "14", "ua_add_ibeacon_adv_data",
menu_ua_add_ibeacon_adv_data, NULL, NULL},
{ NULL, NULL, },
};