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 
00087 struct iReporterListener : public iBase
00088 {
00094   virtual bool Report (iReporter* reporter, int severity, const char* msgId,
00095         const char* description) = 0;
00096 };
00097 
00098 SCF_VERSION (iReporterIterator, 0, 0, 1);
00099 
00108 struct iReporterIterator : public iBase
00109 {
00111   virtual bool HasNext () = 0;
00116   virtual void Next () = 0;
00117 
00121   virtual int GetMessageSeverity () const = 0;
00122 
00126   virtual const char* GetMessageId () const = 0;
00127 
00131   virtual const char* GetMessageDescription () const = 0;
00132 };
00133 
00134 SCF_VERSION (iReporter, 0, 1, 0);
00135 
00159 struct iReporter : public iBase
00160 {
00166   virtual void Report (int severity, const char* msgId,
00167         const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00168 
00172   virtual void ReportV (int severity, const char* msgId,
00173         const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00174 
00180   virtual void Clear (int severity = -1) = 0;
00181 
00188   virtual void Clear (const char* mask) = 0;
00189 
00194   virtual csPtr<iReporterIterator> GetMessageIterator () = 0;
00195 
00202   virtual void AddReporterListener (iReporterListener* listener) = 0;
00203 
00210   virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00211 
00215   virtual bool FindReporterListener (iReporterListener* listener) = 0;
00216 
00217   //----------------------------------------------------------------------
00218   // Convenience functions, these are not to be implemented in the plugin.
00219   //----------------------------------------------------------------------
00220 
00224   inline void ReportError (const char* msgId, const char* description, ...)
00225     CS_GNUC_PRINTF (3, 4);
00226 
00230   inline void ReportWarning (const char* msgId, const char* description, ...)
00231     CS_GNUC_PRINTF (3, 4);
00232 
00236   inline void ReportNotify (const char* msgId, const char* description, ...)
00237     CS_GNUC_PRINTF (3, 4);
00238 
00242   inline void ReportBug (const char* msgId, const char* description, ...)
00243     CS_GNUC_PRINTF (3, 4);
00244 
00248   inline void ReportDebug (const char* msgId, const char* description, ...)
00249     CS_GNUC_PRINTF (3, 4);
00250 };
00251 
00252 inline void iReporter::ReportError
00253   (const char* msgId, const char* description, ...)
00254 {
00255   va_list arg;
00256   va_start (arg, description);
00257   ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00258   va_end (arg);
00259 }
00260 
00261 inline void iReporter::ReportWarning
00262   (const char* msgId, const char* description, ...)
00263 {
00264   va_list arg;
00265   va_start (arg, description);
00266   ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00267   va_end (arg);
00268 }
00269 
00270 inline void iReporter::ReportNotify
00271   (const char* msgId, const char* description, ...)
00272 {
00273   va_list arg;
00274   va_start (arg, description);
00275   ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00276   va_end (arg);
00277 }
00278 
00279 inline void iReporter::ReportBug
00280   (const char* msgId, const char* description, ...)
00281 {
00282   va_list arg;
00283   va_start (arg, description);
00284   ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00285   va_end (arg);
00286 }
00287 
00288 inline void iReporter::ReportDebug
00289   (const char* msgId, const char* description, ...)
00290 {
00291   va_list arg;
00292   va_start (arg, description);
00293   ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00294   va_end (arg);
00295 }
00296 
00297 
00304 class csReporterHelper
00305 {
00306 public:
00312   static inline void ReportV(iObjectRegistry* reg, int severity,
00313     char const* msgId, char const* description, va_list args)
00314     CS_GNUC_PRINTF (4, 0);
00315 
00321   static inline void Report(iObjectRegistry* reg, int severity,
00322     char const* msgId, char const* description, ...)
00323     CS_GNUC_PRINTF (4, 5);
00324 };
00325 
00326 inline void csReporterHelper::ReportV(iObjectRegistry* reg, int severity,
00327   char const* msgId, char const* description, va_list args)
00328 {
00329   csRef<iReporter> reporter;
00330   if (reg && (reporter = CS_QUERY_REGISTRY (reg, iReporter)))
00331     reporter->ReportV (severity, msgId, description, args);
00332   else
00333   {
00334     /*
00335       @@@ The strncasecmp()s are there because sometimes reported messages
00336       start with "Warning", and a "Warning: Warning" output looks rather
00337       crappy. The correct fix is obviously to remove "Warning" prefixes
00338       when the reporter is used.
00339      */
00340     switch (severity)
00341     {
00342       case CS_REPORTER_SEVERITY_BUG:
00343         csPrintf("BUG: ");
00344         break;
00345       case CS_REPORTER_SEVERITY_ERROR:
00346         if (strncasecmp (description, "error", 5) != 0)
00347           csPrintf("ERROR: ");
00348         break;
00349       case CS_REPORTER_SEVERITY_WARNING:
00350         if (strncasecmp (description, "warning", 7) != 0)
00351           csPrintf("WARNING: ");
00352         break;
00353       case CS_REPORTER_SEVERITY_NOTIFY:
00354         csPrintf("NOTIFY: ");
00355         break;
00356       case CS_REPORTER_SEVERITY_DEBUG:
00357         csPrintf("DEBUG: ");
00358         break;
00359     }
00360     csPrintfV(description, args);
00361     csPrintf("\n");
00362   }
00363 }
00364 
00365 inline void csReporterHelper::Report(iObjectRegistry* reg, int severity,
00366   char const* msgId, char const* description, ...)
00367 {
00368   va_list arg;
00369   va_start(arg, description);
00370 
00371   ReportV(reg,severity,msgId,description,arg);
00372 
00373   va_end (arg);
00374 }
00375 
00379 #define csReport csReporterHelper::Report
00380 
00383 #define csReportV csReporterHelper::ReportV
00384 
00385 /* @} */
00386 
00387 #endif // __CS_IVARIA_REPORTER_H__
00388 

Generated for Crystal Space by doxygen 1.2.18