Home | History | Annotate | Download | only in utils
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #ifndef HWC_TRACE_H
     17 #define HWC_TRACE_H
     18 
     19 #define LOG_TAG "hwcomposer"
     20 //#define LOG_NDEBUG 0
     21 #include <cutils/log.h>
     22 
     23 
     24 #ifdef _cplusplus
     25 extern "C" {
     26 #endif
     27 
     28 // Helper to automatically preappend classname::functionname to the log message
     29 #define VTRACE(fmt,...)     ALOGV("%s: " fmt, __func__, ##__VA_ARGS__)
     30 #define DTRACE(fmt,...)     ALOGD("%s: " fmt, __func__, ##__VA_ARGS__)
     31 #define ITRACE(fmt,...)     ALOGI("%s: " fmt, __func__, ##__VA_ARGS__)
     32 #define WTRACE(fmt,...)     ALOGW("%s: " fmt, __func__, ##__VA_ARGS__)
     33 #define ETRACE(fmt,...)     ALOGE("%s: " fmt, __func__, ##__VA_ARGS__)
     34 
     35 
     36 // Function call tracing
     37 #if 0
     38 #define CTRACE()            ALOGV("Calling %s", __func__)
     39 #define XTRACE()            ALOGV("Leaving %s", __func__)
     40 #else
     41 #define CTRACE()            ((void)0)
     42 #define XTRACE()            ((void)0)
     43 #endif
     44 
     45 
     46 // Arguments tracing
     47 #if 0
     48 #define ATRACE(fmt,...)     ALOGV("%s(args): "fmt, __func__, ##__VA_ARGS__);
     49 #else
     50 #define ATRACE(fmt,...)     ((void)0)
     51 #endif
     52 
     53 
     54 
     55 // Helper to abort the execution if object is not initialized.
     56 // This should never happen if the rules below are followed during design:
     57 // 1) Create an object.
     58 // 2) Initialize the object immediately.
     59 // 3) If failed, delete the object.
     60 // These helpers should be disabled and stripped out of release build
     61 
     62 #define RETURN_X_IF_NOT_INIT(X) \
     63 do { \
     64     CTRACE(); \
     65     if (false == mInitialized) { \
     66         LOG_ALWAYS_FATAL("%s: Object is not initialized! Line = %d", __func__, __LINE__); \
     67         return X; \
     68     } \
     69 } while (0)
     70 
     71 #if 1
     72 #define RETURN_FALSE_IF_NOT_INIT()      RETURN_X_IF_NOT_INIT(false)
     73 #define RETURN_VOID_IF_NOT_INIT()       RETURN_X_IF_NOT_INIT()
     74 #define RETURN_NULL_IF_NOT_INIT()       RETURN_X_IF_NOT_INIT(0)
     75 #else
     76 #define RETURN_FALSE_IF_NOT_INIT()      ((void)0)
     77 #define RETURN_VOID_IF_NOT_INIT()       ((void)0)
     78 #define RETURN_NULL_IF_NOT_INIT()       ((void)0)
     79 #endif
     80 
     81 
     82 // Helper to log error message, call de-initializer and return false.
     83 #define DEINIT_AND_RETURN_FALSE(...) \
     84 do { \
     85     ETRACE(__VA_ARGS__); \
     86     deinitialize(); \
     87     return false; \
     88 } while (0)
     89 
     90 
     91 #define DEINIT_AND_DELETE_OBJ(X) \
     92     if (X) {\
     93         X->deinitialize();\
     94         delete X; \
     95         X = NULL; \
     96     }
     97 
     98 
     99 #define WARN_IF_NOT_DEINIT() \
    100     CTRACE(); \
    101     if (mInitialized) {\
    102         LOG_ALWAYS_FATAL("%s: Object is not deinitialized! Line = %d", __func__, __LINE__); \
    103     }
    104 
    105 
    106 // _cplusplus
    107 #ifdef _cplusplus
    108 }
    109 #endif
    110 
    111 
    112 #endif /* HWC_TRACE_H */
    113