• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 // Copyright (c) 2014 Intel Corporation 
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 #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 VLOGTRACE(fmt,...)     ALOGV("%s: "fmt, __func__, ##__VA_ARGS__)
30 #define DLOGTRACE(fmt,...)     ALOGD("%s: "fmt, __func__, ##__VA_ARGS__)
31 #define ILOGTRACE(fmt,...)     ALOGI("%s: "fmt, __func__, ##__VA_ARGS__)
32 #define WLOGTRACE(fmt,...)     ALOGW("%s: "fmt, __func__, ##__VA_ARGS__)
33 #define ELOGTRACE(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 XLOGTRACE()            ALOGV("Leaving %s", __func__)
40 #else
41 #define CTRACE()            ((void)0)
42 #define XLOGTRACE()            ((void)0)
43 #endif
44 
45 
46 // Arguments tracing
47 #if 0
48 #define ALOGTRACE(fmt,...)     ALOGV("%s(args): "fmt, __func__, ##__VA_ARGS__);
49 #else
50 #define ALOGTRACE(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     ELOGTRACE(__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