[ML][utils] Add native error to PlatformResult converter 75/250575/5
authorPawel Wasowski <p.wasowski2@samsung.com>
Tue, 29 Dec 2020 15:56:01 +0000 (16:56 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Mon, 4 Jan 2021 11:55:14 +0000 (11:55 +0000)
[Verification] The code builds fine

Change-Id: I88234f6474850f554dc617bb0ccc5343b6ed7e93
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/ml/ml_utils.cc
src/ml/ml_utils.h

index 44987d8..7babe96 100644 (file)
@@ -24,6 +24,35 @@ namespace extension {
 namespace ml {
 namespace util {
 
+PlatformResult ToPlatformResult(int ml_error_code, const std::string& error_message_beginning) {
+  ScopeLogger("ml_error_code: [%d] (%s)", ml_error_code, get_error_message(ml_error_code));
+
+  switch (ml_error_code) {
+    case ML_ERROR_NONE:
+      return PlatformResult{};
+    case ML_ERROR_INVALID_PARAMETER:
+      return PlatformResult{ErrorCode::INVALID_VALUES_ERR,
+                            error_message_beginning + ": invalid parameter"};
+    case ML_ERROR_PERMISSION_DENIED:
+      return PlatformResult{ErrorCode::SECURITY_ERR,
+                            error_message_beginning + ": permission denied"};
+    case ML_ERROR_TRY_AGAIN:
+      return PlatformResult{ErrorCode::INVALID_STATE_ERR,
+                            error_message_beginning + ": invalid state"};
+    case ML_ERROR_TIMED_OUT:
+      return PlatformResult{ErrorCode::TIMEOUT_ERR, error_message_beginning + ": timeout"};
+    case ML_ERROR_NOT_SUPPORTED:
+      return PlatformResult{ErrorCode::NOT_SUPPORTED_ERR,
+                            error_message_beginning + ": not supported"};
+    case ML_ERROR_STREAMS_PIPE:
+    case ML_ERROR_UNKNOWN:
+    case ML_ERROR_OUT_OF_MEMORY:
+    default:
+      return PlatformResult{ErrorCode::ABORT_ERR,
+                            error_message_beginning + ": an unknown error occurred"};
+  }
+}
+
 using namespace common;
 
 }  // util
index 3424aad..725c7d9 100644 (file)
 #ifndef ML_ML_UTILS_H_
 #define ML_ML_UTILS_H_
 
+#include <nnstreamer/nnstreamer.h>
+
 #include "common/picojson.h"
 #include "common/platform_result.h"
 
+using common::PlatformResult;
+using common::ErrorCode;
+
 namespace extension {
 namespace ml {
-namespace util {}  // util
+namespace util {
+
+PlatformResult ToPlatformResult(int ml_error_code, const std::string& error_message);
+
+}  // util
 }  // ml
 }  // extension