return true;
}
-API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
+API int sensord_get_sensor_list_ex(sensor_type_t type, sensor_t **list, int *sensor_count)
{
- retvm_if (!get_sensor_list(), false, "Fail to get sensor list from server");
+ retvm_if (!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
vector<sensor_info *> sensor_infos = sensor_info_manager::get_instance().get_infos(type);
- if (!sensor_infos.empty()) {
- *list = (sensor_t *) malloc(sizeof(sensor_info *) * sensor_infos.size());
- retvm_if(!*list, false, "Failed to allocate memory");
+ if (sensor_infos.empty()) {
+ *sensor_count = 0;
+ return -ENODATA;
+ }
+
+ if (type != ALL_SENSOR) {
+ if (sensor_infos[0]->get_id() == (sensor_id_t)(-EACCES))
+ return -EACCES;
}
+ *list = (sensor_t *) malloc(sizeof(sensor_info *) * sensor_infos.size());
+ retvm_if(!*list, false, "Failed to allocate memory");
+
for (unsigned int i = 0; i < sensor_infos.size(); ++i)
*(*list + i) = sensor_info_to_sensor(sensor_infos[i]);
*sensor_count = sensor_infos.size();
- return true;
+ return OP_SUCCESS;
}
-API sensor_t sensord_get_sensor(sensor_type_t type)
+API int sensord_get_sensor_ex(sensor_type_t type, sensor_t *sensor)
{
- retvm_if (!get_sensor_list(), NULL, "Fail to get sensor list from server");
+ retvm_if (!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
const sensor_info *info;
info = sensor_info_manager::get_instance().get_info(type);
+ if (info == NULL) {
+ *sensor = NULL;
+ return -ENODATA;
+ }
+
+ if ((const_cast<sensor_info *>(info))->get_id() == (sensor_id_t)(-EACCES))
+ return -EACCES;
+
+ *sensor = sensor_info_to_sensor(info);
+
+ return OP_SUCCESS;
+}
+
+API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
+{
+ return (sensord_get_sensor_list_ex(type, list, sensor_count) == OP_SUCCESS);
+}
+
+API sensor_t sensord_get_sensor(sensor_type_t type)
+{
+ sensor_t sensor;
+ sensord_get_sensor_ex(type, &sensor);
- return sensor_info_to_sensor(info);
+ return sensor;
}
API bool sensord_get_type(sensor_t sensor, sensor_type_t *type)
sensor_t sensord_get_sensor(sensor_type_t type);
/**
+ * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
+ *
+ * @param[in] type the type of sensors requested.
+ * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
+ * @param[out] sensor count the count of sensors contained in the list.
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EPERM Operation not permitted
+ * @retval -EACCES Permission denied
+ * @retval -ENODATA NO sensor available
+ */
+int sensord_get_sensor_list_ex(sensor_type_t type, sensor_t **list, int *sensor_count);
+
+/**
+ * @brief Get the default sensor for a given type.
+ *
+ * @param[in] type the type of a sensor requested.
+ * @param[out] a sensor matching the asked type.
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EPERM Operation not permitted
+ * @retval -EACCES Permission denied
+ */
+int sensord_get_sensor_ex(sensor_type_t type, sensor_t *sensor);
+
+/**
* @brief Get the type of this sensor.
*
* @param[in] sensor a sensor to get type.