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