00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/SysSupport/Messages.h"
00026 #ifndef SWIG
00027 #include <cstdio>
00028 #include <cstdlib>
00029 #include <cstdarg>
00030 #endif
00031
00032 namespace Teddy {
00033 namespace SysSupport {
00034
00035
00036 #define MAX_MSG_TYPES 64
00037 static bool msg_enable[MAX_MSG_TYPES];
00038 static char *msg_desc [MAX_MSG_TYPES];
00039 static int last_msg_type = 0;
00040
00041
00042 int M_FATAL;
00043 int M_ERROR;
00044 int M_WARN;
00045 int M_DEBUG;
00046 int M_INIT;
00047 int M_GL;
00048 int M_WM;
00049 int M_WMD;
00050 int M_WME;
00051 int M_WML;
00052 int M_MAT;
00053 int M_MOD;
00054 int M_SCN;
00055 int M_LWO;
00056 int M_LWS;
00057 int M_TMAP;
00058 int M_VERT;
00059 int M_AUDIO;
00060 int M_FFE;
00061 int M_NET;
00062
00063
00064 #if defined(_MSC_VER)
00065 # define MSG_DEST stdout
00066 #else
00067 # define MSG_DEST stderr
00068 #endif
00069
00070 void init_msg(){
00071 for( int i=0; i<MAX_MSG_TYPES; i++ ){
00072 msg_enable[i] = false;
00073 msg_desc [i] = NULL;
00074 }
00075 M_FATAL = alloc_msg( "Fatal: " ); enable_msg ( M_FATAL );
00076 M_ERROR = alloc_msg( "Error: " ); enable_msg ( M_ERROR );
00077 M_WARN = alloc_msg( "Warning: " ); enable_msg ( M_WARN );
00078 M_DEBUG = alloc_msg( "Debug: " ); enable_msg ( M_DEBUG );
00079 M_INIT = alloc_msg( "Init: " ); enable_msg ( M_INIT );
00080 M_GL = alloc_msg( "GL: " ); disable_msg( M_GL );
00081 M_WM = alloc_msg( "WM: " ); disable_msg( M_WM );
00082 M_WMD = alloc_msg( "WMD: " ); disable_msg( M_WMD );
00083 M_WME = alloc_msg( "WME: " ); disable_msg( M_WME );
00084 M_WML = alloc_msg( "WML: " ); disable_msg( M_WML );
00085 M_MAT = alloc_msg( "MAT: " ); disable_msg( M_MAT );
00086 M_MOD = alloc_msg( "MOD: " ); disable_msg( M_MOD );
00087 M_LWO = alloc_msg( "LWO: " ); disable_msg( M_LWO );
00088 M_LWS = alloc_msg( "LWS: " ); disable_msg( M_LWS );
00089 M_TMAP = alloc_msg( "TMAP: " ); disable_msg( M_TMAP );
00090 M_VERT = alloc_msg( "VERT: " ); disable_msg( M_VERT );
00091 M_FFE = alloc_msg( "FFE: " ); disable_msg( M_FFE );
00092 M_NET = alloc_msg( "NET: " ); disable_msg( M_NET );
00093 M_SCN = alloc_msg( "SCN: " ); disable_msg( M_SCN );
00094 M_AUDIO = alloc_msg( "AUD: " ); disable_msg( M_AUDIO );
00095 }
00096
00097
00098 int alloc_msg( char *desc ){
00099 msg_desc[last_msg_type] = desc;
00100 return last_msg_type++;
00101 }
00102
00103
00104 void enable_msg( int type ){
00105 if( (type >=0) && (type < last_msg_type) ){
00106 msg_enable[type] = true;
00107 }
00108 if( msg_desc[type] != NULL ){
00109
00110 }
00111 }
00112
00113
00114 void disable_msg( int type ){
00115 if( (type >=0) && (type < last_msg_type) ){
00116 msg_enable[type] = false;
00117 }
00118 if( msg_desc[type] != NULL ){
00119
00120 }
00121 }
00122
00123
00124 void msg( int type, char *format, ... ){
00125 if( (type >=0) && (type < last_msg_type) ){
00126 if( msg_enable[type] == true ){
00127 va_list ap;
00128
00129 va_start( ap, format );
00130
00131
00132
00133 vfprintf( MSG_DEST, format, ap );
00134 fprintf ( MSG_DEST, "\n" );
00135 va_end ( ap );
00136 }
00137 }
00138 }
00139
00140
00141 void dmsg( int type, char *format, ... ){
00142 if( (type >=0) && (type < last_msg_type) ){
00143 if( msg_enable[type] == true ){
00144 va_list ap;
00145
00146 va_start( ap, format );
00147 if( msg_desc[type] != NULL ){
00148 fprintf( MSG_DEST, msg_desc[type] );
00149 }
00150 vfprintf( MSG_DEST, format, ap );
00151 fprintf( MSG_DEST, "\n" );
00152 va_end ( ap );
00153 }
00154 }
00155 }
00156
00157
00158 void dprint( int type, char *format, ... ){
00159 if( (type >=0) && (type < last_msg_type) ){
00160 if( msg_enable[type] == true ){
00161 va_list ap;
00162 va_start( ap, format );
00163 vfprintf( MSG_DEST, format, ap );
00164 va_end ( ap );
00165 }
00166 }
00167 }
00168
00169
00170 void emsg( int type, char *format, ... ){
00171 if( (type >=0) && (type < last_msg_type) ){
00172 va_list ap;
00173
00174 va_start( ap, format );
00175 if( msg_desc[type] != NULL ){
00176 fprintf( MSG_DEST, msg_desc[type] );
00177 }
00178 vfprintf( MSG_DEST, format, ap );
00179 fprintf ( MSG_DEST, "\n" );
00180 va_end ( ap );
00181 }
00182 }
00183
00184
00185 void fmsg( int type, char *format, ... ){
00186 if( (type >=0) && (type < last_msg_type) ){
00187 va_list ap;
00188
00189 va_start( ap, format );
00190 if( msg_desc[type] != NULL ){
00191 fprintf( MSG_DEST, msg_desc[type] );
00192 }
00193 vfprintf( MSG_DEST, format, ap );
00194 fprintf ( MSG_DEST, "\n" );
00195 va_end ( ap );
00196 }
00197 exit( 1 );
00198 }
00199
00200
00201 };
00202 };
00203