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