xref: /haiku/headers/os/app/Handler.h (revision f23596149e0d173463f70629581aa10cc305d32e)
1 /*
2  * Copyright 2001-2006, 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 class _ObserverList;
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 
27 class BHandler : public BArchivable {
28 public:
29 							BHandler(const char* name = NULL);
30 	virtual					~BHandler();
31 
32 	// Archiving
33 							BHandler(BMessage* data);
34 	static	BArchivable*	Instantiate(BMessage* data);
35 	virtual	status_t		Archive(BMessage* data, bool deep = true) const;
36 
37 	// BHandler guts.
38 	virtual	void			MessageReceived(BMessage* message);
39 			BLooper*		Looper() const;
40 			void			SetName(const char* name);
41 			const char*		Name() const;
42 	virtual	void			SetNextHandler(BHandler* handler);
43 			BHandler*		NextHandler() const;
44 
45 	// Message filtering
46 	virtual	void			AddFilter(BMessageFilter* filter);
47 	virtual	bool			RemoveFilter(BMessageFilter* filter);
48 	virtual	void			SetFilterList(BList* filters);
49 			BList*			FilterList();
50 
51 			bool			LockLooper();
52 			status_t		LockLooperWithTimeout(bigtime_t timeout);
53 			void			UnlockLooper();
54 
55 	// Scripting
56 	virtual BHandler*		ResolveSpecifier(BMessage* msg,
57 											 int32 index,
58 											 BMessage* specifier,
59 											 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, uint32 what);
65 			status_t		StartWatchingAll(BMessenger);
66 			status_t		StopWatching(BMessenger, uint32 what);
67 			status_t		StopWatchingAll(BMessenger);
68 
69 	// Observer calls for observing targets in the same BLooper
70 			status_t		StartWatching(BHandler* , uint32 what);
71 			status_t		StartWatchingAll(BHandler* );
72 			status_t		StopWatching(BHandler* , uint32 what);
73 			status_t		StopWatchingAll(BHandler* );
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*  = 0);
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 
95 							BHandler(const BHandler&);
96 			BHandler&		operator=(const BHandler&);
97 			void			SetLooper(BLooper* loop);
98 
99 			int32			fToken;
100 			char*			fName;
101 			BLooper*		fLooper;
102 			BHandler*		fNextHandler;
103 			BList*			fFilters;
104 			_ObserverList*	fObserverList;
105 			uint32			_reserved[3];
106 };
107 
108 #endif	// _HANDLER_H
109