xref: /haiku/headers/os/app/Handler.h (revision b028e77473189065f2baefc6f5e10d451cf591e2)
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 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* msg, int32 index,
59 								BMessage* specifier, int32 form,
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, const BMessage* notice = NULL);
81 			bool			IsWatched() const;
82 
83 private:
84 	typedef BArchivable		_inherited;
85 	friend inline int32		_get_object_token_(const BHandler* );
86 	friend class BLooper;
87 	friend class BMessageFilter;
88 
89 	virtual	void			_ReservedHandler2();
90 	virtual	void			_ReservedHandler3();
91 	virtual	void			_ReservedHandler4();
92 
93 			void			_InitData(const char* name);
94 			BPrivate::ObserverList* _ObserverList();
95 
96 							BHandler(const BHandler&);
97 			BHandler&		operator=(const BHandler&);
98 			void			SetLooper(BLooper* looper);
99 
100 			int32			fToken;
101 			char*			fName;
102 			BLooper*		fLooper;
103 			BHandler*		fNextHandler;
104 			BList*			fFilters;
105 			BPrivate::ObserverList*	fObserverList;
106 			uint32			_reserved[3];
107 };
108 
109 #endif	// _HANDLER_H
110