00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __IVARIA_REPORTER_H__
00020 #define __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 (iReporter, 0, 0, 3);
00080
00084 struct iReporter : public iBase
00085 {
00091 virtual void Report (int severity, const char* msgId,
00092 const char* description, ...) CS_GNUC_PRINTF(4, 5) = 0;
00093
00097 virtual void ReportV (int severity, const char* msgId,
00098 const char* description, va_list) CS_GNUC_PRINTF(4, 0) = 0;
00099
00105 virtual void Clear (int severity = -1) = 0;
00106
00113 virtual void Clear (const char* mask) = 0;
00114
00118 virtual int GetMessageCount () const = 0;
00119
00123 virtual int GetMessageSeverity (int idx) const = 0;
00124
00128 virtual const char* GetMessageId (int idx) const = 0;
00129
00133 virtual const char* GetMessageDescription (int idx) const = 0;
00134
00141 virtual void AddReporterListener (iReporterListener* listener) = 0;
00142
00149 virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00150
00154 virtual bool FindReporterListener (iReporterListener* listener) = 0;
00155
00156
00157
00158
00159
00163 void CS_GNUC_PRINTF (3, 4)
00164 ReportError (const char* msgId, const char* description, ...)
00165 {
00166 va_list arg;
00167 va_start (arg, description);
00168 ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00169 va_end (arg);
00170 }
00171
00175 void CS_GNUC_PRINTF (3, 4)
00176 ReportWarning (const char* msgId, const char* description, ...)
00177 {
00178 va_list arg;
00179 va_start (arg, description);
00180 ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00181 va_end (arg);
00182 }
00183
00187 void CS_GNUC_PRINTF (3, 4)
00188 ReportNotify (const char* msgId, const char* description, ...)
00189 {
00190 va_list arg;
00191 va_start (arg, description);
00192 ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00193 va_end (arg);
00194 }
00195
00199 void CS_GNUC_PRINTF (3, 4)
00200 ReportBug (const char* msgId, const char* description, ...)
00201 {
00202 va_list arg;
00203 va_start (arg, description);
00204 ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00205 va_end (arg);
00206 }
00207
00211 void CS_GNUC_PRINTF (3, 4)
00212 ReportDebug (const char* msgId, const char* description, ...)
00213 {
00214 va_list arg;
00215 va_start (arg, description);
00216 ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00217 va_end (arg);
00218 }
00219 };
00220
00221
00222
00223
00224
00225
00226
00227
00228 class csReporterHelper
00229 {
00230 public:
00231 static void CS_GNUC_PRINTF (4, 0)
00232 ReportV(iObjectRegistry* reg, int severity, char const* msgId,
00233 char const* description, va_list args)
00234 {
00235 iReporter* reporter = CS_QUERY_REGISTRY(reg, iReporter);
00236 if (reporter)
00237 {
00238 reporter->ReportV(severity, msgId, description, args);
00239 reporter->DecRef ();
00240 }
00241 else
00242 {
00243 csPrintfV(description, args);
00244 csPrintf("\n");
00245 }
00246 }
00247
00248 static void CS_GNUC_PRINTF (4, 5)
00249 Report(iObjectRegistry* reg, int severity, char const* msgId,
00250 char const* description, ...)
00251 {
00252 va_list arg;
00253 va_start(arg, description);
00254
00255 ReportV(reg,severity,msgId,description,arg);
00256
00257 va_end (arg);
00258 }
00259 };
00260
00265 #define csReport csReporterHelper::Report
00266 #define csReportV csReporterHelper::ReportV
00267
00268 #endif // __IVARIA_REPORTER_H__
00269