16d894312SIngo Weinhold//------------------------------------------------------------------------------
26d894312SIngo Weinhold//	Copyright (c) 2001-2002, OpenBeOS
36d894312SIngo Weinhold//
46d894312SIngo Weinhold//	Permission is hereby granted, free of charge, to any person obtaining a
56d894312SIngo Weinhold//	copy of this software and associated documentation files (the "Software"),
66d894312SIngo Weinhold//	to deal in the Software without restriction, including without limitation
76d894312SIngo Weinhold//	the rights to use, copy, modify, merge, publish, distribute, sublicense,
86d894312SIngo Weinhold//	and/or sell copies of the Software, and to permit persons to whom the
96d894312SIngo Weinhold//	Software is furnished to do so, subject to the following conditions:
106d894312SIngo Weinhold//
116d894312SIngo Weinhold//	The above copyright notice and this permission notice shall be included in
126d894312SIngo Weinhold//	all copies or substantial portions of the Software.
136d894312SIngo Weinhold//
146d894312SIngo Weinhold//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
156d894312SIngo Weinhold//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166d894312SIngo Weinhold//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
176d894312SIngo Weinhold//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
186d894312SIngo Weinhold//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
196d894312SIngo Weinhold//	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
206d894312SIngo Weinhold//	DEALINGS IN THE SOFTWARE.
216d894312SIngo Weinhold//
226d894312SIngo Weinhold//	File Name:		Watcher.cpp
236d894312SIngo Weinhold//	Author:			Ingo Weinhold (bonefish@users.sf.net)
246d894312SIngo Weinhold//	Description:	A Watcher represents a target of a watching service.
255f20a509SIngo Weinhold//					A WatcherFilter represents a predicate on Watchers.
266d894312SIngo Weinhold//------------------------------------------------------------------------------
276d894312SIngo Weinhold
286d894312SIngo Weinhold#include <Message.h>
296d894312SIngo Weinhold
30634f747eSIngo Weinhold#include "MessageDeliverer.h"
316d894312SIngo Weinhold#include "Watcher.h"
326d894312SIngo Weinhold
336d894312SIngo Weinhold// Watcher
346d894312SIngo Weinhold
355f20a509SIngo Weinhold/*!	\class Watcher
365f20a509SIngo Weinhold	\brief A Watcher represents a target of a watching service.
375f20a509SIngo Weinhold
385f20a509SIngo Weinhold	The Watcher base class only has one attribute, a BMessenger which
395f20a509SIngo Weinhold	specifies the target to which notification messages shall be sent.
405f20a509SIngo Weinhold	SendMessage() actually sends the message to the target. It can be
415f20a509SIngo Weinhold	overridden in case of special needs.
425f20a509SIngo Weinhold*/
435f20a509SIngo Weinhold
445f20a509SIngo Weinhold/*!	\var Watcher::fTarget
455f20a509SIngo Weinhold	\brief The watcher's message target.
465f20a509SIngo Weinhold*/
475f20a509SIngo Weinhold
486d894312SIngo Weinhold// constructor
495f20a509SIngo Weinhold/*!	\brief Creates a new watcher with a specified target.
505f20a509SIngo Weinhold
515f20a509SIngo Weinhold	The supplied BMessenger is copied, that is the caller can delete the
525f20a509SIngo Weinhold	object when the constructor returns.
535f20a509SIngo Weinhold
545f20a509SIngo Weinhold	\param target The watcher's message target.
555f20a509SIngo Weinhold*/
566d894312SIngo WeinholdWatcher::Watcher(const BMessenger &target)
576d894312SIngo Weinhold	: fTarget(target)
586d894312SIngo Weinhold{
596d894312SIngo Weinhold}
606d894312SIngo Weinhold
616d894312SIngo Weinhold// destructor
625f20a509SIngo Weinhold/*!	\brief Frees all resources associated with the object.
635f20a509SIngo Weinhold*/
646d894312SIngo WeinholdWatcher::~Watcher()
656d894312SIngo Weinhold{
666d894312SIngo Weinhold}
676d894312SIngo Weinhold
686d894312SIngo Weinhold// Target
695f20a509SIngo Weinhold/*!	\brief Returns the watcher's message target.
705f20a509SIngo Weinhold	\return The watcher's message target.
715f20a509SIngo Weinhold*/
726d894312SIngo Weinholdconst BMessenger&
736d894312SIngo WeinholdWatcher::Target() const
746d894312SIngo Weinhold{
756d894312SIngo Weinhold	return fTarget;
766d894312SIngo Weinhold}
776d894312SIngo Weinhold
786d894312SIngo Weinhold// SendMessage
795f20a509SIngo Weinhold/*!	\brief Sends the supplied message to the watcher's message target.
805f20a509SIngo Weinhold
815f20a509SIngo Weinhold	The method can be overridden by a derived class to e.g. add additional
825f20a509SIngo Weinhold	fields to the message. Note, that in this case the message must not be
835f20a509SIngo Weinhold	modified directly, but a copy has to be made.
845f20a509SIngo Weinhold
855f20a509SIngo Weinhold	\param message The message to be sent.
865f20a509SIngo Weinhold	\return \c B_OK, if everything went fine, another error code, if an error
875f20a509SIngo Weinhold			occured.
885f20a509SIngo Weinhold*/
896d894312SIngo Weinholdstatus_t
906d894312SIngo WeinholdWatcher::SendMessage(BMessage *message)
916d894312SIngo Weinhold{
92634f747eSIngo Weinhold	return MessageDeliverer::Default()->DeliverMessage(message, fTarget);
936d894312SIngo Weinhold}
946d894312SIngo Weinhold
956d894312SIngo Weinhold
966d894312SIngo Weinhold// WatcherFilter
976d894312SIngo Weinhold
985f20a509SIngo Weinhold/*!	\class WatcherFilter
995f20a509SIngo Weinhold	\brief A WatcherFilter represents a predicate on Watchers.
1005f20a509SIngo Weinhold
1015f20a509SIngo Weinhold	It's only method Filter() returns whether a given Watcher and a BMessage
1025f20a509SIngo Weinhold	satisfy the predicate. This class' Filter() implementation always returns
1035f20a509SIngo Weinhold	\c true. Derived classes override it.
1045f20a509SIngo Weinhold*/
1055f20a509SIngo Weinhold
1066d894312SIngo Weinhold// constructor
1075f20a509SIngo Weinhold/*!	\brief Creates a new WatchingFilter.
1085f20a509SIngo Weinhold*/
1096d894312SIngo WeinholdWatcherFilter::WatcherFilter()
1106d894312SIngo Weinhold{
1116d894312SIngo Weinhold}
1126d894312SIngo Weinhold
1136d894312SIngo Weinhold// destructor
1145f20a509SIngo Weinhold/*!	\brief Frees all resources associated with the object.
1155f20a509SIngo Weinhold*/
1166d894312SIngo WeinholdWatcherFilter::~WatcherFilter()
1176d894312SIngo Weinhold{
1186d894312SIngo Weinhold}
1196d894312SIngo Weinhold
1206d894312SIngo Weinhold// Filter
1215f20a509SIngo Weinhold/*!	\brief Returns whether the watcher-message pair satisfies the predicate
1225f20a509SIngo Weinhold		   represented by this object.
1235f20a509SIngo Weinhold
1245f20a509SIngo Weinhold	Derived classes override this method. This version always returns \c true.
1255f20a509SIngo Weinhold
1265f20a509SIngo Weinhold	\param watcher The watcher in question.
1275f20a509SIngo Weinhold	\param message The message in question.
1285f20a509SIngo Weinhold	\return \c true.
1295f20a509SIngo Weinhold*/
1306d894312SIngo Weinholdbool
1316d894312SIngo WeinholdWatcherFilter::Filter(Watcher *watcher, BMessage *message)
1326d894312SIngo Weinhold{
1336d894312SIngo Weinhold	return true;
1346d894312SIngo Weinhold}
1356d894312SIngo Weinhold
136