xref: /haiku/headers/os/app/MessageFilter.h (revision be902ac4db5c9d0be72f6d54aa67b66e3dcc7eca)
1 /*
2  * Copyright 2001-2014 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 _MESSAGE_FILTER_H
9 #define _MESSAGE_FILTER_H
10 
11 
12 #include <Handler.h>
13 
14 
15 class BMessage;
16 
17 
18 // filter_hook Return Codes and Protocol
19 enum filter_result {
20 	B_SKIP_MESSAGE,
21 	B_DISPATCH_MESSAGE
22 };
23 
24 
25 typedef filter_result (*filter_hook)
26 	(BMessage* message, BHandler** target, BMessageFilter* filter);
27 
28 
29 // BMessageFilter invocation criteria
30 enum message_delivery {
31 	B_ANY_DELIVERY,
32 	B_DROPPED_DELIVERY,
33 	B_PROGRAMMED_DELIVERY
34 };
35 
36 enum message_source {
37 	B_ANY_SOURCE,
38 	B_REMOTE_SOURCE,
39 	B_LOCAL_SOURCE
40 };
41 
42 
43 class BMessageFilter {
44 public:
45 								BMessageFilter(uint32 what,
46 									filter_hook func = NULL);
47 								BMessageFilter(message_delivery delivery,
48 									message_source source, filter_hook func = NULL);
49 								BMessageFilter(message_delivery delivery,
50 									message_source source, uint32 what,
51 									filter_hook func = NULL);
52 								BMessageFilter(const BMessageFilter& filter);
53 								BMessageFilter(const BMessageFilter* filter);
54 	virtual						~BMessageFilter();
55 
56 			BMessageFilter&		operator=(const BMessageFilter& from);
57 
58 			// Hook function; ignored if filter_hook is non-NULL
59 	virtual	filter_result		Filter(BMessage* message, BHandler** _target);
60 
61 			message_delivery	MessageDelivery() const;
62 			message_source		MessageSource() const;
63 			uint32				Command() const;
64 			bool				FiltersAnyCommand() const;
65 			BLooper*			Looper() const;
66 
67 private:
68 	friend class BLooper;
69 	friend class BHandler;
70 
71 	virtual	void				_ReservedMessageFilter1();
72 	virtual	void				_ReservedMessageFilter2();
73 
74 			void				SetLooper(BLooper* owner);
75 			filter_hook			FilterFunction() const;
76 
77 			bool				fFiltersAny;
78 			uint32				fWhat;
79 			message_delivery	fDelivery;
80 			message_source		fSource;
81 			BLooper*			fLooper;
82 			filter_hook			fFilterFunction;
83 
84 			uint32				_reserved[3];
85 };
86 
87 
88 #endif	// _MESSAGE_FILTER_H
89