2 * Copyright 2001-2007, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold (bonefish@users.sf.net)
11 #include <MessageUtils.h>
12 #include "TokenSpace.h"
14 #include <Application.h>
17 #include <LooperList.h>
19 #include <MessagePrivate.h>
20 #include <Messenger.h>
23 #include <TokenSpace.h>
37 NOT_IMPLEMENTED
= B_ERROR
,
41 /*! \brief Creates an unitialized BMessenger.
43 BMessenger::BMessenger()
46 fHandlerToken(B_NULL_TOKEN
),
52 /*! \brief Creates a BMessenger and initializes it to have the same target
53 as the supplied messemger.
55 \param from The messenger to be copied.
57 BMessenger::BMessenger(const BMessenger
& from
)
60 fHandlerToken(from
.fHandlerToken
),
66 /*! \brief Frees all resources associated with this object.
68 BMessenger::~BMessenger()
73 // #pragma mark - Operators and misc
76 /*! \brief Makes this BMessenger a copy of the supplied one.
78 \param from the messenger to be copied.
79 \return A reference to this object.
82 BMessenger::operator=(const BMessenger
&from
)
86 fHandlerToken
= from
.fHandlerToken
;
93 /*! \brief Returns whether this and the supplied messenger have the same
96 \param other The other messenger.
97 \return \c true, if the messengers have the same target or if both aren't
98 properly initialzed, \c false otherwise.
101 BMessenger::operator==(const BMessenger
&other
) const
103 // Note: The fTeam fields are not compared.
104 return fPort
== other
.fPort
105 && fHandlerToken
== other
.fHandlerToken
;
109 /*! \brief Returns whether the messenger's target looper does still exist.
111 It is not checked whether the target handler is also still existing.
113 \return \c true, if the messenger's target looper does still exist,
117 BMessenger::IsValid() const
123 /*! \brief Returns the ID of the team the messenger's target lives in.
125 \return The team of the messenger's target.
128 BMessenger::Team() const
134 // #pragma mark - Private or reserved
137 /*! \brief Sets the messenger's team, target looper port and handler token.
139 To target the preferred handler, use B_PREFERRED_TOKEN as token.
141 \param team The target's team.
142 \param port The target looper port.
143 \param token The target handler token.
146 BMessenger::_SetTo(team_id team
, port_id port
, int32 token
)
150 fHandlerToken
= token
;
154 /*! \brief Returns whether the first one of two BMessengers is less than the
157 This method defines an order on BMessengers based on their member
158 variables \c fPort, \c fHandlerToken and \c fPreferredTarget.
160 \param a The first messenger.
161 \param b The second messenger.
162 \return \c true, if \a a is less than \a b, \c false otherwise.
165 operator<(const BMessenger
&_a
, const BMessenger
&_b
)
167 BMessenger::Private
a(const_cast<BMessenger
&>(_a
));
168 BMessenger::Private
b(const_cast<BMessenger
&>(_b
));
173 // 3. fPreferredTarget
174 // fTeam is insignificant
175 return (a
.Port() < b
.Port()
176 || (a
.Port() == b
.Port()
177 && (a
.Token() < b
.Token()
178 || (a
.Token() == b
.Token()
179 && !a
.IsPreferredTarget()
180 && b
.IsPreferredTarget()))));
184 /*! \brief Returns whether two BMessengers have not the same target.
186 \param a The first messenger.
187 \param b The second messenger.
188 \return \c false, if \a a and \a b have the same targets or are both not
189 properly initialized, \c true otherwise.
192 operator!=(const BMessenger
&a
, const BMessenger
&b
)