CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 <stdarg.h>
00023 #include "csutil/scf.h"
00024 #include "csutil/sysfunc.h"
00025 #include "iutil/objreg.h"
00026 
00033 struct iReporter;
00034 
00042 #define CS_REPORTER_SEVERITY_BUG 0
00043 
00049 #define CS_REPORTER_SEVERITY_ERROR 1
00050 
00055 #define CS_REPORTER_SEVERITY_WARNING 2
00056 
00061 #define CS_REPORTER_SEVERITY_NOTIFY 3
00062 
00068 #define CS_REPORTER_SEVERITY_DEBUG 4
00069 
00071 SCF_VERSION (iReporterListener, 0, 0, 1);
00072 
00077 struct iReporterListener : public iBase
00078 {
00084   virtual bool Report (iReporter* reporter, int severity, const char* msgId,
00085         const char* description) = 0;
00086 };
00087 
00088 SCF_VERSION (iReporterIterator, 0, 0, 1);
00089 
00093 struct iReporterIterator : public iBase
00094 {
00096   virtual bool HasNext () = 0;
00101   virtual void Next () = 0;
00102 
00106   virtual int GetMessageSeverity () const = 0;
00107 
00111   virtual const char* GetMessageId () const = 0;
00112 
00116   virtual const char* GetMessageDescription () const = 0;
00117 };
00118 
00119 SCF_VERSION (iReporter, 0, 1, 0);
00120 
00124 struct iReporter : public iBase
00125 {
00131   virtual void Report (int severity, const char* msgId,
00132         const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00133 
00137   virtual void ReportV (int severity, const char* msgId,
00138         const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00139 
00145   virtual void Clear (int severity = -1) = 0;
00146 
00153   virtual void Clear (const char* mask) = 0;
00154 
00159   virtual csPtr<iReporterIterator> GetMessageIterator () = 0;
00160 
00167   virtual void AddReporterListener (iReporterListener* listener) = 0;
00168 
00175   virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00176 
00180   virtual bool FindReporterListener (iReporterListener* listener) = 0;
00181 
00182   //----------------------------------------------------------------------
00183   // Convenience functions, these are not to be implemented in the plugin.
00184   //----------------------------------------------------------------------
00185 
00189   inline void ReportError (const char* msgId, const char* description, ...)
00190     CS_GNUC_PRINTF (3, 4);
00191 
00195   inline void ReportWarning (const char* msgId, const char* description, ...)
00196     CS_GNUC_PRINTF (3, 4);
00197 
00201   inline void ReportNotify (const char* msgId, const char* description, ...)
00202     CS_GNUC_PRINTF (3, 4);
00203 
00207   inline void ReportBug (const char* msgId, const char* description, ...)
00208     CS_GNUC_PRINTF (3, 4);
00209 
00213   inline void ReportDebug (const char* msgId, const char* description, ...)
00214     CS_GNUC_PRINTF (3, 4);
00215 };
00216 
00217 inline void iReporter::ReportError
00218   (const char* msgId, const char* description, ...)
00219 {
00220   va_list arg;
00221   va_start (arg, description);
00222   ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00223   va_end (arg);
00224 }
00225 
00226 inline void iReporter::ReportWarning
00227   (const char* msgId, const char* description, ...)
00228 {
00229   va_list arg;
00230   va_start (arg, description);
00231   ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00232   va_end (arg);
00233 }
00234 
00235 inline void iReporter::ReportNotify
00236   (const char* msgId, const char* description, ...)
00237 {
00238   va_list arg;
00239   va_start (arg, description);
00240   ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00241   va_end (arg);
00242 }
00243 
00244 inline void iReporter::ReportBug
00245   (const char* msgId, const char* description, ...)
00246 {
00247   va_list arg;
00248   va_start (arg, description);
00249   ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00250   va_end (arg);
00251 }
00252 
00253 inline void iReporter::ReportDebug
00254   (const char* msgId, const char* description, ...)
00255 {
00256   va_list arg;
00257   va_start (arg, description);
00258   ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00259   va_end (arg);
00260 }
00261 
00262 
00269 class csReporterHelper
00270 {
00271 public:
00277   static inline void ReportV(iObjectRegistry* reg, int severity,
00278     char const* msgId, char const* description, va_list args)
00279     CS_GNUC_PRINTF (4, 0);
00280 
00286   static inline void Report(iObjectRegistry* reg, int severity,
00287     char const* msgId, char const* description, ...)
00288     CS_GNUC_PRINTF (4, 5);
00289 };
00290 
00291 inline void csReporterHelper::ReportV(iObjectRegistry* reg, int severity,
00292   char const* msgId, char const* description, va_list args)
00293 {
00294   csRef<iReporter> reporter;
00295   if (reg && (reporter = CS_QUERY_REGISTRY (reg, iReporter)))
00296     reporter->ReportV (severity, msgId, description, args);
00297   else
00298   {
00299     /*
00300       @@@ The strncasecmp()s are there because sometimes reported messages
00301       start with "Warning", and a "Warning: Warning" output looks rather
00302       crappy. The correct fix is obviously to remove "Warning" prefixes
00303       when the reporter is used.
00304      */
00305     switch (severity)
00306     {
00307       case CS_REPORTER_SEVERITY_BUG:
00308         csPrintf("BUG: ");
00309         break;
00310       case CS_REPORTER_SEVERITY_ERROR:
00311         if (strncasecmp (description, "error", 5) != 0)
00312           csPrintf("ERROR: ");
00313         break;
00314       case CS_REPORTER_SEVERITY_WARNING:
00315         if (strncasecmp (description, "warning", 7) != 0)
00316           csPrintf("WARNING: ");
00317         break;
00318       case CS_REPORTER_SEVERITY_NOTIFY:
00319         csPrintf("NOTIFY: ");
00320         break;
00321       case CS_REPORTER_SEVERITY_DEBUG:
00322         csPrintf("DEBUG: ");
00323         break;
00324     }
00325     csPrintfV(description, args);
00326     csPrintf("\n");
00327   }
00328 }
00329 
00330 inline void csReporterHelper::Report(iObjectRegistry* reg, int severity,
00331   char const* msgId, char const* description, ...)
00332 {
00333   va_list arg;
00334   va_start(arg, description);
00335 
00336   ReportV(reg,severity,msgId,description,arg);
00337 
00338   va_end (arg);
00339 }
00340 
00344 #define csReport csReporterHelper::Report
00345 
00348 #define csReportV csReporterHelper::ReportV
00349 
00350 /* @} */
00351 
00352 #endif // __CS_IVARIA_REPORTER_H__
00353 

Generated for Crystal Space by doxygen 1.2.18