CrystalSpace

Public API Reference

ivaria/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 "csutil/ansicommand.h"
00023 #include "csutil/scf_interface.h"
00024 #include "csutil/sysfunc.h"
00025 #include "csutil/util.h"
00026 #include "iutil/objreg.h"
00027 
00034 struct iReporter;
00035 
00043 #define CS_REPORTER_SEVERITY_BUG 0
00044 
00050 #define CS_REPORTER_SEVERITY_ERROR 1
00051 
00056 #define CS_REPORTER_SEVERITY_WARNING 2
00057 
00062 #define CS_REPORTER_SEVERITY_NOTIFY 3
00063 
00069 #define CS_REPORTER_SEVERITY_DEBUG 4
00070 
00084 struct iReporterListener : public virtual iBase
00085 {
00086   SCF_INTERFACE (iReporterListener, 1, 0, 0);
00087 
00093   virtual bool Report (iReporter* reporter, int severity, const char* msgId,
00094         const char* description) = 0;
00095 };
00096 
00104 struct iReporterIterator : public virtual iBase
00105 {
00106   SCF_INTERFACE(iReporterIterator, 2, 0, 0);
00107 
00109   virtual bool HasNext () = 0;
00114   virtual void Next () = 0;
00115 
00119   virtual int GetMessageSeverity () const = 0;
00120 
00124   virtual const char* GetMessageId () const = 0;
00125 
00129   virtual const char* GetMessageDescription () const = 0;
00130 };
00131 
00152 struct iReporter : public virtual iBase
00153 {
00154   SCF_INTERFACE(iReporter, 2, 0, 0);
00155 
00162   virtual void Report (int severity, const char* msgId,
00163         const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00164 
00169   virtual void ReportV (int severity, const char* msgId,
00170         const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00171 
00177   virtual void Clear (int severity = -1) = 0;
00178 
00185   virtual void Clear (const char* mask) = 0;
00186 
00191   virtual csPtr<iReporterIterator> GetMessageIterator () = 0;
00192 
00199   virtual void AddReporterListener (iReporterListener* listener) = 0;
00200 
00207   virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00208 
00212   virtual bool FindReporterListener (iReporterListener* listener) = 0;
00213 
00214   //----------------------------------------------------------------------
00215   // Convenience functions, these are not to be implemented in the plugin.
00216   //----------------------------------------------------------------------
00217 
00222   inline void ReportError (const char* msgId, const char* description, ...)
00223     CS_GNUC_PRINTF (3, 4);
00224 
00229   inline void ReportWarning (const char* msgId, const char* description, ...)
00230     CS_GNUC_PRINTF (3, 4);
00231 
00236   inline void ReportNotify (const char* msgId, const char* description, ...)
00237     CS_GNUC_PRINTF (3, 4);
00238 
00243   inline void ReportBug (const char* msgId, const char* description, ...)
00244     CS_GNUC_PRINTF (3, 4);
00245 
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:
00315   static inline void ReportV(iObjectRegistry* reg, int severity,
00316     char const* msgId, char const* description, va_list args)
00317     CS_GNUC_PRINTF (4, 0);
00318 
00325   static inline void Report(iObjectRegistry* reg, int severity,
00326     char const* msgId, char const* description, ...)
00327     CS_GNUC_PRINTF (4, 5);
00328 };
00329 
00330 inline void csReporterHelper::ReportV(iObjectRegistry* reg, int severity,
00331   char const* msgId, char const* description, va_list args)
00332 {
00333   csRef<iReporter> reporter;
00334   if (reg && (reporter = csQueryRegistry<iReporter> (reg)))
00335     reporter->ReportV (severity, msgId, description, args);
00336   else
00337   {
00338     /*
00339       \todo The csStrNCaseCmp()s are there because sometimes reported messages
00340       start with "Warning", and a "Warning: Warning" output looks rather
00341       crappy. The correct fix is obviously to remove "Warning" prefixes
00342       when the reporter is used.
00343      */
00344     switch (severity)
00345     {
00346       case CS_REPORTER_SEVERITY_BUG:
00347         csPrintf (CS_ANSI_FM CS_ANSI_TEXT_BOLD_ON "BUG: " CS_ANSI_RST);
00348         break;
00349       case CS_REPORTER_SEVERITY_ERROR:
00350         if (csStrNCaseCmp (description, "error", 5) != 0)
00351           csPrintf (CS_ANSI_FR CS_ANSI_TEXT_BOLD_ON "ERROR: " CS_ANSI_RST);
00352         break;
00353       case CS_REPORTER_SEVERITY_WARNING:
00354         if (csStrNCaseCmp (description, "warning", 7) != 0)
00355           csPrintf (CS_ANSI_FY CS_ANSI_TEXT_BOLD_ON "WARNING: " CS_ANSI_RST);
00356         break;
00357       case CS_REPORTER_SEVERITY_NOTIFY:
00358         csPrintf ("NOTIFY: ");
00359         break;
00360       case CS_REPORTER_SEVERITY_DEBUG:
00361         csPrintf (CS_ANSI_FW CS_ANSI_TEXT_BOLD_ON "DEBUG: " CS_ANSI_RST);
00362         break;
00363     }
00364     csPrintfV(description, args);
00365     csPrintf("\n");
00366   }
00367 }
00368 
00369 inline void csReporterHelper::Report(iObjectRegistry* reg, int severity,
00370   char const* msgId, char const* description, ...)
00371 {
00372   va_list arg;
00373   va_start(arg, description);
00374 
00375   ReportV(reg,severity,msgId,description,arg);
00376 
00377   va_end (arg);
00378 }
00379 
00383 #define csReport csReporterHelper::Report
00384 
00387 #define csReportV csReporterHelper::ReportV
00388 
00389 /* @} */
00390 
00391 #endif // __CS_IVARIA_REPORTER_H__
00392 

Generated for Crystal Space 1.2.1 by doxygen 1.5.3