xref: /haiku/headers/os/app/MessageFilter.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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:		MessageFilter.h
23 //	Author:			Erik Jaesler (erik@cgsoftware.com)
24 //	Description:	BMessageFilter class creates objects that filter
25 //					in-coming BMessages.
26 //------------------------------------------------------------------------------
27 
28 #ifndef _MESSAGE_FILTER_H
29 #define _MESSAGE_FILTER_H
30 
31 // Standard Includes -----------------------------------------------------------
32 
33 // System Includes -------------------------------------------------------------
34 #include <BeBuild.h>
35 #include <Handler.h>
36 
37 // Project Includes ------------------------------------------------------------
38 
39 // Local Includes --------------------------------------------------------------
40 
41 // Local Defines ---------------------------------------------------------------
42 
43 // Globals ---------------------------------------------------------------------
44 
45 class BMessage;
46 
47 // filter_hook Return Codes and Protocol ---------------------------------------
48 enum filter_result {
49 	B_SKIP_MESSAGE,
50 	B_DISPATCH_MESSAGE
51 };
52 
53 typedef filter_result (*filter_hook)
54 	(BMessage* message, BHandler** target, BMessageFilter* filter);
55 
56 
57 // BMessageFilter invocation criteria ------------------------------------------
58 enum message_delivery {
59 	B_ANY_DELIVERY,
60 	B_DROPPED_DELIVERY,
61 	B_PROGRAMMED_DELIVERY
62 };
63 
64 enum message_source {
65 	B_ANY_SOURCE,
66 	B_REMOTE_SOURCE,
67 	B_LOCAL_SOURCE
68 };
69 
70 // BMessageFilter Class --------------------------------------------------------
71 class BMessageFilter {
72 
73 public:
74 								BMessageFilter(	uint32 what,
75 												filter_hook func = NULL);
76 								BMessageFilter(	message_delivery delivery,
77 												message_source source,
78 												filter_hook func = NULL);
79 								BMessageFilter(	message_delivery delivery,
80 												message_source source,
81 												uint32 what,
82 												filter_hook func = NULL);
83 								BMessageFilter(const BMessageFilter& filter);
84 								BMessageFilter(const BMessageFilter* filter);
85 	virtual						~BMessageFilter();
86 
87 			BMessageFilter		&operator=(const BMessageFilter& from);
88 
89 	// Hook function; ignored if filter_hook is non-NULL
90 	virtual	filter_result		Filter(BMessage* message, BHandler** target);
91 
92 			message_delivery	MessageDelivery() const;
93 			message_source		MessageSource() const;
94 			uint32				Command() const;
95 			bool				FiltersAnyCommand() const;
96 			BLooper				*Looper() const;
97 
98 // Private or reserved ---------------------------------------------------------
99 private:
100 	friend	class BLooper;
101 	friend	class BHandler;
102 
103 	virtual	void				_ReservedMessageFilter1();
104 	virtual	void				_ReservedMessageFilter2();
105 
106 			void				SetLooper(BLooper* owner);
107 			filter_hook			FilterFunction() const;
108 			bool				fFiltersAny;
109 			uint32				what;
110 			message_delivery	fDelivery;
111 			message_source		fSource;
112 			BLooper				*fLooper;
113 			filter_hook			fFilterFunction;
114 			uint32				_reserved[3];
115 };
116 //------------------------------------------------------------------------------
117 
118 #endif	// _MESSAGE_FILTER_H
119 
120 /*
121  * $Log $
122  *
123  * $Id  $
124  *
125  */
126 
127