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 <BeBuild.h> 13 #include <Handler.h> 14 15 16 class BMessage; 17 18 // filter_hook Return Codes and Protocol --------------------------------------- 19 enum filter_result { 20 B_SKIP_MESSAGE, 21 B_DISPATCH_MESSAGE 22 }; 23 24 typedef filter_result (*filter_hook) 25 (BMessage* message, BHandler** target, BMessageFilter* filter); 26 27 28 // BMessageFilter invocation criteria ------------------------------------------ 29 enum message_delivery { 30 B_ANY_DELIVERY, 31 B_DROPPED_DELIVERY, 32 B_PROGRAMMED_DELIVERY 33 }; 34 35 enum message_source { 36 B_ANY_SOURCE, 37 B_REMOTE_SOURCE, 38 B_LOCAL_SOURCE 39 }; 40 41 42 // BMessageFilter Class -------------------------------------------------------- 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 bool fFiltersAny; 77 uint32 fWhat; 78 message_delivery fDelivery; 79 message_source fSource; 80 BLooper *fLooper; 81 filter_hook fFilterFunction; 82 uint32 _reserved[3]; 83 }; 84 85 #endif // _MESSAGE_FILTER_H 86