This commit provides the sensor information to application using a sensor handle
instead of providing directly using sensor struct, so that sensor struct need not
to be disclosed to the application.
Change-Id: Iab7ff5c6898404412f0fbb3d2d3586f2306d3237
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
void *user_data; /**< User data */
} ua_monitor_s;
+/**
+ * @brief sensor info data structure.
+ * @since_tizen 5.5
+ */
+typedef struct {
+ ua_sensor_h handle;
+ ua_sensor_e bitmask;
+ long int timestamp;
+ int accuracy;
+ int count;
+ double *values;
+} ua_sensor_info_s;
+
/**
* @brief User state data structure.
* @since_tizen 5.5
*/
ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info);
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor handle by sensor info.
+ * @since_tizen 5.5
+ *
+ * @remarks The @a sensor_handle should not be released.
+ * @remarks The @a sensor_handle can be used only in the function.
+ *
+ * @param[in] sensor_info The detected sensor information
+ * @param[out] sensor_handle The sensor handle.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+int ua_sensor_get_by_sensor_info(
+ ua_sensor_info_s *sensor_info,
+ ua_sensor_h * sensor_handle);
+
#ifdef __cplusplus
}
#endif
} ua_condition_conjunction_e;
/**
- * @brief sensor info data structure.
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief The handle of sensor information.
* @since_tizen 5.5
*/
-typedef struct {
- ua_sensor_e bitmask;
- long int timestamp;
- int accuracy;
- int count;
- double *values;
-} ua_sensor_info_s;
+typedef void *ua_sensor_h;
/**
* @ingroup CAPI_NETWORK_UA_MODULE
ua_monitor_h handle,
ua_sensor_e sensor,
ua_device_h device_handle,
- ua_sensor_info_s *sensor_info,
+ ua_sensor_h sensor_handle,
void *user_data);
/**
int result,
ua_monitor_h handle,
ua_sensor_e sensor,
- ua_sensor_info_s *sensor_info,
+ ua_sensor_h sensor_info,
void *user_data);
/**
{
FUNC_ENTRY;
ua_sensor_e bitmask = sensor_info->bitmask;
+ ua_sensor_h sensor_handle;
+ int ret = ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle);
+ UA_INFO("ua_device_get_by_device_id returned %s",
+ _ua_get_error_string(ret));
switch (monitor->presence_mode) {
case UA_DETECT_MODE_ALL_SENSOR:
/*
#include <user-awareness-log.h>
#include <user-awareness-private.h>
+GSList *ua_sensors_list = NULL; /* ua_sensor_info_s */
+
ua_mac_type_e _to_ua_mac_type(uam_tech_type_e tech_type)
{
switch (tech_type) {
FUNC_EXIT;
}
-ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info)
+static ua_sensor_info_s* __ua_allocate_ua_sensor_info()
{
- FUNC_ENTRY;
- ua_sensor_info_s *sensor_info = NULL;
- unsigned int i = 0;
-
+ ua_sensor_info_s *sensor_info;
sensor_info = g_malloc0(sizeof(ua_sensor_info_s));
if (!sensor_info) {
UA_ERR("g_malloc0 failed");
g_free(sensor_info);
return NULL;
}
+ return sensor_info;
+}
+
+static ua_sensor_info_s *__ua_get_sensor_info_from_list(ua_sensor_e bitmask)
+{
+ GSList *l;
+ ua_sensor_info_s *sensor;
+
+ for (l = ua_sensors_list; NULL != l; l = g_slist_next(l)) {
+ sensor = (ua_sensor_info_s *)l->data;
+
+ if (bitmask == sensor->bitmask) {
+ UA_INFO("Sensor info found, sensor bitmask[%d]", sensor->bitmask);
+ return sensor;
+ }
+ }
+
+ return NULL;
+}
+
+static int __ua_update_sensor_info(
+ ua_sensor_info_s *sensor,
+ ua_sensor_info_s *info)
+{
+ FUNC_ENTRY;
+ unsigned int i = 0;
+
+ UA_VALIDATE_INPUT_PARAMETER(sensor);
+ UA_VALIDATE_INPUT_PARAMETER(info);
+
+ sensor->timestamp = info->timestamp;
+ sensor->count = info->count;
+ sensor->bitmask = info->bitmask;
+ for(i = 0; i < UA_SENSOR_MAX_VALUES; i++) {
+ sensor->values[i] = info->values[i];
+ }
+
+ FUNC_EXIT;
+ return UA_ERROR_NONE;
+}
+
+ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info)
+{
+ FUNC_ENTRY;
+ ua_sensor_info_s *sensor_info = NULL;
+ unsigned int i = 0;
+
+ sensor_info = __ua_allocate_ua_sensor_info();
+ if (!sensor_info)
+ return NULL;
+
sensor_info->timestamp = info->timestamp;
sensor_info->count = info->count;
sensor_info->bitmask = _uam_to_ua_sensor(info->sensor_bitmask);
return sensor_info;
FUNC_EXIT;
}
+
+int ua_sensor_get_by_sensor_info(
+ ua_sensor_info_s *info,
+ ua_sensor_h *sensor_handle)
+{
+ FUNC_ENTRY;
+ int ret = UA_ERROR_NONE;
+ ua_sensor_info_s *sensor;
+ *sensor_handle = NULL;
+
+ UA_VALIDATE_INPUT_PARAMETER(info);
+ UA_VALIDATE_INPUT_PARAMETER(sensor_handle);
+
+ sensor = __ua_get_sensor_info_from_list(info->bitmask);
+
+ if (NULL != sensor) {
+ ret = __ua_update_sensor_info(sensor, info);
+ *sensor_handle = (ua_sensor_h)sensor;
+ goto done;
+ }
+
+ sensor = __ua_allocate_ua_sensor_info();
+ if (!sensor)
+ return UA_ERROR_OUT_OF_MEMORY;
+
+ ret = __ua_update_sensor_info(sensor, info);
+
+ /* Add sensor to list of sensors */
+ *sensor_handle = (ua_sensor_h)sensor;
+ sensor->handle = *sensor_handle;
+ ua_sensors_list = g_slist_append(ua_sensors_list, sensor);
+
+done:
+ FUNC_EXIT;
+ return ret;
+}
g_free(mac);
}
-static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor,
- ua_sensor_e sensor, ua_device_h device_handle, ua_sensor_info_s *info,
- void *user_data)
+static void __sensor_presence_detected_sensor_info(ua_sensor_h sensor_handle)
{
+/*
char buf[MENU_DATA_SIZE] = {0, };
char final_buf[MENU_DATA_SIZE * 4] = {0, };
+ for (int i = 0; i < info->count ; i++) {
+ if (i >= 4)
+ break;
+ snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]);
+ strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
+ memset(buf, 0, MENU_DATA_SIZE);
+ }
+ msgb("[%s] information detected at timestamp [%ld] value [%s]",
+ uat_get_sensor_bitmask_str(info->bitmask), info->timestamp,
+ final_buf);
+*/
+}
+
+static 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,
+ void *user_data)
+{
char *pbuf = uat_get_time();
msg("\n[%s] Sensor PRESENCE [%d]", pbuf, sensor);
free(pbuf);
if (device_handle)
__sensor_presence_detected_device(device_handle);
/* For sensor information */
- if (info && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION))) {
- for (int i = 0; i < info->count ; i++) {
- if (i >= 4)
- break;
- snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]);
- strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
- memset(buf, 0, MENU_DATA_SIZE);
- }
- msgb("[%s] information detected at timestamp [%ld] value [%s]",
- uat_get_sensor_bitmask_str(info->bitmask), info->timestamp,
- final_buf);
- }
+ if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION)))
+ __sensor_presence_detected_sensor_info(sensor_handle);
}
static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor,
- ua_sensor_e sensor, ua_sensor_info_s *info, void *user_data)
+ ua_sensor_e sensor, ua_sensor_h sensor_handle, void *user_data)
{
- char buf[MENU_DATA_SIZE] = {0, };
- char final_buf[MENU_DATA_SIZE * 4] = {0, };
char *pbuf = uat_get_time();
msg("\n[%s] Sensor ABSENCE", pbuf);
free(pbuf);
uat_get_sensor_bitmask_str(UA_SENSOR_MOTION), uat_get_error_str(result));
}
/* For sensor information */
- if (info && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION))) {
- for (int i = 0; i < info->count ; i++) {
- if (i >= 4)
- break;
- snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]);
- strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
- memset(buf, 0, MENU_DATA_SIZE);
- }
- msgb("[%s] information detected at timestamp [%ld] value [%s]",
- uat_get_sensor_bitmask_str(info->bitmask), info->timestamp,
- final_buf);
- }
+ if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION)))
+ __sensor_presence_detected_sensor_info(sensor_handle);
}
void __ua_test_scan_completed_cb(ua_active_scan_type_e result, ua_monitor_h handle,