xref: /haiku/headers/os/app/Handler.h (revision 5d9e40fe9252c8f9c5e5e41594545bfa4419fcc7)
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 BList;
49 class _ObserverList;
50 
51 #define B_OBSERVE_WHAT_CHANGE "be:observe_change_what"
52 #define B_OBSERVE_ORIGINAL_WHAT "be:observe_orig_what"
53 const uint32 B_OBSERVER_OBSERVE_ALL = 0xffffffff;
54 
55 // BHandler class --------------------------------------------------------------
56 class BHandler : public BArchivable {
57 
58 public:
59 							BHandler(const char* name = NULL);
60 	virtual					~BHandler();
61 
62 	// Archiving
63 							BHandler(BMessage* data);
64 	static	BArchivable*	Instantiate(BMessage* data);
65 	virtual	status_t		Archive(BMessage* data, bool deep = true) const;
66 
67 	// BHandler guts.
68 	virtual	void			MessageReceived(BMessage* message);
69 			BLooper*		Looper() const;
70 			void			SetName(const char* name);
71 			const char*		Name() const;
72 	virtual	void			SetNextHandler(BHandler* handler);
73 			BHandler*		NextHandler() const;
74 
75 	// Message filtering
76 	virtual	void			AddFilter(BMessageFilter* filter);
77 	virtual	bool			RemoveFilter(BMessageFilter* filter);
78 	virtual	void			SetFilterList(BList* filters);
79 			BList*			FilterList();
80 
81 			bool			LockLooper();
82 			status_t		LockLooperWithTimeout(bigtime_t timeout);
83 			void			UnlockLooper();
84 
85 	// Scripting
86 	virtual BHandler*		ResolveSpecifier(BMessage* msg,
87 											 int32 index,
88 											 BMessage* specifier,
89 											 int32 form,
90 											 const char* property);
91 	virtual status_t		GetSupportedSuites(BMessage* data);
92 
93 	// Observer calls, inter-looper and inter-team
94 			status_t		StartWatching(BMessenger, uint32 what);
95 			status_t		StartWatchingAll(BMessenger);
96 			status_t		StopWatching(BMessenger, uint32 what);
97 			status_t		StopWatchingAll(BMessenger);
98 
99 	// Observer calls for observing targets in the same BLooper
100 			status_t		StartWatching(BHandler* , uint32 what);
101 			status_t		StartWatchingAll(BHandler* );
102 			status_t		StopWatching(BHandler* , uint32 what);
103 			status_t		StopWatchingAll(BHandler* );
104 
105 
106 	// Reserved
107 	virtual status_t		Perform(perform_code d, void* arg);
108 
109 	// Notifier calls
110 	virtual	void 			SendNotices(uint32 what, const BMessage*  = 0);
111 			bool			IsWatched() const;
112 
113 //----- Private or reserved -----------------------------------------
114 private:
115 	typedef BArchivable		_inherited;
116 	friend inline int32		_get_object_token_(const BHandler* );
117 	friend class BLooper;
118 	friend class BMessageFilter;
119 
120 	virtual	void			_ReservedHandler2();
121 	virtual	void			_ReservedHandler3();
122 	virtual	void			_ReservedHandler4();
123 
124 			void			InitData(const char* name);
125 
126 							BHandler(const BHandler&);
127 			BHandler&		operator=(const BHandler&);
128 			void			SetLooper(BLooper* loop);
129 
130 			int32			fToken;
131 			char*			fName;
132 			BLooper*		fLooper;
133 			BHandler*		fNextHandler;
134 			BList*			fFilters;
135 			_ObserverList*	fObserverList;
136 			uint32			_reserved[3];
137 };
138 //------------------------------------------------------------------------------
139 
140 #endif	// _HANDLER_H
141 
142 /*
143  * $Log $
144  *
145  * $Id  $
146  *
147  */
148 
149