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 "iutil/objreg.h"
00023 #include "iutil/threadmanager.h"
00024
00025 #include "csutil/ansicommand.h"
00026 #include "csutil/scf_interface.h"
00027 #include "csutil/sysfunc.h"
00028 #include "csutil/util.h"
00029
00036 struct iReporter;
00037
00045 #define CS_REPORTER_SEVERITY_BUG 0
00046
00052 #define CS_REPORTER_SEVERITY_ERROR 1
00053
00058 #define CS_REPORTER_SEVERITY_WARNING 2
00059
00064 #define CS_REPORTER_SEVERITY_NOTIFY 3
00065
00071 #define CS_REPORTER_SEVERITY_DEBUG 4
00072
00086 struct iReporterListener : public virtual iBase
00087 {
00088 SCF_INTERFACE (iReporterListener, 1, 0, 0);
00089
00095 THREADED_INTERFACE4(Report, iReporter* reporter, int severity, const char* msgId,
00096 const char* description);
00097 };
00098
00106 struct iReporterIterator : public virtual iBase
00107 {
00108 SCF_INTERFACE(iReporterIterator, 2, 0, 0);
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
00154 struct iReporter : public virtual iBase
00155 {
00156 SCF_INTERFACE(iReporter, 2, 0, 0);
00157
00164 virtual void Report (int severity, const char* msgId,
00165 const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00166
00171 virtual void ReportV (int severity, const char* msgId,
00172 const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00173
00179 virtual void Clear (int severity = -1) = 0;
00180
00187 virtual void Clear (const char* mask) = 0;
00188
00193 virtual csPtr<iReporterIterator> GetMessageIterator () = 0;
00194
00201 virtual void AddReporterListener (iReporterListener* listener) = 0;
00202
00209 virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00210
00214 virtual bool FindReporterListener (iReporterListener* listener) = 0;
00215
00216
00217
00218
00219
00224 inline void ReportError (const char* msgId, const char* description, ...)
00225 CS_GNUC_PRINTF (3, 4);
00226
00231 inline void ReportWarning (const char* msgId, const char* description, ...)
00232 CS_GNUC_PRINTF (3, 4);
00233
00238 inline void ReportNotify (const char* msgId, const char* description, ...)
00239 CS_GNUC_PRINTF (3, 4);
00240
00245 inline void ReportBug (const char* msgId, const char* description, ...)
00246 CS_GNUC_PRINTF (3, 4);
00247
00252 inline void ReportDebug (const char* msgId, const char* description, ...)
00253 CS_GNUC_PRINTF (3, 4);
00254 };
00255
00256 inline void iReporter::ReportError
00257 (const char* msgId, const char* description, ...)
00258 {
00259 va_list arg;
00260 va_start (arg, description);
00261 ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00262 va_end (arg);
00263 }
00264
00265 inline void iReporter::ReportWarning
00266 (const char* msgId, const char* description, ...)
00267 {
00268 va_list arg;
00269 va_start (arg, description);
00270 ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00271 va_end (arg);
00272 }
00273
00274 inline void iReporter::ReportNotify
00275 (const char* msgId, const char* description, ...)
00276 {
00277 va_list arg;
00278 va_start (arg, description);
00279 ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00280 va_end (arg);
00281 }
00282
00283 inline void iReporter::ReportBug
00284 (const char* msgId, const char* description, ...)
00285 {
00286 va_list arg;
00287 va_start (arg, description);
00288 ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00289 va_end (arg);
00290 }
00291
00292 inline void iReporter::ReportDebug
00293 (const char* msgId, const char* description, ...)
00294 {
00295 va_list arg;
00296 va_start (arg, description);
00297 ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00298 va_end (arg);
00299 }
00300
00301
00308 class csReporterHelper
00309 {
00310 public:
00317 static inline void ReportV(iObjectRegistry* reg, int severity,
00318 char const* msgId, char const* description, va_list args)
00319 CS_GNUC_PRINTF (4, 0);
00320
00327 static inline void Report(iObjectRegistry* reg, int severity,
00328 char const* msgId, char const* description, ...)
00329 CS_GNUC_PRINTF (4, 5);
00330 };
00331
00332 inline void csReporterHelper::ReportV(iObjectRegistry* reg, int severity,
00333 char const* msgId, char const* description, va_list args)
00334 {
00335 csRef<iReporter> reporter;
00336 if (reg && (reporter = csQueryRegistry<iReporter> (reg)))
00337 reporter->ReportV (severity, msgId, description, args);
00338 else
00339 {
00340
00341
00342
00343
00344
00345
00346 switch (severity)
00347 {
00348 case CS_REPORTER_SEVERITY_BUG:
00349 csPrintf (CS_ANSI_FM CS_ANSI_TEXT_BOLD_ON "BUG: " CS_ANSI_RST);
00350 break;
00351 case CS_REPORTER_SEVERITY_ERROR:
00352 if (csStrNCaseCmp (description, "error", 5) != 0)
00353 csPrintf (CS_ANSI_FR CS_ANSI_TEXT_BOLD_ON "ERROR: " CS_ANSI_RST);
00354 break;
00355 case CS_REPORTER_SEVERITY_WARNING:
00356 if (csStrNCaseCmp (description, "warning", 7) != 0)
00357 csPrintf (CS_ANSI_FY CS_ANSI_TEXT_BOLD_ON "WARNING: " CS_ANSI_RST);
00358 break;
00359 case CS_REPORTER_SEVERITY_NOTIFY:
00360 csPrintf ("NOTIFY: ");
00361 break;
00362 case CS_REPORTER_SEVERITY_DEBUG:
00363 csPrintf (CS_ANSI_FW CS_ANSI_TEXT_BOLD_ON "DEBUG: " CS_ANSI_RST);
00364 break;
00365 }
00366 csPrintfV(description, args);
00367 csPrintf("\n");
00368 }
00369 }
00370
00371 inline void csReporterHelper::Report(iObjectRegistry* reg, int severity,
00372 char const* msgId, char const* description, ...)
00373 {
00374 va_list arg;
00375 va_start(arg, description);
00376
00377 ReportV(reg,severity,msgId,description,arg);
00378
00379 va_end (arg);
00380 }
00381
00385 #define csReport csReporterHelper::Report
00386
00389 #define csReportV csReporterHelper::ReportV
00390
00391
00392
00393 #endif // __CS_IVARIA_REPORTER_H__
00394