1 #ifndef __gammu_common_debug_h 2 #define __gammu_common_debug_h 3 4 #include <gammu-debug.h> 5 #include <stdarg.h> 6 7 /* ------------------------------------------------------------------------- */ 8 9 10 extern GSM_Debug_Info GSM_global_debug; 11 extern GSM_Debug_Info GSM_none_debug; 12 13 void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize); 14 void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize); 15 16 17 /* ------------------------------------------------------------------------- */ 18 19 20 /** 21 * Debugging level. 22 */ 23 typedef enum { 24 DL_NONE = 0, /**< No debug messages */ 25 DL_BINARY = 1, /**< Binary transmission dump */ 26 DL_TEXT, /**< Text transmission dump */ 27 DL_TEXTALL, /**< Everything */ 28 DL_TEXTERROR, /**< Only errors */ 29 DL_TEXTDATE, /**< Text transmission dump */ 30 DL_TEXTALLDATE, /**< Everything */ 31 DL_TEXTERRORDATE /**< Only errors */ 32 } Debug_Level; 33 34 struct _GSM_Debug_Info { 35 Debug_Level dl; /**< Level of messages to display */ 36 FILE *df; /**< File used for debug messages output */ 37 gboolean use_global; /**< Whether to use global debug structure instead of this one. */ 38 const char *coding; /**< Encoding used in console */ 39 gboolean was_lf; /**< Has there already been new line */ 40 gboolean closable; /**< Whether Gammu can close the file when it is no longer needed for debug output. */ 41 /** 42 * Function which performs logging, in case it is set, no file logging happens. 43 */ 44 GSM_Log_Function log_function; 45 /** 46 * User data to be passed to callback. 47 */ 48 void * user_data; 49 }; 50 51 52 PRINTF_STYLE(2, 3) 53 int smfprintf(GSM_Debug_Info *d, const char *format, ...); 54 55 PRINTF_STYLE(2, 0) 56 int dbg_vprintf(GSM_Debug_Info *d, const char *format, va_list argp); 57 58 /** 59 * Prints string to global debug log. 60 * 61 * \param format Format string as for printf. 62 * \return Upon successful return, these functions return the number of characters printed (as printf). 63 * 64 * \ingroup Debug 65 */ 66 #ifdef DEBUG 67 #define dbgprintf smfprintf 68 #else 69 # ifdef __GNUC__ 70 # define dbgprintf(...) do { } while (0) 71 # else 72 # define dbgprintf 73 # endif 74 #endif 75 76 /** 77 * Severity of printed message. 78 */ 79 typedef enum { 80 /** 81 * Message will not be printed. 82 */ 83 D_NONE, 84 /** 85 * Message is printed in all text log levels. 86 */ 87 D_TEXT, 88 /** 89 * Message is printed on all text error log levels. 90 */ 91 D_ERROR 92 } GSM_DebugSeverity; 93 94 /** 95 * Prints string to defined debug log. 96 * 97 * \param s State machine, where to print. 98 * \param severity Severity of printed message. 99 * \param format Format string as for printf. 100 * \return Upon successful return, these functions return the number of characters printed (as printf). 101 * 102 * \ingroup Debug 103 */ 104 PRINTF_STYLE(3, 4) 105 int smprintf_level(GSM_StateMachine * s, GSM_DebugSeverity severity, const char *format, ...); 106 107 #endif 108