1 //------------------------------------------------------------------------------
2 // Copyright (c) 2001-2002, OpenBeOS
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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.
22 // File Name: EventMaskWatcher.cpp
23 // Author: Ingo Weinhold (bonefish@users.sf.net)
24 // Description: EventMaskWatcher is a Watcher extended by an event mask.
25 // EventMaskWatcherFilter filters EventMaskWatchers with
26 // respect to their event mask and a specific event.
27 //------------------------------------------------------------------------------
29 #include "EventMaskWatcher.h"
33 /*! \class EventMaskWatcher
34 \brief EventMaskWatcher is a Watcher extended by an event mask.
36 Each set bit in the watcher's event mask specifies an event the watcher
37 wants to get notified about.
39 This class is intended to be used together with EventMaskWatcherFilter.
40 Such a filter object is created with a certain event and its
41 EventMaskWatcherFilter::Filter() method only selects those
42 EventMaskWatchers with an event mask that contains the event.
45 /*! \var uint32 EventMaskWatcher::fEventMask
46 \brief The watcher's event mask.
50 /*! \brief Creates a new EventMaskWatcher with a given target and event mask.
51 \param target The watcher's message target.
52 \param eventMask the watcher's event mask.
54 EventMaskWatcher::EventMaskWatcher(const BMessenger
&target
, uint32 eventMask
)
61 /*! \brief Returns the watcher's event mask.
62 \return The watcher's event mask.
65 EventMaskWatcher::EventMask() const
71 // EventMaskWatcherFilter
73 /*! \class EventMaskWatcherFilter
74 \brief EventMaskWatcherFilter filters EventMaskWatchers with respect to
75 their event mask and a specific event.
77 This class is intended to be used together with EventMaskWatcher.
78 A filter object is created with a certain event and its Filter() method
79 only selects those EventMaskWatchers with an event mask that contains
83 /*! \var uint32 EventMaskWatcherFilter::fEvent
84 \brief The filter's event.
86 Filter only returns \c true for watchers whose event mask contains the
91 /*! \brief Creates a new EventMaskWatcherFilter with a specified event.
93 Actually \a event may specify more than one event. Usually each set bit
96 \param event The event.
98 EventMaskWatcherFilter::EventMaskWatcherFilter(uint32 event
)
105 /*! \brief Returns whether the watcher-message pair satisfies the predicate
106 represented by this object.
108 Returns \c true, if the supplied watcher is an EventMaskWatcher and its
109 event mask contains this filter's event, or more precise the bitwise AND
110 on event mask and event is not 0.
112 \param watcher The watcher in question.
113 \param message The message in question.
114 \return \c true, if the watcher's event mask contains the filter's event.
117 EventMaskWatcherFilter::Filter(Watcher
*watcher
, BMessage
*message
)
119 EventMaskWatcher
*emWatcher
= dynamic_cast<EventMaskWatcher
*>(watcher
);
120 return (emWatcher
&& (emWatcher
->EventMask() & fEvent
));