1/*
2
3Report.
4
5Copyright (c) 2002 OpenBeOS.
6
7Author:
8	Michael Pfeiffer
9
10Permission is hereby granted, free of charge, to any person obtaining a copy of
11this software and associated documentation files (the "Software"), to deal in
12the Software without restriction, including without limitation the rights to
13use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14of the Software, and to permit persons to whom the Software is furnished to do
15so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE SOFTWARE.
27
28*/
29
30#ifndef _REPORT_H
31#define _REPORT_H
32
33#include <stdio.h>
34#include <String.h>
35#include <Locker.h>
36#include "PrintUtils.h"
37
38
39enum kind {
40	kInfo,
41	kWarning,
42	kError,
43	kDebug,
44};
45
46const int32 kNumKinds = kDebug + 1;
47
48
49class ReportRecord {
50public:
51private:
52	kind    fKind;
53	int32   fPage;
54	BString fLabel;
55	BString fDesc;
56
57public:
58	ReportRecord(kind kind, int32 page, const char* label, const char* desc)
59		: fKind(kind), fPage(page), fLabel(label), fDesc(desc)
60	{ }
61
62	kind Kind() const         { return fKind; }
63	int32 Page() const        { return fPage; }
64	const char* Label() const { return fLabel.String(); }
65	const char* Desc() const  { return fDesc.String(); }
66};
67
68
69class Report : public TList<ReportRecord>{
70	static  Report* fInstance;
71	int32   fNum[kNumKinds];
72	BLocker fLock;
73
74	Report();
75	~Report();
76
77	typedef TList<ReportRecord> inherited;
78
79public:
80	static Report* Instance();
81	void           Free();
82
83	// Only these methods are "synchronized":
84	// Note that they are *NOT* virtual in the base class!
85	void          Add(kind kind, int32 page, const char* fmt, ...);
86	int           Count(kind kind);
87	ReportRecord* ItemAt(int32 i);
88	int32         CountItems();
89};
90
91
92#define REPORT  Report::Instance()->Add
93
94#endif
95