1 /* 2 * Copyright 2015, 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(); 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 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