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