Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
reporter.h
Go to the documentation of this file.00001 /* 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 __CS_IVARIA_REPORTER_H__ 00020 #define __CS_IVARIA_REPORTER_H__ 00021 00022 #include <stdarg.h> 00023 #include "csutil/ansicolor.h" 00024 #include "csutil/scf.h" 00025 #include "csutil/sysfunc.h" 00026 #include "csutil/util.h" 00027 #include "iutil/objreg.h" 00028 00035 struct iReporter; 00036 00044 #define CS_REPORTER_SEVERITY_BUG 0 00045 00051 #define CS_REPORTER_SEVERITY_ERROR 1 00052 00057 #define CS_REPORTER_SEVERITY_WARNING 2 00058 00063 #define CS_REPORTER_SEVERITY_NOTIFY 3 00064 00070 #define CS_REPORTER_SEVERITY_DEBUG 4 00071 00073 SCF_VERSION (iReporterListener, 0, 0, 1); 00074 00089 struct iReporterListener : public iBase 00090 { 00096 virtual bool Report (iReporter* reporter, int severity, const char* msgId, 00097 const char* description) = 0; 00098 }; 00099 00100 SCF_VERSION (iReporterIterator, 0, 0, 1); 00101 00110 struct iReporterIterator : public iBase 00111 { 00113 virtual bool HasNext () = 0; 00118 virtual void Next () = 0; 00119 00123 virtual int GetMessageSeverity () const = 0; 00124 00128 virtual const char* GetMessageId () const = 0; 00129 00133 virtual const char* GetMessageDescription () const = 0; 00134 }; 00135 00136 SCF_VERSION (iReporter, 0, 1, 0); 00137 00161 struct iReporter : public iBase 00162 { 00168 virtual void Report (int severity, const char* msgId, 00169 const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0; 00170 00174 virtual void ReportV (int severity, const char* msgId, 00175 const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0; 00176 00182 virtual void Clear (int severity = -1) = 0; 00183 00190 virtual void Clear (const char* mask) = 0; 00191 00196 virtual csPtr<iReporterIterator> GetMessageIterator () = 0; 00197 00204 virtual void AddReporterListener (iReporterListener* listener) = 0; 00205 00212 virtual void RemoveReporterListener (iReporterListener* listener) = 0; 00213 00217 virtual bool FindReporterListener (iReporterListener* listener) = 0; 00218 00219 //---------------------------------------------------------------------- 00220 // Convenience functions, these are not to be implemented in the plugin. 00221 //---------------------------------------------------------------------- 00222 00226 inline void ReportError (const char* msgId, const char* description, ...) 00227 CS_GNUC_PRINTF (3, 4); 00228 00232 inline void ReportWarning (const char* msgId, const char* description, ...) 00233 CS_GNUC_PRINTF (3, 4); 00234 00238 inline void ReportNotify (const char* msgId, const char* description, ...) 00239 CS_GNUC_PRINTF (3, 4); 00240 00244 inline void ReportBug (const char* msgId, const char* description, ...) 00245 CS_GNUC_PRINTF (3, 4); 00246 00250 inline void ReportDebug (const char* msgId, const char* description, ...) 00251 CS_GNUC_PRINTF (3, 4); 00252 }; 00253 00254 inline void iReporter::ReportError 00255 (const char* msgId, const char* description, ...) 00256 { 00257 va_list arg; 00258 va_start (arg, description); 00259 ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg); 00260 va_end (arg); 00261 } 00262 00263 inline void iReporter::ReportWarning 00264 (const char* msgId, const char* description, ...) 00265 { 00266 va_list arg; 00267 va_start (arg, description); 00268 ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg); 00269 va_end (arg); 00270 } 00271 00272 inline void iReporter::ReportNotify 00273 (const char* msgId, const char* description, ...) 00274 { 00275 va_list arg; 00276 va_start (arg, description); 00277 ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg); 00278 va_end (arg); 00279 } 00280 00281 inline void iReporter::ReportBug 00282 (const char* msgId, const char* description, ...) 00283 { 00284 va_list arg; 00285 va_start (arg, description); 00286 ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg); 00287 va_end (arg); 00288 } 00289 00290 inline void iReporter::ReportDebug 00291 (const char* msgId, const char* description, ...) 00292 { 00293 va_list arg; 00294 va_start (arg, description); 00295 ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg); 00296 va_end (arg); 00297 } 00298 00299 00306 class csReporterHelper 00307 { 00308 public: 00314 static inline void ReportV(iObjectRegistry* reg, int severity, 00315 char const* msgId, char const* description, va_list args) 00316 CS_GNUC_PRINTF (4, 0); 00317 00323 static inline void Report(iObjectRegistry* reg, int severity, 00324 char const* msgId, char const* description, ...) 00325 CS_GNUC_PRINTF (4, 5); 00326 }; 00327 00328 inline void csReporterHelper::ReportV(iObjectRegistry* reg, int severity, 00329 char const* msgId, char const* description, va_list args) 00330 { 00331 csRef<iReporter> reporter; 00332 if (reg && (reporter = CS_QUERY_REGISTRY (reg, iReporter))) 00333 reporter->ReportV (severity, msgId, description, args); 00334 else 00335 { 00336 /* 00337 @@@ The csStrNCaseCmp()s are there because sometimes reported messages 00338 start with "Warning", and a "Warning: Warning" output looks rather 00339 crappy. The correct fix is obviously to remove "Warning" prefixes 00340 when the reporter is used. 00341 */ 00342 switch (severity) 00343 { 00344 case CS_REPORTER_SEVERITY_BUG: 00345 csPrintf(CS_ANSI_BK CS_ANSI_FM CS_ANSI_FI "BUG: " CS_ANSI_RST); 00346 break; 00347 case CS_REPORTER_SEVERITY_ERROR: 00348 if (csStrNCaseCmp (description, "error", 5) != 0) 00349 csPrintf(CS_ANSI_BK CS_ANSI_FR CS_ANSI_FI "ERROR: " CS_ANSI_RST); 00350 break; 00351 case CS_REPORTER_SEVERITY_WARNING: 00352 if (csStrNCaseCmp (description, "warning", 7) != 0) 00353 csPrintf(CS_ANSI_BK CS_ANSI_FY CS_ANSI_FI "WARNING: " CS_ANSI_RST); 00354 break; 00355 case CS_REPORTER_SEVERITY_NOTIFY: 00356 csPrintf ("NOTIFY: "); 00357 break; 00358 case CS_REPORTER_SEVERITY_DEBUG: 00359 csPrintf(CS_ANSI_BK CS_ANSI_FW CS_ANSI_FI "DEBUG: " CS_ANSI_RST); 00360 break; 00361 } 00362 csPrintfV(description, args); 00363 csPrintf("\n"); 00364 } 00365 } 00366 00367 inline void csReporterHelper::Report(iObjectRegistry* reg, int severity, 00368 char const* msgId, char const* description, ...) 00369 { 00370 va_list arg; 00371 va_start(arg, description); 00372 00373 ReportV(reg,severity,msgId,description,arg); 00374 00375 va_end (arg); 00376 } 00377 00381 #define csReport csReporterHelper::Report 00382 00385 #define csReportV csReporterHelper::ReportV 00386 00387 /* @} */ 00388 00389 #endif // __CS_IVARIA_REPORTER_H__ 00390
Generated for Crystal Space by doxygen 1.3.9.1