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 // Standard Includes ----------------------------------------------------------- 29 30 // System Includes ------------------------------------------------------------- 31 #include <MessageFilter.h> 32 33 // Project Includes ------------------------------------------------------------ 34 35 // Local Includes -------------------------------------------------------------- 36 37 // Local Defines --------------------------------------------------------------- 38 39 // Globals --------------------------------------------------------------------- 40 41 //------------------------------------------------------------------------------ 42 BMessageFilter::BMessageFilter(uint32 inWhat, filter_hook func) 43 : fFiltersAny(false), 44 what(inWhat), 45 fDelivery(B_ANY_DELIVERY), 46 fSource(B_ANY_SOURCE), 47 fLooper(NULL), 48 fFilterFunction(func) 49 { 50 } 51 //------------------------------------------------------------------------------ 52 BMessageFilter::BMessageFilter(message_delivery delivery, message_source source, 53 filter_hook func) 54 : fFiltersAny(true), 55 what(0), 56 fDelivery(delivery), 57 fSource(source), 58 fLooper(NULL), 59 fFilterFunction(func) 60 { 61 } 62 //------------------------------------------------------------------------------ 63 BMessageFilter::BMessageFilter(message_delivery delivery, message_source source, 64 uint32 inWhat, filter_hook func) 65 : fFiltersAny(false), 66 what(inWhat), 67 fDelivery(delivery), 68 fSource(source), 69 fLooper(NULL), 70 fFilterFunction(func) 71 { 72 } 73 //------------------------------------------------------------------------------ 74 BMessageFilter::BMessageFilter(const BMessageFilter& filter) 75 { 76 *this = filter; 77 } 78 //------------------------------------------------------------------------------ 79 BMessageFilter::BMessageFilter(const BMessageFilter* filter) 80 { 81 *this = *filter; 82 } 83 //------------------------------------------------------------------------------ 84 BMessageFilter::~BMessageFilter() 85 { 86 ; 87 } 88 //------------------------------------------------------------------------------ 89 BMessageFilter& BMessageFilter::operator=(const BMessageFilter& from) 90 { 91 fFiltersAny = from.FiltersAnyCommand(); 92 what = from.Command(); 93 fDelivery = from.MessageDelivery(); 94 fSource = from.MessageSource(); 95 fFilterFunction = from.FilterFunction(); 96 97 SetLooper(from.Looper()); 98 99 return *this; 100 } 101 //------------------------------------------------------------------------------ 102 filter_result BMessageFilter::Filter(BMessage* message, BHandler** target) 103 { 104 if (fFilterFunction) 105 { 106 return fFilterFunction(message, target, this); 107 } 108 109 return B_DISPATCH_MESSAGE; 110 } 111 //------------------------------------------------------------------------------ 112 message_delivery BMessageFilter::MessageDelivery() const 113 { 114 return fDelivery; 115 } 116 //------------------------------------------------------------------------------ 117 message_source BMessageFilter::MessageSource() const 118 { 119 return fSource; 120 } 121 //------------------------------------------------------------------------------ 122 uint32 BMessageFilter::Command() const 123 { 124 return what; 125 } 126 //------------------------------------------------------------------------------ 127 bool BMessageFilter::FiltersAnyCommand() const 128 { 129 return fFiltersAny; 130 } 131 //------------------------------------------------------------------------------ 132 BLooper* BMessageFilter::Looper() const 133 { 134 return fLooper; 135 } 136 //------------------------------------------------------------------------------ 137 void BMessageFilter::_ReservedMessageFilter1() 138 { 139 ; 140 } 141 //------------------------------------------------------------------------------ 142 void BMessageFilter::_ReservedMessageFilter2() 143 { 144 ; 145 } 146 //------------------------------------------------------------------------------ 147 void BMessageFilter::SetLooper(BLooper* owner) 148 { 149 // TODO: implement locking? 150 fLooper = owner; 151 } 152 //------------------------------------------------------------------------------ 153 filter_hook BMessageFilter::FilterFunction() const 154 { 155 return fFilterFunction; 156 } 157 //------------------------------------------------------------------------------ 158 159 /* 160 * $Log $ 161 * 162 * $Id $ 163 * 164 */ 165 166