vfs: check userland buffers before reading them.
[haiku.git] / src / servers / registrar / Watcher.cpp
blob4cfc356155b84162c474d214007a79a7add99420
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:
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: 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 //------------------------------------------------------------------------------
28 #include <Message.h>
30 #include "MessageDeliverer.h"
31 #include "Watcher.h"
33 // Watcher
35 /*! \class Watcher
36 \brief A Watcher represents a target of a watching service.
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.
44 /*! \var Watcher::fTarget
45 \brief The watcher's message target.
48 // constructor
49 /*! \brief Creates a new watcher with a specified target.
51 The supplied BMessenger is copied, that is the caller can delete the
52 object when the constructor returns.
54 \param target The watcher's message target.
56 Watcher::Watcher(const BMessenger &target)
57 : fTarget(target)
61 // destructor
62 /*! \brief Frees all resources associated with the object.
64 Watcher::~Watcher()
68 // Target
69 /*! \brief Returns the watcher's message target.
70 \return The watcher's message target.
72 const BMessenger&
73 Watcher::Target() const
75 return fTarget;
78 // SendMessage
79 /*! \brief Sends the supplied message to the watcher's message target.
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.
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.
89 status_t
90 Watcher::SendMessage(BMessage *message)
92 return MessageDeliverer::Default()->DeliverMessage(message, fTarget);
96 // WatcherFilter
98 /*! \class WatcherFilter
99 \brief A WatcherFilter represents a predicate on Watchers.
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.
106 // constructor
107 /*! \brief Creates a new WatchingFilter.
109 WatcherFilter::WatcherFilter()
113 // destructor
114 /*! \brief Frees all resources associated with the object.
116 WatcherFilter::~WatcherFilter()
120 // Filter
121 /*! \brief Returns whether the watcher-message pair satisfies the predicate
122 represented by this object.
124 Derived classes override this method. This version always returns \c true.
126 \param watcher The watcher in question.
127 \param message The message in question.
128 \return \c true.
130 bool
131 WatcherFilter::Filter(Watcher *watcher, BMessage *message)
133 return true;