xref: /haiku/src/servers/launch/Events.h (revision 1a76488fc88584bf66b9751d7fb9b6527ac20d87)
1 /*
2  * Copyright 2015-2018, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef EVENTS_H
6 #define EVENTS_H
7 
8 
9 #include <Messenger.h>
10 #include <String.h>
11 
12 
13 class BaseJob;
14 class Event;
15 
16 
17 class EventRegistrator {
18 public:
19 	virtual	status_t			RegisterExternalEvent(Event* event,
20 									const char* name,
21 									const BStringList& arguments) = 0;
22 	virtual	void				UnregisterExternalEvent(Event* event,
23 									const char* name) = 0;
24 };
25 
26 
27 class Event {
28 public:
29 								Event(Event* parent);
30 	virtual						~Event();
31 
32 	virtual	status_t			Register(
33 									EventRegistrator& registrator) = 0;
34 	virtual	void				Unregister(
35 									EventRegistrator& registrator) = 0;
36 
37 			bool				Triggered() const;
38 	virtual	void				Trigger(Event* origin);
39 	virtual	void				ResetTrigger();
40 
41 	virtual	BaseJob*			Owner() const;
42 	virtual	void				SetOwner(BaseJob* owner);
43 
44 			Event*				Parent() const;
45 
46 	virtual	BString				ToString() const = 0;
47 
48 protected:
49 			Event*				fParent;
50 			bool				fTriggered;
51 };
52 
53 
54 class Events {
55 public:
56 	static	Event*			FromMessage(const BMessenger& target,
57 								const BMessage& message);
58 	static	Event*			AddOnDemand(const BMessenger& target, Event* event);
59 	static	Event*			ResolveExternalEvent(Event* event,
60 								const char* name, uint32 flags);
61 	static	void			TriggerExternalEvent(Event* event);
62 	static	void			ResetStickyExternalEvent(Event* event);
63 	static	bool			TriggerDemand(Event* event, bool testOnly = false);
64 };
65 
66 
67 #endif // EVENTS_H
68