1 #ifndef HAP_FARF_H 2 #define HAP_FARF_H 3 /** 4 * Copyright (c) 2019, The Linux Foundation. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following 13 * disclaimer in the documentation and/or other materials provided 14 * with the distribution. 15 * * Neither the name of The Linux Foundation nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 26 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include "AEEStdDef.h" 33 #include "HAP_debug.h" 34 35 /** 36 * FARF macro used for logging 37 * 38 * Compile time logging options 39 * ----------------------------- 40 * 41 * Logging is controlled via conditional compilation. A FARF 42 * level should be defined to 1 for FARF macros to be compiled 43 * in. For example: 44 * 45 * #define FARF_LOW 1 46 * #include "HAP_farf.h" 47 * 48 * FARF(LOW, "something happened: %s", (const char*)string); 49 * 50 * If FARF_LOW is defined to 0, as it is by default, the above 51 * FARF string will not be compiled in, if it is defined to 1 it 52 * will be compiled in. Users can also define their own custom 53 * levels. For example: 54 * 55 * #include "HAP_farf.h" 56 * #define FARF_MYTRACE 1 57 * #define FARF_MYTRACE_LEVEL HAP_LEVEL_LOW 58 * 59 * FARF(MYTRACE, "custom trace in file %s on line %d", __FILE__, __LINE__); 60 * 61 * The LEVEL define tells FARF what logging level to 62 * use. These are mapped to their diag level counterparts, in 63 * the above example the message will be logged to diag's LOW 64 * level. 65 * 66 * Messages logged with ALWAYS level are always compiled in and logged 67 * ------ 68 * 69 * When building the Debug variant or builds defining _DEBUG the 70 * following FARF levels will be enabled: 71 * 72 * HIGH 73 * ERROR 74 * FATAL 75 * 76 * 77 * 78 * Run time logging options 79 * -------------------------- 80 * 81 * In order to enable run-time logging (logging that can be enabled / disabled 82 * at run-time), the FARF_RUNTIME_* macros should be used. 83 * 84 * Log messages sent with these macros are compiled in by default. However by 85 * these messages WILL NOT be logged by default. In order to enable logging, 86 * the FASTRPC process will need to either call the 87 * HAP_SetFARFRuntimeLoggingParams() API, or by adding a <process_name>.farf 88 * file to the HLOS file system with the appropriate contents. 89 * 90 * #include "HAP_farf.h" 91 * FARF(RUNTIME_HIGH, "something happened: %s", (const char*)string); 92 * 93 */ 94 95 96 /* 97 * @param x, the FARF level defined to either 0 to disable compilation or 1 to enable. 98 * @param ..., format string and arguments. 99 */ 100 #define FARF(x, ...) _FARF_PASTE(_FARF_,_FARF_VAL(FARF_##x))(x, ##__VA_ARGS__) 101 102 /* by default _DEBUG turns on ALWAYS, HIGH, ERROR, FATAL 103 * 104 */ 105 #ifdef _DEBUG 106 #ifndef FARF_HIGH 107 #define FARF_HIGH 1 108 #endif 109 #ifndef FARF_ERROR 110 #define FARF_ERROR 1 111 #endif 112 #ifndef FARF_FATAL 113 #define FARF_FATAL 1 114 #endif 115 #endif 116 117 /* Compile time macros. Set these to 1 to enable logging at that 118 level. Setting them to 0 will cause them to be COMPILED out . 119 120 Example Usage: 121 #define FARF_HIGH 1 122 FARF(HIGH,"Log message"); 123 124 Defining _DEBUG will automatically enable compiled log messages with 125 priority higher than HIGH. 126 127 The ALWAYS macro will cause log messages to be ALWAYS compiled in. 128 FARF(ALWAYS,"Log message") 129 */ 130 131 #ifndef FARF_ALWAYS 132 #define FARF_ALWAYS 1 /* 0 turns me off */ 133 #endif 134 #define FARF_ALWAYS_LEVEL HAP_LEVEL_HIGH 135 136 #ifndef FARF_LOW 137 #define FARF_LOW 0 /* 0 turns me off */ 138 #endif 139 #define FARF_LOW_LEVEL HAP_LEVEL_LOW 140 141 #ifndef FARF_MEDIUM 142 #define FARF_MEDIUM 0 /* 0 turns me off */ 143 #endif 144 #define FARF_MEDIUM_LEVEL HAP_LEVEL_MEDIUM 145 146 #ifndef FARF_HIGH 147 #define FARF_HIGH 0 /* 0 turns me off */ 148 #endif 149 #define FARF_HIGH_LEVEL HAP_LEVEL_HIGH 150 151 #ifndef FARF_ERROR 152 #define FARF_ERROR 0 /* 0 turns me off */ 153 #endif 154 #define FARF_ERROR_LEVEL HAP_LEVEL_ERROR 155 156 #ifndef FARF_FATAL 157 #define FARF_FATAL 0 /* 0 turns me off */ 158 #endif 159 #define FARF_FATAL_LEVEL HAP_LEVEL_FATAL 160 161 /* Runtime FARF macros. FARFs with these levels can be enabled at runtime. 162 They are turned OFF by default. 163 164 Example Usage: 165 166 FARF(RUNTIME_HIGH,"Log message"); 167 */ 168 #ifndef FARF_RUNTIME_LOW 169 #define FARF_RUNTIME_LOW 1 /* 0 turns me off */ 170 #endif 171 #define FARF_RUNTIME_LOW_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_LOW) 172 173 #ifndef FARF_RUNTIME_MEDIUM 174 #define FARF_RUNTIME_MEDIUM 1 /* 0 turns me off */ 175 #endif 176 #define FARF_RUNTIME_MEDIUM_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_MEDIUM) 177 178 #ifndef FARF_RUNTIME_HIGH 179 #define FARF_RUNTIME_HIGH 1 /* 0 turns me off */ 180 #endif 181 #define FARF_RUNTIME_HIGH_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_HIGH) 182 183 #ifndef FARF_RUNTIME_ERROR 184 #define FARF_RUNTIME_ERROR 1 /* 0 turns me off */ 185 #endif 186 #define FARF_RUNTIME_ERROR_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_ERROR) 187 188 #ifndef FARF_RUNTIME_FATAL 189 #define FARF_RUNTIME_FATAL 1 /* 0 turns me off */ 190 #endif 191 #define FARF_RUNTIME_FATAL_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_FATAL) 192 193 //internal macros 194 #define _FARF_PASTE(a,b) _FARF_PASTE_(a,b) 195 #define _FARF_PASTE_(a,b) a##b 196 #define _FARF_VAL(a) a 197 198 //internal macro 199 //this one is used when farfs are not compiled in 200 #define _FARF_0(x, ...) 201 202 #ifndef __FILENAME__ 203 #define __FILENAME__ __FILE__ 204 #endif 205 206 //lint -emacro(506,FARF) Constant Boolean Value 207 //lint -emacro(774,FARF) Boolean within always evaluates to True 208 //this one is used when farfs are compiled in 209 #define _FARF_1(x, ...) \ 210 do { \ 211 if(0 == (HAP_debug_v2)) { \ 212 _HAP_debug_v2(FARF_##x##_LEVEL, __FILENAME__, __LINE__, ##__VA_ARGS__); \ 213 } else { \ 214 if (FARF_##x##_LEVEL & HAP_LEVEL_RUNTIME) { \ 215 if (0 != HAP_debug_runtime) { \ 216 HAP_debug_runtime(FARF_##x##_LEVEL ^ HAP_LEVEL_RUNTIME , __FILENAME__, __LINE__, ##__VA_ARGS__); \ 217 } else { \ 218 break; \ 219 } \ 220 } else { \ 221 HAP_debug_v2(FARF_##x##_LEVEL, __FILENAME__, __LINE__, ##__VA_ARGS__); \ 222 } \ 223 } \ 224 } while (0) 225 226 #endif /* #ifndef HAP_FARF_H */ 227