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