1/*
2 * Copyright (C) 2011 The Android Open Source Project
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* @file        LV_Macros.h
19* @par        NXP Software
20* @brief    Macros definition for Smartphone team
21*******************************************************************************/
22
23#ifndef LV_MACROS_H
24#define LV_MACROS_H
25
26/*------------*/
27/*    INCLUDES  */
28/*------------*/
29#include "M4OSA_Memory.h"
30#include "M4OSA_Debug.h"
31
32/******************************************************************************
33*
34* CHECK_PTR(fct, p, err, errValue)
35* @note    This macro checks the value p. If it is NULL, it sets the variable err
36*           to errValue and jumps to the label <fct>_cleanUp. A trace is displayed
37*           signalling the error, the function name and the line number.
38*
39******************************************************************************/
40#define CHECK_PTR(fct, p, err, errValue) \
41{ \
42    if(M4OSA_NULL == (p)) \
43    { \
44        (err) = (errValue) ; \
45        M4OSA_TRACE1_1((M4OSA_Char*)"" #fct "(L%d): " #p " is NULL, returning " #errValue "",__LINE__) ; \
46        goto fct##_cleanUp; \
47    } \
48}
49
50/******************************************************************************
51*
52* CHECK_ERR(fct, err)
53* @note    This macro checks the value err. If it is not NULL, a trace is displayed
54*           signalling the error, the function name and the line number. The macro
55*           jumps to the label <fct>_cleanUp.
56*
57******************************************************************************/
58#define CHECK_ERR(fct, err) \
59{ \
60    if(M4NO_ERROR != (err)) \
61    { \
62        M4OSA_TRACE1_2((M4OSA_Char*)"!!! " #fct "(L%d): ERROR 0x%.8x returned",\
63                                                               __LINE__,err) ; \
64        goto fct##_cleanUp; \
65    } \
66}
67
68
69/******************************************************************************
70*
71* CHECK_ERR(fct, err)
72* @note    This macro compares a current state with a state value. If they are different,
73*           err is set to M4ERR_STATE.
74*           A trace is displayed signalling the error, the function name and the line number.
75*           The macro jumps to the label <fct>_cleanUp.
76*
77******************************************************************************/
78#define    CHECK_STATE(fct, stateValue, state) \
79{ \
80    if((stateValue) != (state)) \
81    { \
82        M4OSA_TRACE1_1("" #fct " called in bad state %d", state) ; \
83        (err) = M4ERR_STATE ; \
84        goto fct##_cleanUp; \
85    } \
86}
87
88/******************************************************************************
89*
90* SAFE_FREE(p)
91* @note    This macro checks the value of p is not NULL. If it is NULL, it does
92*           nothing. Else, p is de allocated and set to NULL.
93*
94******************************************************************************/
95#define SAFE_FREE(p) \
96{ \
97    if(M4OSA_NULL != (p)) \
98    { \
99        free((p)) ; \
100        (p) = M4OSA_NULL ; \
101    } \
102}
103
104
105
106#endif /*---  LV_MACROS_H ---*/
107
108