* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold (bonefish@users.sf.net)
*/
#include <AppMisc.h>
#include <MessageUtils.h>
#include "TokenSpace.h"
#include <Application.h>
#include <Handler.h>
#include <Looper.h>
#include <LooperList.h>
#include <Message.h>
#include <MessagePrivate.h>
#include <Messenger.h>
#include <OS.h>
#include <Roster.h>
#include <TokenSpace.h>
#include <new>
#include <stdio.h>
#include <string.h>
#define DBG(x)
#define OUT printf
*/
BMessenger::BMessenger()
:
fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1)
{
}
as the supplied messemger.
\param from The messenger to be copied.
*/
BMessenger::BMessenger(const BMessenger& from)
:
fPort(from.fPort),
fHandlerToken(from.fHandlerToken),
fTeam(from.fTeam)
{
}
*/
BMessenger::~BMessenger()
{
}
\param from the messenger to be copied.
\return A reference to this object.
*/
BMessenger &
BMessenger::operator=(const BMessenger &from)
{
if (this != &from) {
fPort = from.fPort;
fHandlerToken = from.fHandlerToken;
fTeam = from.fTeam;
}
return *this;
}
target.
\param other The other messenger.
\return \c true, if the messengers have the same target or if both aren't
properly initialzed, \c false otherwise.
*/
bool
BMessenger::operator==(const BMessenger &other) const
{
return fPort == other.fPort
&& fHandlerToken == other.fHandlerToken;
}
It is not checked whether the target handler is also still existing.
\return \c true, if the messenger's target looper does still exist,
\c false otherwise.
*/
bool
BMessenger::IsValid() const
{
return fPort >= 0;
}
\return The team of the messenger's target.
*/
team_id
BMessenger::Team() const
{
return fTeam;
}
To target the preferred handler, use B_PREFERRED_TOKEN as token.
\param team The target's team.
\param port The target looper port.
\param token The target handler token.
*/
void
BMessenger::_SetTo(team_id team, port_id port, int32 token)
{
fTeam = team;
fPort = port;
fHandlerToken = token;
}
second one.
This method defines an order on BMessengers based on their member
variables \c fPort, \c fHandlerToken and \c fPreferredTarget.
\param a The first messenger.
\param b The second messenger.
\return \c true, if \a a is less than \a b, \c false otherwise.
*/
bool
operator<(const BMessenger &_a, const BMessenger &_b)
{
BMessenger::Private a(const_cast<BMessenger&>(_a));
BMessenger::Private b(const_cast<BMessenger&>(_b));
return (a.Port() < b.Port()
|| (a.Port() == b.Port()
&& (a.Token() < b.Token()
|| (a.Token() == b.Token()
&& !a.IsPreferredTarget()
&& b.IsPreferredTarget()))));
}
\param a The first messenger.
\param b The second messenger.
\return \c false, if \a a and \a b have the same targets or are both not
properly initialized, \c true otherwise.
*/
bool
operator!=(const BMessenger &a, const BMessenger &b)
{
return !(a == b);
}