xref: /haiku/headers/os/app/Handler.h (revision d06cbe081b7ea043aea2012359744091de6d604d)
1 /*
2  * Copyright 2001-2014 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 <Archivable.h>
13 
14 
15 class BLooper;
16 class BMessageFilter;
17 class BMessage;
18 class BMessenger;
19 class BList;
20 
21 #define B_OBSERVE_WHAT_CHANGE "be:observe_change_what"
22 #define B_OBSERVE_ORIGINAL_WHAT "be:observe_orig_what"
23 const uint32 B_OBSERVER_OBSERVE_ALL = 0xffffffff;
24 
25 namespace BPrivate {
26 	class ObserverList;
27 }
28 
29 class BHandler : public BArchivable {
30 public:
31 							BHandler(const char* name = NULL);
32 	virtual					~BHandler();
33 
34 	// Archiving
35 							BHandler(BMessage* data);
36 	static	BArchivable*	Instantiate(BMessage* data);
37 	virtual	status_t		Archive(BMessage* data, bool deep = true) const;
38 
39 	// BHandler guts.
40 	virtual	void			MessageReceived(BMessage* message);
41 			BLooper*		Looper() const;
42 			void			SetName(const char* name);
43 			const char*		Name() const;
44 	virtual	void			SetNextHandler(BHandler* handler);
45 			BHandler*		NextHandler() const;
46 
47 	// Message filtering
48 	virtual	void			AddFilter(BMessageFilter* filter);
49 	virtual	bool			RemoveFilter(BMessageFilter* filter);
50 	virtual	void			SetFilterList(BList* filters);
51 			BList*			FilterList();
52 
53 			bool			LockLooper();
54 			status_t		LockLooperWithTimeout(bigtime_t timeout);
55 			void			UnlockLooper();
56 
57 	// Scripting
58 	virtual BHandler*		ResolveSpecifier(BMessage* message, int32 index,
59 								BMessage* specifier, int32 what,
60 								const char* property);
61 	virtual status_t		GetSupportedSuites(BMessage* data);
62 
63 	// Observer calls, inter-looper and inter-team
64 			status_t		StartWatching(BMessenger target, uint32 what);
65 			status_t		StartWatchingAll(BMessenger target);
66 			status_t		StopWatching(BMessenger target, uint32 what);
67 			status_t		StopWatchingAll(BMessenger target);
68 
69 	// Observer calls for observing targets in the local team
70 			status_t		StartWatching(BHandler* observer, uint32 what);
71 			status_t		StartWatchingAll(BHandler* observer);
72 			status_t		StopWatching(BHandler* observer, uint32 what);
73 			status_t		StopWatchingAll(BHandler* observer);
74 
75 
76 	// Reserved
77 	virtual status_t		Perform(perform_code d, void* arg);
78 
79 	// Notifier calls
80 	virtual	void 			SendNotices(uint32 what,
81 								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