CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | 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 "csutil/ansicolor.h"
00023 #include "csutil/scf.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 
00072 SCF_VERSION (iReporterListener, 0, 0, 1);
00073 
00088 struct iReporterListener : public iBase
00089 {
00095   virtual bool Report (iReporter* reporter, int severity, const char* msgId,
00096         const char* description) = 0;
00097 };
00098 
00099 SCF_VERSION (iReporterIterator, 0, 0, 1);
00100 
00109 struct iReporterIterator : public iBase
00110 {
00112   virtual bool HasNext () = 0;
00117   virtual void Next () = 0;
00118 
00122   virtual int GetMessageSeverity () const = 0;
00123 
00127   virtual const char* GetMessageId () const = 0;
00128 
00132   virtual const char* GetMessageDescription () const = 0;
00133 };
00134 
00135 SCF_VERSION (iReporter, 0, 1, 0);
00136 
00160 struct iReporter : public iBase
00161 {
00168   virtual void Report (int severity, const char* msgId,
00169         const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00170 
00175   virtual void ReportV (int severity, const char* msgId,
00176         const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00177 
00183   virtual void Clear (int severity = -1) = 0;
00184 
00191   virtual void Clear (const char* mask) = 0;
00192 
00197   virtual csPtr<iReporterIterator> GetMessageIterator () = 0;
00198 
00205   virtual void AddReporterListener (iReporterListener* listener) = 0;
00206 
00213   virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00214 
00218   virtual bool FindReporterListener (iReporterListener* listener) = 0;
00219 
00220   //----------------------------------------------------------------------
00221   // Convenience functions, these are not to be implemented in the plugin.
00222   //----------------------------------------------------------------------
00223 
00228   inline void ReportError (const char* msgId, const char* description, ...)
00229     CS_GNUC_PRINTF (3, 4);
00230 
00235   inline void ReportWarning (const char* msgId, const char* description, ...)
00236     CS_GNUC_PRINTF (3, 4);
00237 
00242   inline void ReportNotify (const char* msgId, const char* description, ...)
00243     CS_GNUC_PRINTF (3, 4);
00244 
00249   inline void ReportBug (const char* msgId, const char* description, ...)
00250     CS_GNUC_PRINTF (3, 4);
00251 
00256   inline void ReportDebug (const char* msgId, const char* description, ...)
00257     CS_GNUC_PRINTF (3, 4);
00258 };
00259 
00260 inline void iReporter::ReportError
00261   (const char* msgId, const char* description, ...)
00262 {
00263   va_list arg;
00264   va_start (arg, description);
00265   ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00266   va_end (arg);
00267 }
00268 
00269 inline void iReporter::ReportWarning
00270   (const char* msgId, const char* description, ...)
00271 {
00272   va_list arg;
00273   va_start (arg, description);
00274   ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00275   va_end (arg);
00276 }
00277 
00278 inline void iReporter::ReportNotify
00279   (const char* msgId, const char* description, ...)
00280 {
00281   va_list arg;
00282   va_start (arg, description);
00283   ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00284   va_end (arg);
00285 }
00286 
00287 inline void iReporter::ReportBug
00288   (const char* msgId, const char* description, ...)
00289 {
00290   va_list arg;
00291   va_start (arg, description);
00292   ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00293   va_end (arg);
00294 }
00295 
00296 inline void iReporter::ReportDebug
00297   (const char* msgId, const char* description, ...)
00298 {
00299   va_list arg;
00300   va_start (arg, description);
00301   ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00302   va_end (arg);
00303 }
00304 
00305 
00312 class csReporterHelper
00313 {
00314 public:
00321   static inline void ReportV(iObjectRegistry* reg, int severity,
00322     char const* msgId, char const* description, va_list args)
00323     CS_GNUC_PRINTF (4, 0);
00324 
00331   static inline void Report(iObjectRegistry* reg, int severity,
00332     char const* msgId, char const* description, ...)
00333     CS_GNUC_PRINTF (4, 5);
00334 };
00335 
00336 inline void csReporterHelper::ReportV(iObjectRegistry* reg, int severity,
00337   char const* msgId, char const* description, va_list args)
00338 {
00339   csRef<iReporter> reporter;
00340   if (reg && (reporter = CS_QUERY_REGISTRY (reg, iReporter)))
00341     reporter->ReportV (severity, msgId, description, args);
00342   else
00343   {
00344     /*
00345       @@@ The csStrNCaseCmp()s are there because sometimes reported messages
00346       start with "Warning", and a "Warning: Warning" output looks rather
00347       crappy. The correct fix is obviously to remove "Warning" prefixes
00348       when the reporter is used.
00349      */
00350     switch (severity)
00351     {
00352       case CS_REPORTER_SEVERITY_BUG:
00353         csPrintf(CS_ANSI_BK CS_ANSI_FM CS_ANSI_FI "BUG: " CS_ANSI_RST);
00354         break;
00355       case CS_REPORTER_SEVERITY_ERROR:
00356         if (csStrNCaseCmp (description, "error", 5) != 0)
00357           csPrintf(CS_ANSI_BK CS_ANSI_FR CS_ANSI_FI "ERROR: " CS_ANSI_RST);
00358         break;
00359       case CS_REPORTER_SEVERITY_WARNING:
00360         if (csStrNCaseCmp (description, "warning", 7) != 0)
00361           csPrintf(CS_ANSI_BK CS_ANSI_FY CS_ANSI_FI "WARNING: " CS_ANSI_RST);
00362         break;
00363       case CS_REPORTER_SEVERITY_NOTIFY:
00364         csPrintf ("NOTIFY: ");
00365         break;
00366       case CS_REPORTER_SEVERITY_DEBUG:
00367         csPrintf(CS_ANSI_BK CS_ANSI_FW CS_ANSI_FI "DEBUG: " CS_ANSI_RST);
00368         break;
00369     }
00370     csPrintfV(description, args);
00371     csPrintf("\n");
00372   }
00373 }
00374 
00375 inline void csReporterHelper::Report(iObjectRegistry* reg, int severity,
00376   char const* msgId, char const* description, ...)
00377 {
00378   va_list arg;
00379   va_start(arg, description);
00380 
00381   ReportV(reg,severity,msgId,description,arg);
00382 
00383   va_end (arg);
00384 }
00385 
00389 #define csReport csReporterHelper::Report
00390 
00393 #define csReportV csReporterHelper::ReportV
00394 
00395 /* @} */
00396 
00397 #endif // __CS_IVARIA_REPORTER_H__
00398 

Generated for Crystal Space by doxygen 1.4.4