summaryrefslogtreecommitdiffstats
path: root/libsensors_iio/software/simple_apps/common/mlerrorcode.h
blob: 9a357921cff93bfb79d9412bf681744772049812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 $License:
    Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
 $
 */
/*******************************************************************************
 *
 * $Id: mltypes.h 3680 2010-09-04 03:13:32Z mcaramello $
 *
 *******************************************************************************/

#ifndef _MLERRORCODE_H_
#define _MLERRORCODE_H_

#include "mltypes.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
    Defines 
*/
#define CALL_N_CHECK(f) {                                                   \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                             \
        MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
    }                                                                       \
}

#define CALL_CHECK_N_RETURN_ERROR(f) {                                      \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                             \
        MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        return r35uLt;                                                      \
    }                                                                       \
}

// for functions returning void
#define CALL_CHECK_N_RETURN(f) do {                                         \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                             \
        MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        return;                                                             \
    }                                                                       \
    } while(0)

#define CALL_CHECK_N_EXIT(f) {                                              \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                             \
        MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        exit (r35uLt);                                                      \
    }                                                                       \
}

    
#define CALL_CHECK_N_CALLBACK(f, cb) {                                      \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                             \
        MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        cb;                                                                 \
    }                                                                       \
}

#define CALL_CHECK_N_GOTO(f, label) {                                       \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                             \
        MPL_LOGE("Error in file %s, line %d : %s returned code %s (#%d)\n", \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        goto label;                                                         \
    }                                                                       \
}

char* MLErrorCode(inv_error_t errorcode);

#ifdef __cplusplus
}
#endif

#endif