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
13class BaseJob;
14class Event;
15
16
17class EventRegistrator {
18public:
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
27class Event {
28public:
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
48protected:
49			Event*				fParent;
50			bool				fTriggered;
51};
52
53
54class Events {
55public:
56	static	Event*			FromMessage(const BMessenger& target,
57								const BMessage& message);
58	static	Event*			AddOnDemand(const BMessenger& target, Event* event);
59	static	bool			ResolveExternalEvent(Event* event,
60								const char* name, uint32 flags);
61	static	void			TriggerExternalEvent(Event* event,
62								const char* name);
63	static	void			ResetStickyExternalEvent(Event* event,
64								const char* name);
65	static	bool			TriggerDemand(Event* event, bool testOnly = false);
66};
67
68
69#endif // EVENTS_H
70