]> git.mxchange.org Git - flightgear.git/blob - Lib/Debug/fg_debug.h
Merge FG_Lib as subdirectory
[flightgear.git] / Lib / Debug / fg_debug.h
1 /* -*- Mode: C++ -*-
2  *
3  * fg_debug.h -- Flight Gear debug utility functions
4  *
5  * Written by Paul Bleisch, started January 1998. 
6  *
7  * Copyright (C) 1998 Paul Bleisch, pbleisch@acm.org
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26 #error "use logstream"
27
28 #ifndef _FG_DEBUG_H
29 #define _FG_DEBUG_H
30
31 #ifdef __cplusplus                                                          
32 extern "C" {                            
33 #endif                                   
34
35
36 #include <stdio.h>
37
38 /* NB: To add a dbg_class, add it here, and add it to the structure in
39    fg_debug.c */
40 typedef enum {
41     FG_NONE      = 0x00000000,
42
43     FG_TERRAIN   = 0x00000001,
44     FG_ASTRO     = 0x00000002,
45     FG_FLIGHT    = 0x00000004,
46     FG_INPUT     = 0x00000008,
47     FG_GL        = 0x00000010,
48     FG_VIEW      = 0x00000020,
49     FG_COCKPIT   = 0x00000040,
50     FG_GENERAL   = 0x00000080,
51     FG_MATH      = 0x00000100,
52     FG_EVENT     = 0x00000200,
53     FG_AIRCRAFT  = 0x00000400,
54     FG_AUTOPILOT = 0x00000800,
55     FG_UNDEFD    = 0x00001000, // For range checking
56
57     FG_ALL     = 0xFFFFFFFF
58 } fgDebugClass;
59
60 /* NB: To add a priority, add it here. */
61 typedef enum  {
62     FG_BULK,        /* For frequent messages */
63     FG_DEBUG,       /* Less frequent debug type messages */
64     FG_INFO,          /* Informatory messages */
65     FG_WARN,        /* Possible impending problem */
66     FG_ALERT,         /* Very possible impending problem */
67     FG_EXIT,          /* Problem (no core) */
68     FG_ABORT          /* Abandon ship (core) */
69 } fgDebugPriority;
70
71
72 /* Initialize the debuggin stuff. */
73 void fgInitDebug( void );
74
75
76 /* fgPrintf
77
78    Expects:
79    class      fgDebugClass mask for this message.
80    prio       fgDebugPriority of this message.
81    fmt        printf like string format
82    ...        var args for fmt
83
84    Returns:
85    number of items in fmt handled.
86
87    This function works like the standard C library function printf() with
88    the addition of message classes and priorities (see fgDebugClasses
89    and fgDebugPriorities).  These additions allow us to classify messages
90    and disable sets of messages at runtime.  Only messages with a prio
91    greater than or equal to fg_DebugPriority and in the current debug class 
92    (fg_DebugClass) are printed.
93 */
94 int fgPrintf( fgDebugClass dbg_class, fgDebugPriority prio, char *fmt, ... ); 
95
96
97 /* fgSetDebugLevels()
98
99    Expects:
100    dbg_class      Bitmask representing classes to display.
101    prio       Minimum priority of messages to display.
102 */
103 void fgSetDebugLevels( fgDebugClass dbg_class, fgDebugPriority prio );
104
105 /* fgSetDebugOutput()
106
107    Expects:
108    file       A FILE* to a stream to send messages to.  
109
110    It is assumed the file stream is open and writable.  The system
111    defaults to stderr.  The current stream is flushed but not
112    closed.
113 */
114 void fgSetDebugOutput( FILE *out );
115
116
117 /* fgRegisterDebugCallback
118
119    Expects:
120    callback   A function that takes parameters as defined by the 
121               fgDebugCallback type.
122
123    Returns:
124    a pointer to the previously registered callback (if any)
125   
126    Install a user defined debug log callback.   This callback is called w
127    whenever fgPrintf is called.  The parameters passed to the callback are
128    defined above by fgDebugCallback.  outstr is the string that is to be
129    printed.  If callback returns nonzero, it is assumed that the message
130    was handled fully by the callback and **fgPrintf need do no further 
131    processing of the message.**  Only one callback may be installed at a 
132    time.
133 */
134
135 //typedef int (*fgDebugCallback)(fgDebugClass, fgDebugPriority, char *outstr);
136 //fgDebugCallback fgRegisterDebugCallback( fgDebugCallback callback );
137
138 typedef int (*fgDebugCallback)( int DebugClass, int DebugPriority, char *outstr);
139 fgDebugCallback fgRegisterDebugCallback( fgDebugCallback callback );
140
141
142 // Leave these alone. Access intended for fg_debug and command line processing.
143 //
144 extern fgDebugClass    fg_DebugClass;
145 extern fgDebugPriority fg_DebugPriority;
146
147 extern FILE *          fg_DebugOutput;
148
149
150 #ifdef __cplusplus
151 }
152 #endif
153
154
155 #endif /* _FG_DEBUG_H */
156