sensord: add get_sensor_*_ex internal APIs for getting error properly 81/63681/1
authorkibak.yoon <kibak.yoon@samsung.com>
Thu, 24 Mar 2016 16:57:05 +0000 (01:57 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 25 Mar 2016 07:37:57 +0000 (16:37 +0900)
* if clients uses sensord_get_sensor/sensord_get_sensor_list APIs to get
  sensor handle(s), they cannot know the error exactly. because APIs
  return only bool or handle itself, not including error info.

Change-Id: I83e9c28217621a5a6ab3c5e35dd45c84a5056cea
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/client.cpp
src/client/sensor_internal.h

index 56e7db9..8bbf2fb 100644 (file)
@@ -334,34 +334,64 @@ static bool get_sensor_list(void)
        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)
index 2c6d56f..86a1b00 100644 (file)
@@ -62,6 +62,32 @@ bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_co
 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.