]> git.mxchange.org Git - flightgear.git/blob - Debug/fg_debug.h
5a818697adde03289fac148ff0386262c76fd28e
[flightgear.git] / 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
27 #ifndef _FG_DEBUG_H
28 #define _FG_DEBUG_H
29
30 #ifdef __cplusplus                                                          
31 extern "C" {                            
32 #endif                                   
33
34
35 #include <stdio.h>
36
37 /* NB: To add a dbg_class, add it here, and add it to the structure in
38    fg_debug.c */
39 typedef enum {
40     FG_NONE      = 0x00000000,
41
42     FG_TERRAIN   = 0x00000001,
43     FG_ASTRO     = 0x00000002,
44     FG_FLIGHT    = 0x00000004,
45     FG_INPUT     = 0x00000008,
46     FG_GL        = 0x00000010,
47     FG_VIEW      = 0x00000020,
48     FG_COCKPIT   = 0x00000040,
49     FG_GENERAL   = 0x00000080,
50     FG_MATH      = 0x00000100,
51     FG_EVENT     = 0x00000200,
52     FG_AIRCRAFT  = 0x00000400,
53     FG_AUTOPILOT = 0x00000800,
54     FG_UNDEFD    = 0x00001000, // For range checking
55
56     FG_ALL     = 0xFFFFFFFF
57 } fgDebugClass;
58
59 /* NB: To add a priority, add it here. */
60 typedef enum  {
61     FG_BULK,        /* For frequent messages */
62     FG_DEBUG,       /* Less frequent debug type messages */
63     FG_INFO,          /* Informatory messages */
64     FG_WARN,        /* Possible impending problem */
65     FG_ALERT,         /* Very possible impending problem */
66     FG_EXIT,          /* Problem (no core) */
67     FG_ABORT          /* Abandon ship (core) */
68 } fgDebugPriority;
69
70
71 /* Initialize the debuggin stuff. */
72 void fgInitDebug( void );
73
74
75 /* fgPrintf
76
77    Expects:
78    class      fgDebugClass mask for this message.
79    prio       fgDebugPriority of this message.
80    fmt        printf like string format
81    ...        var args for fmt
82
83    Returns:
84    number of items in fmt handled.
85
86    This function works like the standard C library function printf() with
87    the addition of message classes and priorities (see fgDebugClasses
88    and fgDebugPriorities).  These additions allow us to classify messages
89    and disable sets of messages at runtime.  Only messages with a prio
90    greater than or equal to fg_DebugPriority and in the current debug class 
91    (fg_DebugClass) are printed.
92 */
93 int fgPrintf( fgDebugClass dbg_class, fgDebugPriority prio, char *fmt, ... ); 
94
95
96 /* fgSetDebugLevels()
97
98    Expects:
99    dbg_class      Bitmask representing classes to display.
100    prio       Minimum priority of messages to display.
101 */
102 void fgSetDebugLevels( fgDebugClass dbg_class, fgDebugPriority prio );
103
104 /* fgSetDebugOutput()
105
106    Expects:
107    file       A FILE* to a stream to send messages to.  
108
109    It is assumed the file stream is open and writable.  The system
110    defaults to stderr.  The current stream is flushed but not
111    closed.
112 */
113 void fgSetDebugOutput( FILE *out );
114
115
116 /* fgRegisterDebugCallback
117
118    Expects:
119    callback   A function that takes parameters as defined by the 
120               fgDebugCallback type.
121
122    Returns:
123    a pointer to the previously registered callback (if any)
124   
125    Install a user defined debug log callback.   This callback is called w
126    whenever fgPrintf is called.  The parameters passed to the callback are
127    defined above by fgDebugCallback.  outstr is the string that is to be
128    printed.  If callback returns nonzero, it is assumed that the message
129    was handled fully by the callback and **fgPrintf need do no further 
130    processing of the message.**  Only one callback may be installed at a 
131    time.
132 */
133
134 //typedef int (*fgDebugCallback)(fgDebugClass, fgDebugPriority, char *outstr);
135 //fgDebugCallback fgRegisterDebugCallback( fgDebugCallback callback );
136
137 typedef int (*fgDebugCallback)( int DebugClass, int DebugPriority, char *outstr);
138 fgDebugCallback fgRegisterDebugCallback( fgDebugCallback callback );
139
140
141 // Leave these alone. Access intended for fg_debug and command line processing.
142 //
143 extern fgDebugClass    fg_DebugClass;
144 extern fgDebugPriority fg_DebugPriority;
145
146 extern FILE *          fg_DebugOutput;
147
148
149 #ifdef __cplusplus
150 }
151 #endif
152
153
154 #endif /* _FG_DEBUG_H */
155