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 android {
     21 
     22 /**
     23    @brief Method to convert from POSIX to Android errors
     24 
     25    @param error Any of the standard POSIX error codes (defined in bionic/libc/kernel/common/asm-generic/errno.h)
     26    @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
     27  */
     28 status_t ErrorUtils::posixToAndroidError(int error)
     29 {
     30     switch(error)
     31         {
     32         case 0:
     33             return NO_ERROR;
     34         case EINVAL:
     35         case EFBIG:
     36         case EMSGSIZE:
     37         case E2BIG:
     38         case EFAULT:
     39         case EILSEQ:
     40             return BAD_VALUE;
     41         case ENOSYS:
     42             return INVALID_OPERATION;
     43         case EACCES:
     44         case EPERM:
     45             return PERMISSION_DENIED;
     46         case EADDRINUSE:
     47         case EAGAIN:
     48         case EALREADY:
     49         case EBUSY:
     50         case EEXIST:
     51         case EINPROGRESS:
     52             return ALREADY_EXISTS;
     53         case ENOMEM:
     54             return NO_MEMORY;
     55         default:
     56             return UNKNOWN_ERROR;
     57         };
     58 
     59     return NO_ERROR;
     60 }
     61 
     62 
     63 /**
     64    @brief Method to convert from TI OSAL to Android errors
     65 
     66    @param error Any of the standard TI OSAL error codes (defined in
     67                                                                                             hardware/ti/omx/ducati/domx/system/mm_osal/inc/timm_osal_error.h)
     68    @return Any of the standard Android error code  (defined in frameworks/base/include/utils/Errors.h)
     69  */
     70 status_t ErrorUtils::osalToAndroidError(TIMM_OSAL_ERRORTYPE error)
     71 {
     72     switch(error)
     73     {
     74     case TIMM_OSAL_ERR_NONE:
     75         return NO_ERROR;
     76     case TIMM_OSAL_ERR_ALLOC:
     77         return NO_MEMORY;
     78     default:
     79         return UNKNOWN_ERROR;
     80     }
     81 
     82     return NO_ERROR;
     83 }
     84 
     85 /**
     86    @brief Method to convert from OMX to Android errors
     87 
     88    @param error Any of the standard OMX error codes (defined in hardware/ti/omx/ducati/domx/system/omx_core/inc/OMX_Core.h)
     89    @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
     90  */
     91 status_t ErrorUtils::omxToAndroidError(OMX_ERRORTYPE error)
     92 {
     93     switch(error)
     94         {
     95         case OMX_ErrorNone:
     96             return NO_ERROR;
     97         case OMX_ErrorBadParameter:
     98         case OMX_ErrorInvalidComponentName:
     99         case OMX_ErrorUndefined:
    100         case OMX_ErrorInvalidState:
    101         case OMX_ErrorStreamCorrupt:
    102         case OMX_ErrorPortsNotCompatible:
    103         case OMX_ErrorVersionMismatch:
    104         case OMX_ErrorMbErrorsInFrame:
    105             return BAD_VALUE;
    106         case OMX_ErrorInsufficientResources:
    107             return NO_MEMORY;
    108         case OMX_ErrorComponentNotFound:
    109         case OMX_ErrorNotImplemented:
    110         case OMX_ErrorFormatNotDetected:
    111         case OMX_ErrorUnsupportedSetting:
    112             return NAME_NOT_FOUND;
    113         case OMX_ErrorUnderflow:
    114         case OMX_ErrorOverflow:
    115         case OMX_ErrorUnsupportedIndex:
    116         case OMX_ErrorBadPortIndex:
    117             return BAD_INDEX;
    118         case OMX_ErrorHardware:
    119         case OMX_ErrorContentPipeCreationFailed:
    120         case OMX_ErrorContentPipeOpenFailed:
    121             return FAILED_TRANSACTION;
    122         case OMX_ErrorTimeout:
    123            return TIMED_OUT;
    124         case OMX_ErrorSameState:
    125         case OMX_ErrorIncorrectStateTransition:
    126         case OMX_ErrorIncorrectStateOperation:
    127            return PERMISSION_DENIED;
    128         case OMX_ErrorTunnelingUnsupported:
    129            return INVALID_OPERATION;
    130         default:
    131             return UNKNOWN_ERROR;
    132         }
    133 
    134     return NO_ERROR;
    135 }
    136 
    137 
    138 };
    139 
    140 
    141 
    142