|
reporter.h00001 /* 00002 Copyright (C) 2001 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __IVARIA_REPORTER_H__ 00020 #define __IVARIA_REPORTER_H__ 00021 00022 #include <stdarg.h> 00023 #include "csutil/scf.h" 00024 #include "cssys/sysfunc.h" 00025 #include "iutil/objreg.h" 00026 00027 struct iReporter; 00028 00034 #define CS_REPORTER_SEVERITY_BUG 0 00035 00041 #define CS_REPORTER_SEVERITY_ERROR 1 00042 00047 #define CS_REPORTER_SEVERITY_WARNING 2 00048 00053 #define CS_REPORTER_SEVERITY_NOTIFY 3 00054 00060 #define CS_REPORTER_SEVERITY_DEBUG 4 00061 00062 SCF_VERSION (iReporterListener, 0, 0, 1); 00063 00068 struct iReporterListener : public iBase 00069 { 00075 virtual bool Report (iReporter* reporter, int severity, const char* msgId, 00076 const char* description) = 0; 00077 }; 00078 00079 SCF_VERSION (iReporter, 0, 0, 3); 00080 00084 struct iReporter : public iBase 00085 { 00091 virtual void Report (int severity, const char* msgId, 00092 const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0; 00093 00097 virtual void ReportV (int severity, const char* msgId, 00098 const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0; 00099 00105 virtual void Clear (int severity = -1) = 0; 00106 00113 virtual void Clear (const char* mask) = 0; 00114 00118 virtual int GetMessageCount () const = 0; 00119 00123 virtual int GetMessageSeverity (int idx) const = 0; 00124 00128 virtual const char* GetMessageId (int idx) const = 0; 00129 00133 virtual const char* GetMessageDescription (int idx) const = 0; 00134 00141 virtual void AddReporterListener (iReporterListener* listener) = 0; 00142 00149 virtual void RemoveReporterListener (iReporterListener* listener) = 0; 00150 00154 virtual bool FindReporterListener (iReporterListener* listener) = 0; 00155 00156 //---------------------------------------------------------------------- 00157 // Conveniance functions, these are not to be implemented. 00158 //---------------------------------------------------------------------- 00159 00163 void CS_GNUC_PRINTF (3, 4) 00164 ReportError (const char* msgId, const char* description, ...) 00165 { 00166 va_list arg; 00167 va_start (arg, description); 00168 ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg); 00169 va_end (arg); 00170 } 00171 00175 void CS_GNUC_PRINTF (3, 4) 00176 ReportWarning (const char* msgId, const char* description, ...) 00177 { 00178 va_list arg; 00179 va_start (arg, description); 00180 ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg); 00181 va_end (arg); 00182 } 00183 00187 void CS_GNUC_PRINTF (3, 4) 00188 ReportNotify (const char* msgId, const char* description, ...) 00189 { 00190 va_list arg; 00191 va_start (arg, description); 00192 ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg); 00193 va_end (arg); 00194 } 00195 00199 void CS_GNUC_PRINTF (3, 4) 00200 ReportBug (const char* msgId, const char* description, ...) 00201 { 00202 va_list arg; 00203 va_start (arg, description); 00204 ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg); 00205 va_end (arg); 00206 } 00207 00211 void CS_GNUC_PRINTF (3, 4) 00212 ReportDebug (const char* msgId, const char* description, ...) 00213 { 00214 va_list arg; 00215 va_start (arg, description); 00216 ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg); 00217 va_end (arg); 00218 } 00219 }; 00220 00221 00222 /* 00223 * Helper class for csReport(). Not all compilers allow a bare `vararg' 00224 * function to be inlined, but wrapping the function in a class seems to 00225 * appease such compilers. The NextStep compiler exhibits this particular 00226 * behavior. 00227 */ 00228 class csReporterHelper 00229 { 00230 public: 00231 static void CS_GNUC_PRINTF (4, 0) 00232 ReportV(iObjectRegistry* reg, int severity, char const* msgId, 00233 char const* description, va_list args) 00234 { 00235 iReporter* reporter = CS_QUERY_REGISTRY(reg, iReporter); 00236 if (reporter) 00237 { 00238 reporter->ReportV(severity, msgId, description, args); 00239 reporter->DecRef (); 00240 } 00241 else 00242 { 00243 csPrintfV(description, args); 00244 csPrintf("\n"); 00245 } 00246 } 00247 00248 static void CS_GNUC_PRINTF (4, 5) 00249 Report(iObjectRegistry* reg, int severity, char const* msgId, 00250 char const* description, ...) 00251 { 00252 va_list arg; 00253 va_start(arg, description); 00254 00255 ReportV(reg,severity,msgId,description,arg); 00256 00257 va_end (arg); 00258 } 00259 }; 00260 00265 #define csReport csReporterHelper::Report 00266 #define csReportV csReporterHelper::ReportV 00267 00268 #endif // __IVARIA_REPORTER_H__ 00269 Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |