1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, Haiku 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: Watcher.cpp 23 // Author: Ingo Weinhold (bonefish@users.sf.net) 24 // Description: A Watcher represents a target of a watching service. 25 // A WatcherFilter represents a predicate on Watchers. 26 //------------------------------------------------------------------------------ 27 28 #include <Message.h> 29 30 #include "MessageDeliverer.h" 31 #include "Watcher.h" 32 33 // Watcher 34 35 /*! \class Watcher 36 \brief A Watcher represents a target of a watching service. 37 38 The Watcher base class only has one attribute, a BMessenger which 39 specifies the target to which notification messages shall be sent. 40 SendMessage() actually sends the message to the target. It can be 41 overridden in case of special needs. 42 */ 43 44 /*! \var Watcher::fTarget 45 \brief The watcher's message target. 46 */ 47 48 // constructor 49 /*! \brief Creates a new watcher with a specified target. 50 51 The supplied BMessenger is copied, that is the caller can delete the 52 object when the constructor returns. 53 54 \param target The watcher's message target. 55 */ 56 Watcher::Watcher(const BMessenger &target) 57 : fTarget(target) 58 { 59 } 60 61 // destructor 62 /*! \brief Frees all resources associated with the object. 63 */ 64 Watcher::~Watcher() 65 { 66 } 67 68 // Target 69 /*! \brief Returns the watcher's message target. 70 \return The watcher's message target. 71 */ 72 const BMessenger& 73 Watcher::Target() const 74 { 75 return fTarget; 76 } 77 78 // SendMessage 79 /*! \brief Sends the supplied message to the watcher's message target. 80 81 The method can be overridden by a derived class to e.g. add additional 82 fields to the message. Note, that in this case the message must not be 83 modified directly, but a copy has to be made. 84 85 \param message The message to be sent. 86 \return \c B_OK, if everything went fine, another error code, if an error 87 occured. 88 */ 89 status_t 90 Watcher::SendMessage(BMessage *message) 91 { 92 return MessageDeliverer::Default()->DeliverMessage(message, fTarget); 93 } 94 95 96 // WatcherFilter 97 98 /*! \class WatcherFilter 99 \brief A WatcherFilter represents a predicate on Watchers. 100 101 It's only method Filter() returns whether a given Watcher and a BMessage 102 satisfy the predicate. This class' Filter() implementation always returns 103 \c true. Derived classes override it. 104 */ 105 106 // constructor 107 /*! \brief Creates a new WatchingFilter. 108 */ 109 WatcherFilter::WatcherFilter() 110 { 111 } 112 113 // destructor 114 /*! \brief Frees all resources associated with the object. 115 */ 116 WatcherFilter::~WatcherFilter() 117 { 118 } 119 120 // Filter 121 /*! \brief Returns whether the watcher-message pair satisfies the predicate 122 represented by this object. 123 124 Derived classes override this method. This version always returns \c true. 125 126 \param watcher The watcher in question. 127 \param message The message in question. 128 \return \c true. 129 */ 130 bool 131 WatcherFilter::Filter(Watcher *watcher, BMessage *message) 132 { 133 return true; 134 } 135 136