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