1 /* 2 * Copyright 2001-2007, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Erik Jaesler (erik@cgsoftware.com) 7 */ 8 #ifndef _HANDLER_H 9 #define _HANDLER_H 10 11 12 #include <BeBuild.h> 13 #include <Archivable.h> 14 15 16 class BLooper; 17 class BMessageFilter; 18 class BMessage; 19 class BMessenger; 20 class BList; 21 22 #define B_OBSERVE_WHAT_CHANGE "be:observe_change_what" 23 #define B_OBSERVE_ORIGINAL_WHAT "be:observe_orig_what" 24 const uint32 B_OBSERVER_OBSERVE_ALL = 0xffffffff; 25 26 namespace BPrivate { 27 class ObserverList; 28 } 29 30 class BHandler : public BArchivable { 31 public: 32 BHandler(const char* name = NULL); 33 virtual ~BHandler(); 34 35 // Archiving 36 BHandler(BMessage* data); 37 static BArchivable* Instantiate(BMessage* data); 38 virtual status_t Archive(BMessage* data, bool deep = true) const; 39 40 // BHandler guts. 41 virtual void MessageReceived(BMessage* message); 42 BLooper* Looper() const; 43 void SetName(const char* name); 44 const char* Name() const; 45 virtual void SetNextHandler(BHandler* handler); 46 BHandler* NextHandler() const; 47 48 // Message filtering 49 virtual void AddFilter(BMessageFilter* filter); 50 virtual bool RemoveFilter(BMessageFilter* filter); 51 virtual void SetFilterList(BList* filters); 52 BList* FilterList(); 53 54 bool LockLooper(); 55 status_t LockLooperWithTimeout(bigtime_t timeout); 56 void UnlockLooper(); 57 58 // Scripting 59 virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index, 60 BMessage* specifier, int32 form, 61 const char* property); 62 virtual status_t GetSupportedSuites(BMessage* data); 63 64 // Observer calls, inter-looper and inter-team 65 status_t StartWatching(BMessenger target, uint32 what); 66 status_t StartWatchingAll(BMessenger target); 67 status_t StopWatching(BMessenger target, uint32 what); 68 status_t StopWatchingAll(BMessenger target); 69 70 // Observer calls for observing targets in the local team 71 status_t StartWatching(BHandler* observer, uint32 what); 72 status_t StartWatchingAll(BHandler* observer); 73 status_t StopWatching(BHandler* observer, uint32 what); 74 status_t StopWatchingAll(BHandler* observer); 75 76 77 // Reserved 78 virtual status_t Perform(perform_code d, void* arg); 79 80 // Notifier calls 81 virtual void SendNotices(uint32 what, const BMessage* notice = NULL); 82 bool IsWatched() const; 83 84 private: 85 typedef BArchivable _inherited; 86 friend inline int32 _get_object_token_(const BHandler* ); 87 friend class BLooper; 88 friend class BMessageFilter; 89 90 virtual void _ReservedHandler2(); 91 virtual void _ReservedHandler3(); 92 virtual void _ReservedHandler4(); 93 94 void _InitData(const char* name); 95 BPrivate::ObserverList* _ObserverList(); 96 97 BHandler(const BHandler&); 98 BHandler& operator=(const BHandler&); 99 void SetLooper(BLooper* looper); 100 101 int32 fToken; 102 char* fName; 103 BLooper* fLooper; 104 BHandler* fNextHandler; 105 BList* fFilters; 106 BPrivate::ObserverList* fObserverList; 107 uint32 _reserved[3]; 108 }; 109 110 #endif // _HANDLER_H 111