[C-API] Add PERMISSION_DENIED state for privilege issue
authorSangjung Woo <sangjung.woo@samsung.com>
Tue, 6 Aug 2019 11:06:26 +0000 (20:06 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 7 Aug 2019 10:20:45 +0000 (19:20 +0900)
This patch newly adds the ML_ERROR_PERMISSION_DENIED error code for
privilege issue and its checking logic in ml_get_feature_enabled()
function.

Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
api/capi/include/nnstreamer-capi-private.h
api/capi/include/nnstreamer-single.h
api/capi/include/nnstreamer.h
api/capi/modify_nnstreamer_h_for_nontizen.sh
api/capi/src/nnstreamer-capi-util.c

index 52428fd..03e2e49 100644 (file)
@@ -35,8 +35,9 @@
 #define ML_INF_FEATURE_PATH "tizen.org/feature/machine_learning.inference"
 
 #define check_feature_state() \
-  if (ML_ERROR_NONE != ml_get_feature_enabled()) \
-    return ML_ERROR_NOT_SUPPORTED;
+  int feature_ret = ml_get_feature_enabled(); \
+  if (ML_ERROR_NONE != feature_ret) \
+    return feature_ret;
 
 #if defined(__TIZEN__)
   #include <dlog.h>
index 51f7b6e..6caeeda 100644 (file)
@@ -74,6 +74,7 @@ typedef void *ml_single_h;
  * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
  * @retval #ML_ERROR_INVALID_PARAMETER Fail. The parameter is invalid.
  * @retval #ML_ERROR_STREAMS_PIPE Failed to start the pipeline.
+ * @retval #ML_ERROR_PERMISSION_DENIED The application does not have the privilege to access to the media storage or external storage.
  */
 int ml_single_open (ml_single_h *single, const char *model, const ml_tensors_info_h input_info, const ml_tensors_info_h output_info, ml_nnfw_type_e nnfw, ml_nnfw_hw_e hw);
 
index 61c5bbd..a20e05b 100644 (file)
@@ -153,6 +153,7 @@ typedef enum {
   ML_ERROR_UNKNOWN              = TIZEN_ERROR_UNKNOWN,  /**< Unknown error */
   ML_ERROR_TIMED_OUT            = TIZEN_ERROR_TIMED_OUT,  /**< Time out */
   ML_ERROR_NOT_SUPPORTED        = TIZEN_ERROR_NOT_SUPPORTED, /**< The feature is not supported */
+  ML_ERROR_PERMISSION_DENIED    = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
 } ml_error_e;
 
 /**
@@ -245,6 +246,7 @@ typedef void (*ml_pipeline_state_cb) (ml_pipeline_state_e state, void *user_data
  * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
  * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. (pipe is NULL?)
  * @retval #ML_ERROR_STREAMS_PIPE Pipeline construction is failed because of wrong parameter or initialization failure.
+ * @retval #ML_ERROR_PERMISSION_DENIED The application does not have the privilege to access to the media storage or external storage.
  */
 int ml_pipeline_construct (const char *pipeline_description, ml_pipeline_state_cb cb, void *user_data, ml_pipeline_h *pipe);
 
index 5962905..8c702dd 100755 (executable)
@@ -7,5 +7,6 @@ sed -i "s|#include <tizen_error.h>|#include <errno.h>\n\
 #define TIZEN_ERROR_TRY_AGAIN (-EAGAIN)\n\
 #define TIZEN_ERROR_UNKNOWN (-1073741824LL)\n\
 #define TIZEN_ERROR_TIMED_OUT (TIZEN_ERROR_UNKNOWN + 1)\n\
-#define TIZEN_ERROR_NOT_SUPPORTED (TIZEN_ERROR_UNKNOWN + 2)\
+#define TIZEN_ERROR_NOT_SUPPORTED (TIZEN_ERROR_UNKNOWN + 2)\n\
+#define TIZEN_ERROR_PERMISSION_DENIED (-EACCES)\
 |" include/nnstreamer.h
index 868bdf5..ac74c1b 100644 (file)
@@ -856,6 +856,7 @@ ml_get_feature_enabled (void)
 
 #if defined(__TIZEN__)
   {
+    int ret;
     int feature_enabled;
 
     g_mutex_lock (&feature_info->mutex);
@@ -867,7 +868,8 @@ ml_get_feature_enabled (void)
       return ML_ERROR_NOT_SUPPORTED;
     } else if (-1 == feature_enabled) {
       bool ml_inf_supported = false;
-      if (0 == system_info_get_platform_bool(ML_INF_FEATURE_PATH, &ml_inf_supported)) {
+      ret = system_info_get_platform_bool(ML_INF_FEATURE_PATH, &ml_inf_supported);
+      if (0 == ret) {
         if (false == ml_inf_supported) {
           ml_loge ("machine_learning.inference NOT supported");
           ml_set_feature_status (0);
@@ -876,8 +878,28 @@ ml_get_feature_enabled (void)
 
         ml_set_feature_status (1);
       } else {
-        ml_loge ("failed to get feature value of machine_learning.inference");
-        return ML_ERROR_NOT_SUPPORTED;
+        switch (ret) {
+          case SYSTEM_INFO_ERROR_INVALID_PARAMETER:
+            ml_loge ("failed to get feature value because feature key is not vaild");
+            ret = ML_ERROR_NOT_SUPPORTED;
+            break;
+
+          case SYSTEM_INFO_ERROR_IO_ERROR:
+            ml_loge ("failed to get feature value because of input/output error");
+            ret = ML_ERROR_NOT_SUPPORTED;
+            break;
+
+          case SYSTEM_INFO_ERROR_PERMISSION_DENIED:
+            ml_loge ("failed to get feature value because of permission denied");
+            ret = ML_ERROR_PERMISSION_DENIED;
+            break;
+
+          default:
+            ml_loge ("failed to get feature value because of unknown error");
+            ret = ML_ERROR_NOT_SUPPORTED;
+            break;
+        }
+        return ret;
       }
     }
   }