MessageFilter.cpp revision 6f4cf451
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.cpp
23//	Author:			Erik Jaesler (erik@cgsoftware.com)
24//	Description:	BMessageFilter class creates objects that filter
25//					in-coming BMessages.
26//------------------------------------------------------------------------------
27
28#include <MessageFilter.h>
29
30BMessageFilter::BMessageFilter(uint32 inWhat, filter_hook func)
31	:	fFiltersAny(false),
32		what(inWhat),
33		fDelivery(B_ANY_DELIVERY),
34		fSource(B_ANY_SOURCE),
35		fLooper(NULL),
36		fFilterFunction(func)
37{
38}
39
40
41BMessageFilter::BMessageFilter(message_delivery delivery, message_source source,
42							   filter_hook func)
43	:	fFiltersAny(true),
44		what(0),
45		fDelivery(delivery),
46		fSource(source),
47		fLooper(NULL),
48		fFilterFunction(func)
49{
50}
51
52
53BMessageFilter::BMessageFilter(message_delivery delivery, message_source source,
54							   uint32 inWhat, filter_hook func)
55	:	fFiltersAny(false),
56		what(inWhat),
57		fDelivery(delivery),
58		fSource(source),
59		fLooper(NULL),
60		fFilterFunction(func)
61{
62}
63
64
65BMessageFilter::BMessageFilter(const BMessageFilter& filter)
66{
67	*this = filter;
68}
69
70
71BMessageFilter::BMessageFilter(const BMessageFilter* filter)
72{
73	*this = *filter;
74}
75
76
77BMessageFilter::~BMessageFilter()
78{
79}
80
81
82BMessageFilter &
83BMessageFilter::operator=(const BMessageFilter& from)
84{
85	fFiltersAny			= from.FiltersAnyCommand();
86	what				= from.Command();
87	fDelivery			= from.MessageDelivery();
88	fSource				= from.MessageSource();
89	fFilterFunction		= from.FilterFunction();
90
91	SetLooper(from.Looper());
92
93	return *this;
94}
95
96
97filter_result
98BMessageFilter::Filter(BMessage* message, BHandler** target)
99{
100	return B_DISPATCH_MESSAGE;
101}
102
103
104message_delivery
105BMessageFilter::MessageDelivery() const
106{
107	return fDelivery;
108}
109
110
111message_source
112BMessageFilter::MessageSource() const
113{
114	return fSource;
115}
116
117
118uint32
119BMessageFilter::Command() const
120{
121	return what;
122}
123
124
125bool
126BMessageFilter::FiltersAnyCommand() const
127{
128	return fFiltersAny;
129}
130
131
132BLooper *
133BMessageFilter::Looper() const
134{
135	return fLooper;
136}
137
138
139void BMessageFilter::_ReservedMessageFilter1() {}
140void BMessageFilter::_ReservedMessageFilter2() {}
141
142
143void
144BMessageFilter::SetLooper(BLooper* owner)
145{
146	fLooper = owner;
147}
148
149
150filter_hook
151BMessageFilter::FilterFunction() const
152{
153	return fFilterFunction;
154}
155