xref: /haiku/headers/build/os/app/Handler.h (revision 9760dcae2038d47442f4658c2575844c6cf92c40)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		Handler.cpp
23 //	Author:			Erik Jaesler (erik@cgsoftware.com)
24 //	Description:	BHandler defines the message-handling protocol.
25 //					MessageReceived() is its lynchpin.
26 //------------------------------------------------------------------------------
27 
28 #ifndef _HANDLER_H
29 #define _HANDLER_H
30 
31 // Standard Includes -----------------------------------------------------------
32 
33 // System Includes -------------------------------------------------------------
34 #include <BeBuild.h>
35 #include <Archivable.h>
36 
37 // Project Includes ------------------------------------------------------------
38 
39 // Local Includes --------------------------------------------------------------
40 
41 // Local Defines ---------------------------------------------------------------
42 
43 // Globals ---------------------------------------------------------------------
44 
45 class BLooper;
46 class BMessageFilter;
47 class BMessage;
48 class BMessenger;
49 class BList;
50 class _ObserverList;
51 
52 #define B_OBSERVE_WHAT_CHANGE "be:observe_change_what"
53 #define B_OBSERVE_ORIGINAL_WHAT "be:observe_orig_what"
54 const uint32 B_OBSERVER_OBSERVE_ALL = 0xffffffff;
55 
56 // BHandler class --------------------------------------------------------------
57 class BHandler : public BArchivable {
58 
59 public:
60 							BHandler(const char* name = NULL);
61 	virtual					~BHandler();
62 
63 	// Archiving
64 							BHandler(BMessage* data);
65 	static	BArchivable*	Instantiate(BMessage* data);
66 	virtual	status_t		Archive(BMessage* data, bool deep = true) const;
67 
68 	// BHandler guts.
69 	virtual	void			MessageReceived(BMessage* message);
70 			BLooper*		Looper() const;
71 			void			SetName(const char* name);
72 			const char*		Name() const;
73 	virtual	void			SetNextHandler(BHandler* handler);
74 			BHandler*		NextHandler() const;
75 
76 	// Message filtering
77 	virtual	void			AddFilter(BMessageFilter* filter);
78 	virtual	bool			RemoveFilter(BMessageFilter* filter);
79 	virtual	void			SetFilterList(BList* filters);
80 			BList*			FilterList();
81 
82 			bool			LockLooper();
83 			status_t		LockLooperWithTimeout(bigtime_t timeout);
84 			void			UnlockLooper();
85 
86 	// Scripting
87 	virtual BHandler*		ResolveSpecifier(BMessage* msg,
88 											 int32 index,
89 											 BMessage* specifier,
90 											 int32 form,
91 											 const char* property);
92 	virtual status_t		GetSupportedSuites(BMessage* data);
93 
94 	// Observer calls, inter-looper and inter-team
95 			status_t		StartWatching(BMessenger, uint32 what);
96 			status_t		StartWatchingAll(BMessenger);
97 			status_t		StopWatching(BMessenger, uint32 what);
98 			status_t		StopWatchingAll(BMessenger);
99 
100 	// Observer calls for observing targets in the same BLooper
101 			status_t		StartWatching(BHandler* , uint32 what);
102 			status_t		StartWatchingAll(BHandler* );
103 			status_t		StopWatching(BHandler* , uint32 what);
104 			status_t		StopWatchingAll(BHandler* );
105 
106 
107 	// Reserved
108 	virtual status_t		Perform(perform_code d, void* arg);
109 
110 	// Notifier calls
111 	virtual	void 			SendNotices(uint32 what, const BMessage*  = 0);
112 			bool			IsWatched() const;
113 
114 //----- Private or reserved -----------------------------------------
115 private:
116 	typedef BArchivable		_inherited;
117 	friend inline int32		_get_object_token_(const BHandler* );
118 	friend class BLooper;
119 	friend class BMessageFilter;
120 
121 	virtual	void			_ReservedHandler2();
122 	virtual	void			_ReservedHandler3();
123 	virtual	void			_ReservedHandler4();
124 
125 			void			InitData(const char* name);
126 
127 							BHandler(const BHandler&);
128 			BHandler&		operator=(const BHandler&);
129 			void			SetLooper(BLooper* loop);
130 
131 			int32			fToken;
132 			char*			fName;
133 			BLooper*		fLooper;
134 			BHandler*		fNextHandler;
135 			BList*			fFilters;
136 			_ObserverList*	fObserverList;
137 			uint32			_reserved[3];
138 };
139 //------------------------------------------------------------------------------
140 
141 #endif	// _HANDLER_H
142 
143 /*
144  * $Log $
145  *
146  * $Id  $
147  *
148  */
149 
150