Updated comments of MPPCommonUtils

This commit is contained in:
Prianka Liz Kariat 2023-01-13 21:18:01 +05:30
parent 2a53d78ae4
commit c4c07acc1e

View File

@ -26,7 +26,7 @@
NSString *const MPPTasksErrorDomain = @"com.google.mediapipe.tasks"; NSString *const MPPTasksErrorDomain = @"com.google.mediapipe.tasks";
namespace { namespace {
using absl::StatusCode; using absl::StatusCode;
} }
@implementation MPPCommonUtils @implementation MPPCommonUtils
@ -72,95 +72,70 @@ namespace {
return YES; return YES;
} }
// Creates the NSEror with the appropriate error /** Converts the absl status message to an NSString. */
// MPPTasksErrorCode and message. MPPTasksErrorCode has a one to one
// mapping with MediaPipeTasksStatus starting from the value 1(MPPTasksErrorCodeError)
// and hence will be correctly initialized if directly cast from the integer code derived from
// MediaPipeTasksStatus stored in its payload. MPPTasksErrorCode omits kOk = 0 of
// MediaPipeTasksStatusx.
//
// Stores a string including absl status code and message(if non empty) as the
// error message See
// https://github.com/abseil/abseil-cpp/blob/master/absl/status/status.h#L514
// for explanation. absl::Status::message() can also be used but not always
// guaranteed to be non empty.
NSString *description = [NSString NSString *description = [NSString
stringWithCString:status.ToString(absl::StatusToStringMode::kWithNoExtraData).c_str() stringWithCString:status.ToString(absl::StatusToStringMode::kWithNoExtraData).c_str()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
// Payload of absl::Status created by the MediaPipe task library stores an appropriate value of
// the enum MediaPipeTasksStatus. The integer value corresponding to the MediaPipeTasksStatus enum
// stored in the payload is extracted here to later map to the appropriate error code to be
// returned. In cases where the enum is not stored in (payload is NULL or the payload string
// cannot be converted to an integer), we set the error code value to be 1
// (MPPTasksErrorCodeError of MPPTasksErrorCode used in the iOS library to signify
// any errors not falling into other categories.) Since payload is of type absl::Cord that can be
// type cast into an absl::optional<std::string>, we use the std::stoi function to convert it into
// an integer code if possible.
MPPTasksErrorCode genericErrorCode = MPPTasksErrorCodeUnknownError; MPPTasksErrorCode genericErrorCode = MPPTasksErrorCodeUnknownError;
MPPTasksErrorCode errorCode = genericErrorCode; MPPTasksErrorCode errorCode = genericErrorCode;
// If errorCode is outside the range of enum values possible or is /** Maps the absl::StatusCode to the appropriate MPPTasksErrorCode. Note: MPPTasksErrorCode omits
// MPPTasksErrorCodeError, we try to map the absl::Status::code() to assign * absl::StatusCode::kOk. */
// appropriate MPPTasksErrorCode in default cases. Note: switch (status.code()) {
// The mapping to absl::Status::code() is done to generate a more specific error code than case StatusCode::kCancelled:
// MPPTasksErrorCodeError in cases when the payload can't be mapped to errorCode = MPPTasksErrorCodeCancelledError;
// MPPTasksErrorCode. This can happen when absl::Status returned by TFLite library are in turn break;
// returned without modification by MediaPipe cc library methods. case StatusCode::kUnknown:
switch (status.code()) { errorCode = MPPTasksErrorCodeUnknownError;
case StatusCode::kCancelled: break;
errorCode = MPPTasksErrorCodeCancelledError; case StatusCode::kInvalidArgument:
break; errorCode = MPPTasksErrorCodeInvalidArgumentError;
case StatusCode::kUnknown: break;
errorCode = MPPTasksErrorCodeUnknownError; case StatusCode::kDeadlineExceeded:
break; errorCode = MPPTasksErrorCodeDeadlineExceededError;
case StatusCode::kInvalidArgument: break;
errorCode = MPPTasksErrorCodeInvalidArgumentError; case StatusCode::kNotFound:
break; errorCode = MPPTasksErrorCodeNotFoundError;
case StatusCode::kDeadlineExceeded: break;
errorCode = MPPTasksErrorCodeDeadlineExceededError; case StatusCode::kAlreadyExists:
break; errorCode = MPPTasksErrorCodeAlreadyExistsError;
case StatusCode::kNotFound: break;
errorCode = MPPTasksErrorCodeNotFoundError; case StatusCode::kPermissionDenied:
break; errorCode = MPPTasksErrorCodePermissionDeniedError;
case StatusCode::kAlreadyExists: break;
errorCode = MPPTasksErrorCodeAlreadyExistsError; case StatusCode::kResourceExhausted:
break; errorCode = MPPTasksErrorCodeResourceExhaustedError;
case StatusCode::kPermissionDenied: break;
errorCode = MPPTasksErrorCodePermissionDeniedError; case StatusCode::kFailedPrecondition:
break; errorCode = MPPTasksErrorCodeFailedPreconditionError;
case StatusCode::kResourceExhausted: break;
errorCode = MPPTasksErrorCodeResourceExhaustedError; case StatusCode::kAborted:
break; errorCode = MPPTasksErrorCodeAbortedError;
case StatusCode::kFailedPrecondition: break;
errorCode = MPPTasksErrorCodeFailedPreconditionError; case StatusCode::kOutOfRange:
break; errorCode = MPPTasksErrorCodeOutOfRangeError;
case StatusCode::kAborted: break;
errorCode = MPPTasksErrorCodeAbortedError; case StatusCode::kUnimplemented:
break; errorCode = MPPTasksErrorCodeUnimplementedError;
case StatusCode::kOutOfRange: break;
errorCode = MPPTasksErrorCodeOutOfRangeError; case StatusCode::kInternal:
break; errorCode = MPPTasksErrorCodeInternalError;
case StatusCode::kUnimplemented: break;
errorCode = MPPTasksErrorCodeUnimplementedError; case StatusCode::kUnavailable:
break; errorCode = MPPTasksErrorCodeUnavailableError;
case StatusCode::kInternal: break;
errorCode = MPPTasksErrorCodeInternalError; case StatusCode::kDataLoss:
break; errorCode = MPPTasksErrorCodeDataLossError;
case StatusCode::kUnavailable: break;
errorCode = MPPTasksErrorCodeUnavailableError; case StatusCode::kUnauthenticated:
break; errorCode = MPPTasksErrorCodeUnauthenticatedError;
case StatusCode::kDataLoss: break;
errorCode = MPPTasksErrorCodeDataLossError; default:
break; errorCode = genericErrorCode;
case StatusCode::kUnauthenticated: break;
errorCode = MPPTasksErrorCodeUnauthenticatedError; }
break;
default:
errorCode = genericErrorCode;
break;
}
[MPPCommonUtils createCustomError:error withCode:errorCode description:description]; [MPPCommonUtils createCustomError:error withCode:errorCode description:description];
return NO; return NO;