Home | History | Annotate | Download | only in libtiutils
      1 /*
      2  * Copyright (C) Texas Instruments - http://www.ti.com/
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 #include "ErrorUtils.h"
     19 
     20 namespace Ti {
     21 namespace Utils {
     22 
     23 /**
     24    @brief Method to convert from POSIX to Android errors
     25 
     26    @param error Any of the standard POSIX error codes (defined in bionic/libc/kernel/common/asm-generic/errno.h)
     27    @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
     28  */
     29 status_t ErrorUtils::posixToAndroidError(int error)
     30 {
     31     switch(error)
     32         {
     33         case 0:
     34             return NO_ERROR;
     35         case EINVAL:
     36         case EFBIG:
     37         case EMSGSIZE:
     38         case E2BIG:
     39         case EFAULT:
     40         case EILSEQ:
     41             return BAD_VALUE;
     42         case ENOSYS:
     43             return INVALID_OPERATION;
     44         case EACCES:
     45         case EPERM:
     46             return PERMISSION_DENIED;
     47         case EADDRINUSE:
     48         case EAGAIN:
     49         case EALREADY:
     50         case EBUSY:
     51         case EEXIST:
     52         case EINPROGRESS:
     53             return ALREADY_EXISTS;
     54         case ENOMEM:
     55             return NO_MEMORY;
     56         default:
     57             return UNKNOWN_ERROR;
     58         };
     59 
     60     return NO_ERROR;
     61 }
     62 
     63 
     64 /**
     65    @brief Method to convert from TI OSAL to Android errors
     66 
     67    @param error Any of the standard TI OSAL error codes (defined in
     68                                                                                             hardware/ti/omx/ducati/domx/system/mm_osal/inc/timm_osal_error.h)
     69    @return Any of the standard Android error code  (defined in frameworks/base/include/utils/Errors.h)
     70  */
     71 status_t ErrorUtils::osalToAndroidError(TIMM_OSAL_ERRORTYPE error)
     72 {
     73     switch(error)
     74     {
     75     case TIMM_OSAL_ERR_NONE:
     76         return NO_ERROR;
     77     case TIMM_OSAL_ERR_ALLOC:
     78         return NO_MEMORY;
     79     default:
     80         return UNKNOWN_ERROR;
     81     }
     82 
     83     return NO_ERROR;
     84 }
     85 
     86 /**
     87    @brief Method to convert from OMX to Android errors
     88 
     89    @param error Any of the standard OMX error codes (defined in hardware/ti/omx/ducati/domx/system/omx_core/inc/OMX_Core.h)
     90    @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
     91  */
     92 status_t ErrorUtils::omxToAndroidError(OMX_ERRORTYPE error)
     93 {
     94     switch(error)
     95         {
     96         case OMX_ErrorNone:
     97             return NO_ERROR;
     98         case OMX_ErrorBadParameter:
     99         case OMX_ErrorInvalidComponentName:
    100         case OMX_ErrorUndefined:
    101         case OMX_ErrorInvalidState:
    102         case OMX_ErrorStreamCorrupt:
    103         case OMX_ErrorPortsNotCompatible:
    104         case OMX_ErrorVersionMismatch:
    105         case OMX_ErrorMbErrorsInFrame:
    106             return BAD_VALUE;
    107         case OMX_ErrorInsufficientResources:
    108             return NO_MEMORY;
    109         case OMX_ErrorComponentNotFound:
    110         case OMX_ErrorNotImplemented:
    111         case OMX_ErrorFormatNotDetected:
    112         case OMX_ErrorUnsupportedSetting:
    113             return NAME_NOT_FOUND;
    114         case OMX_ErrorUnderflow:
    115         case OMX_ErrorOverflow:
    116         case OMX_ErrorUnsupportedIndex:
    117         case OMX_ErrorBadPortIndex:
    118             return BAD_INDEX;
    119         case OMX_ErrorHardware:
    120         case OMX_ErrorContentPipeCreationFailed:
    121         case OMX_ErrorContentPipeOpenFailed:
    122             return FAILED_TRANSACTION;
    123         case OMX_ErrorTimeout:
    124            return TIMED_OUT;
    125         case OMX_ErrorSameState:
    126         case OMX_ErrorIncorrectStateTransition:
    127         case OMX_ErrorIncorrectStateOperation:
    128            return PERMISSION_DENIED;
    129         case OMX_ErrorTunnelingUnsupported:
    130            return INVALID_OPERATION;
    131         default:
    132             return UNKNOWN_ERROR;
    133         }
    134 
    135     return NO_ERROR;
    136 }
    137 
    138 
    139 } // namespace Utils
    140 } // namespace Ti
    141