00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 "cssys/sysfunc.h"
00025 #include "iutil/objreg.h"
00026
00027 struct iReporter;
00028
00034 #define CS_REPORTER_SEVERITY_BUG 0
00035
00041 #define CS_REPORTER_SEVERITY_ERROR 1
00042
00047 #define CS_REPORTER_SEVERITY_WARNING 2
00048
00053 #define CS_REPORTER_SEVERITY_NOTIFY 3
00054
00060 #define CS_REPORTER_SEVERITY_DEBUG 4
00061
00062 SCF_VERSION (iReporterListener, 0, 0, 1);
00063
00068 struct iReporterListener : public iBase
00069 {
00075 virtual bool Report (iReporter* reporter, int severity, const char* msgId,
00076 const char* description) = 0;
00077 };
00078
00079 SCF_VERSION (iReporterIterator, 0, 0, 1);
00080
00084 struct iReporterIterator : public iBase
00085 {
00087 virtual bool HasNext () = 0;
00092 virtual void Next () = 0;
00093
00097 virtual int GetMessageSeverity () const = 0;
00098
00102 virtual const char* GetMessageId () const = 0;
00103
00107 virtual const char* GetMessageDescription () const = 0;
00108 };
00109
00110 SCF_VERSION (iReporter, 0, 1, 0);
00111
00115 struct iReporter : public iBase
00116 {
00122 virtual void Report (int severity, const char* msgId,
00123 const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00124
00128 virtual void ReportV (int severity, const char* msgId,
00129 const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00130
00136 virtual void Clear (int severity = -1) = 0;
00137
00144 virtual void Clear (const char* mask) = 0;
00145
00150 virtual csPtr<iReporterIterator> GetMessageIterator () = 0;
00151
00158 virtual void AddReporterListener (iReporterListener* listener) = 0;
00159
00166 virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00167
00171 virtual bool FindReporterListener (iReporterListener* listener) = 0;
00172
00173
00174
00175
00176
00180 void CS_GNUC_PRINTF (3, 4)
00181 ReportError (const char* msgId, const char* description, ...)
00182 {
00183 va_list arg;
00184 va_start (arg, description);
00185 ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00186 va_end (arg);
00187 }
00188
00192 void CS_GNUC_PRINTF (3, 4)
00193 ReportWarning (const char* msgId, const char* description, ...)
00194 {
00195 va_list arg;
00196 va_start (arg, description);
00197 ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00198 va_end (arg);
00199 }
00200
00204 void CS_GNUC_PRINTF (3, 4)
00205 ReportNotify (const char* msgId, const char* description, ...)
00206 {
00207 va_list arg;
00208 va_start (arg, description);
00209 ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00210 va_end (arg);
00211 }
00212
00216 void CS_GNUC_PRINTF (3, 4)
00217 ReportBug (const char* msgId, const char* description, ...)
00218 {
00219 va_list arg;
00220 va_start (arg, description);
00221 ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00222 va_end (arg);
00223 }
00224
00228 void CS_GNUC_PRINTF (3, 4)
00229 ReportDebug (const char* msgId, const char* description, ...)
00230 {
00231 va_list arg;
00232 va_start (arg, description);
00233 ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00234 va_end (arg);
00235 }
00236 };
00237
00238
00245 class csReporterHelper
00246 {
00247 public:
00248 static void CS_GNUC_PRINTF (4, 0)
00249 ReportV(iObjectRegistry* reg, int severity, char const* msgId,
00250 char const* description, va_list args)
00251 {
00252 csRef<iReporter> reporter (CS_QUERY_REGISTRY (reg, iReporter));
00253 if (reporter)
00254 reporter->ReportV(severity, msgId, description, args);
00255 else
00256 {
00257 csPrintfV(description, args);
00258 csPrintf("\n");
00259 }
00260 }
00261
00262 static void CS_GNUC_PRINTF (4, 5)
00263 Report(iObjectRegistry* reg, int severity, char const* msgId,
00264 char const* description, ...)
00265 {
00266 va_list arg;
00267 va_start(arg, description);
00268
00269 ReportV(reg,severity,msgId,description,arg);
00270
00271 va_end (arg);
00272 }
00273 };
00274
00279 #define csReport csReporterHelper::Report
00280 #define csReportV csReporterHelper::ReportV
00281
00282 #endif // __CS_IVARIA_REPORTER_H__
00283