From: Pawel Wasowski Date: Tue, 29 Dec 2020 15:56:01 +0000 (+0100) Subject: [ML][utils] Add native error to PlatformResult converter X-Git-Tag: submit/tizen/20210128.113801~32^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5699286b81ab1d0f3d4f4322bc0ed8e797aa769;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [ML][utils] Add native error to PlatformResult converter [Verification] The code builds fine Change-Id: I88234f6474850f554dc617bb0ccc5343b6ed7e93 Signed-off-by: Pawel Wasowski --- diff --git a/src/ml/ml_utils.cc b/src/ml/ml_utils.cc index 44987d84..7babe96e 100644 --- a/src/ml/ml_utils.cc +++ b/src/ml/ml_utils.cc @@ -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 diff --git a/src/ml/ml_utils.h b/src/ml/ml_utils.h index 3424aadd..725c7d96 100644 --- a/src/ml/ml_utils.h +++ b/src/ml/ml_utils.h @@ -17,12 +17,21 @@ #ifndef ML_ML_UTILS_H_ #define ML_ML_UTILS_H_ +#include + #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