xref: /haiku/src/servers/launch/Log.h (revision a77aa747eaf779898d401614a11b98fe58dddf35)
1 /*
2  * Copyright 2017-2018, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef LOG_H
6 #define LOG_H
7 
8 
9 #include <String.h>
10 
11 #include <locks.h>
12 #include <util/DoublyLinkedList.h>
13 
14 
15 class BMessage;
16 
17 class BaseJob;
18 class Event;
19 class Job;
20 
21 
22 enum LogItemType {
23 	kJobInitialized,
24 	kJobIgnored,
25 	kJobLaunched,
26 	kJobTerminated,
27 	kJobEnabled,
28 	kJobStopped,
29 	kEvent,
30 	kExternalEvent,
31 	kExternalEventRegistered,
32 	kExternalEventUnregistered,
33 };
34 
35 
36 class LogItem : public DoublyLinkedListLinkImpl<LogItem> {
37 public:
38 public:
39 								LogItem();
40 	virtual						~LogItem();
41 
When()42 			bigtime_t			When()
43 									{ return fWhen; }
44 			BString				Message() const;
45 
46 	virtual	LogItemType			Type() const = 0;
47 	virtual status_t			GetMessage(BString& target) const = 0;
48 	virtual status_t			GetParameter(BMessage& parameter) const = 0;
49 	virtual	bool				Matches(const char* jobName,
50 									const char* eventName) = 0;
51 
52 private:
53 			bigtime_t			fWhen;
54 };
55 
56 
57 typedef DoublyLinkedList<LogItem> LogItemList;
58 
59 
60 class Log {
61 public:
62 								Log();
63 
64 			void				Add(LogItem* item);
65 
66 			LogItemList::Iterator
Iterator()67 								Iterator()
68 									{ return fItems.GetIterator(); }
69 
Lock()70 			mutex&				Lock()
71 									{ return fLock; }
72 
73 			void				JobInitialized(Job* job);
74 			void				JobIgnored(Job* job, status_t status);
75 
76 			void				JobLaunched(Job* job, status_t status);
77 			void				JobTerminated(Job* job, status_t status);
78 
79 			void				JobEnabled(Job* job, bool enabled);
80 			void				JobStopped(BaseJob* job, bool force);
81 
82 			void				EventTriggered(BaseJob* job, Event* event);
83 
84 			void				ExternalEventTriggered(const char* name);
85 			void				ExternalEventRegistered(const char* name);
86 			void				ExternalEventUnregistered(const char* name);
87 
88 private:
89 			mutex				fLock;
90 			LogItemList			fItems;
91 			size_t				fCount;
92 };
93 
94 
95 #endif // LOG_H
96