* reverted Adi's premature changes to BWindow and restored _DetermineTarget() and

task_looper() again.
* removed BMessenger::fPreferred - whenever you had to specify "usePreferred" separately,
  you don't have to do that anymore - use B_PREFERRED_TOKEN instead.
* fixed BTokenSpace::GetToken() semantics: it will no longer touch the "object" argument
  in case of failure.
* Introduced a BWindow::_DistributeMessage() that will be part of the event dispatcher
  counterpart to the app_server (the other will be _DetermineTarget()).
* Made it easier to use Michael's Message4 implementation: just add the following line
  to your UserBuildConfig:
	AppendToConfigVar DEFINES : HAIKU_TOP src : USING_MESSAGE4 : global ;
* Introduced ServerWindow::HandlerMessenger() and FocusMessenger() - the first will
  target the client handler, while the other will target the preferred handler of the
  client looper (usually the view having focus).
* Fixed dano message unflattening in the Message4 code.
* Changed BMessage::PrintToStream() to no longer use macros in the Message4 implementation.
* I hope that's all - it's a huge change, but it's all connected.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15046 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-20 16:24:23 +00:00
parent 26e09e5870
commit 4ceb1e519c
29 changed files with 752 additions and 647 deletions
+7 -4
View File
@@ -6,6 +6,10 @@
* Erik Jaesler ([email protected])
* DarkWyrm <[email protected]>
*/
#ifdef USING_MESSAGE4
# include <Message4.h>
#else
#ifndef _MESSAGE_H
#define _MESSAGE_H
@@ -309,20 +313,17 @@ virtual void _ReservedMessage3();
status_t _send_(port_id port,
int32 token,
bool preferred,
bigtime_t timeout,
bool reply_required,
BMessenger &reply_to) const;
status_t send_message(port_id port,
team_id port_owner,
int32 token,
bool preferred,
BMessage *reply,
bigtime_t send_timeout,
bigtime_t reply_timeout) const;
static status_t _SendFlattenedMessage(void *data, int32 size,
port_id port, int32 token, bool preferred,
bigtime_t timeout);
port_id port, int32 token, bigtime_t timeout);
static void _StaticInit();
static void _StaticCleanup();
@@ -429,3 +430,5 @@ static BBlockCache *sMsgCache;
};
#endif // _MESSAGE_H
#endif // USING_MESSAGE4
+10 -10
View File
@@ -9,7 +9,10 @@
#ifndef _MESSAGE_H
#define _MESSAGE_H
#define USING_MESSAGE4 1
// this should be defined in your UserBuildConfig only
#ifndef USING_MESSAGE4
# define USING_MESSAGE4 1
#endif
#include <BeBuild.h>
#include <DataIO.h>
@@ -39,8 +42,7 @@ extern "C" int _delete_message_();
#define B_FIELD_NAME_LENGTH 255
#define B_PROPERTY_NAME_LENGTH 255
enum
{
enum {
B_NO_SPECIFIER = 0,
B_DIRECT_SPECIFIER = 1,
B_INDEX_SPECIFIER,
@@ -304,15 +306,13 @@ virtual void _ReservedMessage1();
virtual void _ReservedMessage2();
virtual void _ReservedMessage3();
status_t _SendMessage(port_id port, int32 token, bool preferred,
bigtime_t timeout, bool replyRequired,
BMessenger &replyTo) const;
status_t _SendMessage(port_id port, int32 token, bigtime_t timeout,
bool replyRequired, BMessenger &replyTo) const;
status_t _SendMessage(port_id port, team_id portOwner,
int32 token, bool preferred, BMessage *reply,
bigtime_t sendTimeout, bigtime_t replyTimeout) const;
int32 token, BMessage *reply, bigtime_t sendTimeout,
bigtime_t replyTimeout) const;
static status_t _SendFlattenedMessage(void *data, int32 size,
port_id port, int32 token, bool preferred,
bigtime_t timeout);
port_id port, int32 token, bigtime_t timeout);
static void _StaticInit();
static void _StaticCleanup();
+12 -46
View File
@@ -1,52 +1,23 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Messenger.h
// Author: Ingo Weinhold ([email protected])
// Description: BMessenger delivers messages to local or remote targets.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold ([email protected])
*/
#ifndef _MESSENGER_H
#define _MESSENGER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h>
#include <OS.h>
#include <ByteOrder.h>
#include <Message.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class BHandler;
class BLooper;
// BMessenger class ------------------------------------------------------------
class BMessenger {
public:
BMessenger();
@@ -90,21 +61,16 @@ public:
private:
friend class Private;
void SetTo(team_id team, port_id port, int32 token, bool preferred);
void InitData(const char *signature, team_id team, status_t *result);
void _SetTo(team_id team, port_id port, int32 token);
void _InitData(const char *signature, team_id team, status_t *result);
private:
port_id fPort;
int32 fHandlerToken;
team_id fTeam;
int32 extra0;
int32 extra1;
bool fPreferredTarget;
bool extra2;
bool extra3;
bool extra4;
int32 _reserved[3];
};
_IMPEXP_BE bool operator<(const BMessenger &a, const BMessenger &b);
+11 -43
View File
@@ -294,53 +294,23 @@ private:
int32 bitmapToken = -1);
status_t ArchiveChildren(BMessage* data, bool deep) const;
status_t UnarchiveChildren(BMessage* data);
void BitmapClose(); // to be implemented
virtual void task_looper(); // thread function - it's here where app_server messages are received
/* void start_drag( BMessage* msg,
int32 token,
BPoint offset,
BRect track_rect,
BHandler* reply_to);
void start_drag( BMessage* msg,
int32 token,
BPoint offset,
int32 bitmap_token,
drawing_mode dragMode,
BHandler* reply_to);
*/
void BitmapClose(); // to be implemented
virtual void task_looper();
void prepareView(BView* aView);
void attachView(BView* aView);
void detachView(BView* aView);
//int32 get_server_token() const;
BMessage *extract_drop(BMessage* an_event, BHandler* *target);
//void movesize(uint32 opcode, float h, float v);
//int32 MessagesWaiting();
void handle_activate(BMessage* an_event);
//void do_view_frame(BMessage* an_event);
//void do_value_change(BMessage* an_event, BHandler* handler);
//void do_mouse_down(BMessage* an_event, BView* target);
//void do_mouse_moved(BMessage* an_event, BView* target);
//void do_key_down(BMessage* an_event, BHandler* handler);
//void do_key_up(BMessage* an_event, BHandler* handler);
void do_menu_event(BMessage* an_event);
//void do_draw_views();
virtual BMessage *ConvertToMessage(void* raw, int32 code);
//_cmd_key_ *allocShortcut(uint32 key, uint32 modifiers);
//_cmd_key_ *FindShortcut(uint32 key, uint32 modifiers);
void AddShortcut(uint32 key, // !!! - and menu shortcuts to list when a menu is added
uint32 modifiers,
BMenuItem* item);
//void post_message(BMessage* message);
//void SetLocalTitle(const char* new_title);
//void enable_pulsing(bool enable);
//void kb_navigate();
//void navigate_to_next(int32 direction, bool group = false);
//void set_focus(BView* focus, bool notify_input_server); // what does notify_input_server mean??? why???
void AddShortcut(uint32 key, uint32 modifiers,
BMenuItem* item);
BHandler* _DetermineTarget(BMessage* message, BHandler* target);
bool _DistributeMessage(BMessage* message);
bool InUpdate();
void DequeueAll();
//bool find_token_and_handler(BMessage* msg, int32* token, BHandler* *handler);
window_type _ComposeType(window_look look,
window_feel feel) const;
void _DecomposeType(window_type type,
@@ -354,11 +324,9 @@ private:
void setFocus(BView *focusView, bool notifyIputServer = false);
Shortcut* _FindShortcut(uint32 key, uint32 modifiers);
bool findHandler(BView* start, BHandler* handler);
BView* findView(BView* aView, const char* viewName) const;
BView* findView(BView* aView, BPoint point) const;
BView* findView(BView* aView, int32 token);
BView* findLastChild(BView *parent);
BView* _FindView(BView* view, BPoint point) const;
BView* _FindView(int32 token);
BView* _LastViewChild(BView *parent);
BView* _FindNextNavigable(BView *focus, uint32 flags);
BView* _FindPreviousNavigable(BView *focus, uint32 flags);
+11 -16
View File
@@ -3,6 +3,10 @@
//
//------------------------------------------------------------------------------
#ifdef USING_MESSAGE4
# include <MessagePrivate4.h>
#else
#ifndef MESSAGEPRIVATE_H
#define MESSAGEPRIVATE_H
@@ -11,24 +15,22 @@
#include <MessengerPrivate.h>
#include <TokenSpace.h>
class BMessage::Private
{
class BMessage::Private {
public:
Private(BMessage* msg) : fMessage(msg) {;}
Private(BMessage& msg) : fMessage(&msg) {;}
inline void SetTarget(int32 token, bool preferred)
inline void SetTarget(int32 token)
{
fMessage->fTarget = token;
fMessage->fPreferred = preferred;
fMessage->fPreferred = token == B_PREFERRED_TOKEN;
}
inline void SetReply(BMessenger messenger)
{
BMessenger::Private mp(messenger);
fMessage->fReplyTo.port = mp.Port();
fMessage->fReplyTo.target
= (mp.IsPreferredTarget() ? B_PREFERRED_TOKEN : mp.Token());
fMessage->fReplyTo.target = mp.Token();
fMessage->fReplyTo.team = mp.Team();
fMessage->fReplyTo.preferred = mp.IsPreferredTarget();
}
@@ -44,10 +46,10 @@ class BMessage::Private
}
static inline status_t SendFlattenedMessage(void *data, int32 size,
port_id port, int32 token, bool preferred, bigtime_t timeout)
port_id port, int32 token, bigtime_t timeout)
{
return BMessage::_SendFlattenedMessage(data, size, port, token,
preferred, timeout);
timeout);
}
static inline void StaticInit()
@@ -70,11 +72,4 @@ class BMessage::Private
};
#endif // MESSAGEPRIVATE_H
/*
* $Log $
*
* $Id $
*
*/
#endif // USING_MESSAGE4
+119 -100
View File
@@ -1,3 +1,10 @@
/*
* Copyright 2005, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Lotz <[email protected]>
*/
#ifndef _MESSAGE_PRIVATE_H_
#define _MESSAGE_PRIVATE_H_
@@ -75,127 +82,139 @@ typedef struct message_header_s {
class BMessage::Private {
public:
Private(BMessage *msg)
: fMessage(msg)
{
}
public:
Private(BMessage *msg)
: fMessage(msg)
{
}
Private(BMessage &msg)
: fMessage(&msg)
{
}
Private(BMessage &msg)
: fMessage(&msg)
{
}
void
SetTarget(int32 token)
{
fMessage->fHeader->target = token;
}
inline void SetTarget(int32 token, bool preferred)
{
fMessage->fHeader->target = (preferred
? B_PREFERRED_TOKEN : token);
}
void
SetReply(BMessenger messenger)
{
BMessenger::Private messengerPrivate(messenger);
fMessage->fHeader->replyPort = messengerPrivate.Port();
fMessage->fHeader->replyTarget = messengerPrivate.Token();
fMessage->fHeader->replyTeam = messengerPrivate.Team();
}
inline void SetReply(BMessenger messenger)
{
BMessenger::Private messengerPrivate(messenger);
fMessage->fHeader->replyPort = messengerPrivate.Port();
fMessage->fHeader->replyTarget = messengerPrivate.Token();
fMessage->fHeader->replyTeam = messengerPrivate.Team();
}
int32
GetTarget()
{
return fMessage->fHeader->target;
}
inline int32 GetTarget()
{
return fMessage->fHeader->target;
}
bool
UsePreferredTarget()
{
return fMessage->fHeader->target == B_PREFERRED_TOKEN;
}
inline bool UsePreferredTarget()
{
return fMessage->fHeader->target == B_PREFERRED_TOKEN;
}
status_t
Clear()
{
return fMessage->_Clear();
}
inline status_t Clear()
{
return fMessage->_Clear();
}
status_t
InitHeader()
{
return fMessage->_InitHeader();
}
inline status_t InitHeader()
{
return fMessage->_InitHeader();
}
MessageHeader*
GetMessageHeader()
{
return fMessage->fHeader;
}
inline MessageHeader *GetMessageHeader()
{
return fMessage->fHeader;
}
FieldHeader*
GetMessageFields()
{
return fMessage->fFields;
}
inline FieldHeader *GetMessageFields()
{
return fMessage->fFields;
}
uint8*
GetMessageData()
{
return fMessage->fData;
}
inline uint8 *GetMessageData()
{
return fMessage->fData;
}
ssize_t
NativeFlattenedSize() const
{
return fMessage->_NativeFlattenedSize();
}
inline ssize_t NativeFlattenedSize() const
{
return fMessage->_NativeFlattenedSize();
}
status_t
NativeFlatten(char *buffer, ssize_t size) const
{
return fMessage->_NativeFlatten(buffer, size);
}
inline status_t NativeFlatten(char *buffer, ssize_t size) const
{
return fMessage->_NativeFlatten(buffer, size);
}
status_t
NativeFlatten(BDataIO *stream, ssize_t *size) const
{
return fMessage->_NativeFlatten(stream, size);
}
inline status_t NativeFlatten(BDataIO *stream, ssize_t *size) const
{
return fMessage->_NativeFlatten(stream, size);
}
status_t
SendMessage(port_id port, int32 token, bigtime_t timeout,
bool replyRequired, BMessenger &replyTo) const
{
return fMessage->_SendMessage(port, token,
timeout, replyRequired, replyTo);
}
inline status_t SendMessage(port_id port, int32 token, bool preferred,
bigtime_t timeout, bool replyRequired,
BMessenger &replyTo) const
{
return fMessage->_SendMessage(port, token,
preferred, timeout, replyRequired, replyTo);
}
status_t
SendMessage(port_id port, team_id portOwner, int32 token,
BMessage *reply, bigtime_t sendTimeout,
bigtime_t replyTimeout) const
{
return fMessage->_SendMessage(port, portOwner, token,
reply, sendTimeout, replyTimeout);
}
inline status_t SendMessage(port_id port, team_id portOwner,
int32 token, bool preferred, BMessage *reply,
bigtime_t sendTimeout, bigtime_t replyTimeout) const
{
return fMessage->_SendMessage(port, portOwner, token,
preferred, reply, sendTimeout, replyTimeout);
}
// static methods
static
inline status_t SendFlattenedMessage(void *data, int32 size,
port_id port, int32 token, bool preferred,
bigtime_t timeout)
{
return BMessage::_SendFlattenedMessage(data, size,
port, token, preferred, timeout);
}
static status_t
SendFlattenedMessage(void *data, int32 size, port_id port,
int32 token, bigtime_t timeout)
{
return BMessage::_SendFlattenedMessage(data, size,
port, token, timeout);
}
static
inline void StaticInit()
{
BMessage::_StaticInit();
}
static void
StaticInit()
{
BMessage::_StaticInit();
}
static
inline void StaticCleanup()
{
BMessage::_StaticCleanup();
}
static void
StaticCleanup()
{
BMessage::_StaticCleanup();
}
static
inline void StaticCacheCleanup()
{
BMessage::_StaticCacheCleanup();
}
static void
StaticCacheCleanup()
{
BMessage::_StaticCacheCleanup();
}
private:
BMessage *fMessage;
private:
BMessage* fMessage;
};
#endif // _MESSAGE_PRIVATE_H_
+4 -8
View File
@@ -1,3 +1,6 @@
#ifdef USING_MESSAGE4
# include <MessageUtils4.h>
#else
//------------------------------------------------------------------------------
// MessageUtils.h
//
@@ -199,11 +202,4 @@ template<> inline void byte_swap(entry_ref& data)
//------------------------------------------------------------------------------
#endif // MESSAGEUTILS_H
/*
* $Log $
*
* $Id $
*
*/
#endif // USING_MESSAGE4
+1 -1
View File
@@ -79,7 +79,7 @@ public:
throw fError;
}
status_t Status() { return fError; };
status_t Status() { return fError >= B_OK ? B_OK : fError; };
void SetSwap(bool yesNo) { fSwap = yesNo; };
bool IsSwapping() { return fSwap; };
+4 -3
View File
@@ -7,6 +7,7 @@
#include <Messenger.h>
#include <TokenSpace.h>
class BMessenger::Private {
@@ -21,10 +22,10 @@ class BMessenger::Private {
team_id Team()
{ return fMessenger->fTeam; }
bool IsPreferredTarget()
{ return fMessenger->fPreferredTarget; }
{ return fMessenger->fHandlerToken == B_PREFERRED_TOKEN; }
void SetTo(team_id team, port_id port, int32 token, bool preferred)
{ fMessenger->SetTo(team, port, token, preferred); }
void SetTo(team_id team, port_id port, int32 token)
{ fMessenger->_SetTo(team, port, token); }
private:
BMessenger* fMessenger;
+20 -35
View File
@@ -1,64 +1,49 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: InitTerminateLibBe.cpp
// Author(s): Ingo Weinhold ([email protected])
// Description: Global library initialization/termination routines.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold ([email protected])
*/
//! Global library initialization/termination routines.
#include <stdio.h>
#include <ClipboardPrivate.h>
#include <MessagePrivate.h>
#include <RosterPrivate.h>
// debugging
//#define DBG(x) x
#define DBG(x)
#define OUT printf
// initialize_before
extern "C"
void
extern "C" void
initialize_before()
{
DBG(OUT("initialize_before()\n"));
DBG(OUT("initialize_before()\n"));
BMessage::Private::StaticInit();
BRoster::Private::InitBeRoster();
BPrivate::init_clipboard();
DBG(OUT("initialize_before() done\n"));
DBG(OUT("initialize_before() done\n"));
}
// terminate_after
extern "C"
void
extern "C" void
terminate_after()
{
DBG(OUT("terminate_after()\n"));
DBG(OUT("terminate_after()\n"));
BRoster::Private::DeleteBeRoster();
BMessage::Private::StaticCleanup();
BMessage::Private::StaticCacheCleanup();
DBG(OUT("terminate_after() done\n"));
DBG(OUT("terminate_after() done\n"));
}
+1
View File
@@ -48,6 +48,7 @@ MergeObject <libbe>app_kit.o :
MessageUtils.cpp
PropertyInfo.cpp
PortLink.cpp
r5_message.cpp
RegistrarDefs.cpp
RegistrarThread.cpp
RegistrarThreadManager.cpp
+25 -22
View File
@@ -8,6 +8,10 @@
* Ingo Weinhold <[email protected]>
*/
#ifdef USING_MESSAGE4
# include "Message4.cpp"
#else
/** BMessage class creates objects that store data and that
* can be processed in a message loop. BMessage objects
* are also used as data containers by the archiving and
@@ -108,7 +112,7 @@ public:
bool IsSwapped() const { return fSwapped; }
bool HasTarget() const { return (fFlags & MSG_FLAG_INCL_TARGET); }
void SetTarget(int32 token, bool preferred);
void SetTarget(int32 token);
void Dump() const;
@@ -398,7 +402,7 @@ BMessage::Header::CalculateHeaderSize() const
// SetTarget
void
BMessage::Header::SetTarget(int32 token, bool preferred)
BMessage::Header::SetTarget(int32 token)
{
fTargetToken = token;
if (fTargetToken == B_NULL_TOKEN)
@@ -406,7 +410,7 @@ BMessage::Header::SetTarget(int32 token, bool preferred)
else
fFlags |= MSG_FLAG_INCL_TARGET;
fPreferredTarget = preferred;
fPreferredTarget = token == B_PREFERRED_TOKEN;
}
// Dump
@@ -623,7 +627,7 @@ BMessenger BMessage::ReturnAddress() const
{
BMessenger messenger;
BMessenger::Private(messenger).SetTo(fReplyTo.team, fReplyTo.port,
fReplyTo.target, fReplyTo.preferred);
fReplyTo.target);
return messenger;
}
@@ -754,8 +758,7 @@ status_t BMessage::SendReply(BMessage* the_reply, BMessenger reply_to,
BMessenger messenger;
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(fReplyTo.team, fReplyTo.port, fReplyTo.target,
fReplyTo.preferred);
messengerPrivate.SetTo(fReplyTo.team, fReplyTo.port, fReplyTo.target);
if (fReplyRequired)
{
if (fReplyDone)
@@ -824,8 +827,7 @@ status_t BMessage::SendReply(BMessage* the_reply, BMessage* reply_to_reply,
// TODO: test
BMessenger messenger;
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(fReplyTo.team, fReplyTo.port, fReplyTo.target,
fReplyTo.preferred);
messengerPrivate.SetTo(fReplyTo.team, fReplyTo.port, fReplyTo.target);
if (fReplyRequired)
{
if (fReplyDone)
@@ -1873,12 +1875,11 @@ BMessage::calc_hdr_size(uchar flags) const
status_t
BMessage::_send_(port_id port, int32 token, bool preferred,
bigtime_t timeout, bool reply_required,
BMessenger& reply_to) const
BMessage::_send_(port_id port, int32 token, bigtime_t timeout,
bool reply_required, BMessenger& reply_to) const
{
PRINT(("BMessage::_send_(port: %ld, token: %ld, preferred: %d): "
"what: %lx (%.4s)\n", port, token, preferred, what, (char*)&what));
PRINT(("BMessage::_send_(port: %ld, token: %ld): "
"what: %lx (%.4s)\n", port, token, what, (char*)&what));
bool oldPreferred = fPreferred;
int32 oldTarget = fTarget;
@@ -1886,14 +1887,14 @@ BMessage::_send_(port_id port, int32 token, bool preferred,
if (!reply_to.IsValid()) {
BMessenger::Private(reply_to).SetTo(fReplyTo.team,
fReplyTo.port, fReplyTo.target, fReplyTo.preferred);
fReplyTo.port, fReplyTo.target);
if (!reply_to.IsValid())
reply_to = be_app_messenger;
}
BMessage* self = const_cast<BMessage*>(this);
BMessenger::Private replyToPrivate(reply_to);
self->fPreferred = preferred;
self->fPreferred = token == B_PREFERRED_TOKEN;
self->fTarget = token;
self->fReplyRequired = reply_required;
self->fReplyTo.team = replyToPrivate.Team();
@@ -1926,7 +1927,7 @@ BMessage::_send_(port_id port, int32 token, bool preferred,
status_t
BMessage::send_message(port_id port, team_id port_owner, int32 token,
bool preferred, BMessage* reply, bigtime_t send_timeout,
BMessage* reply, bigtime_t send_timeout,
bigtime_t reply_timeout) const
{
const int32 cached_reply_port = sGetCachedReplyPort();
@@ -1961,8 +1962,8 @@ BMessage::send_message(port_id port, team_id port_owner, int32 token,
{
BMessenger messenger;
BMessenger::Private(messenger).SetTo(team, reply_port,
B_PREFERRED_TOKEN, false);
err = _send_(port, token, preferred, send_timeout, true, messenger);
B_PREFERRED_TOKEN);
err = _send_(port, token, send_timeout, true, messenger);
}
if (err)
goto error;
@@ -1993,7 +1994,7 @@ error:
// can be sent.
status_t
BMessage::_SendFlattenedMessage(void *data, int32 size, port_id port,
int32 token, bool preferred, bigtime_t timeout)
int32 token, bigtime_t timeout)
{
if (!data)
return B_BAD_VALUE;
@@ -2004,7 +2005,7 @@ BMessage::_SendFlattenedMessage(void *data, int32 size, port_id port,
if (((KMessage::Header*)data)->magic == KMessage::kMessageHeaderMagic) {
// a KMessage
KMessage::Header *header = (KMessage::Header*)data;
header->targetToken = (preferred ? B_PREFERRED_TOKEN : token);
header->targetToken = token;
} else if (magic == kMessageMagic || magic == kMessageMagicSwapped) {
// get the header
BMemoryIO stream(data, size);
@@ -2033,12 +2034,12 @@ BMessage::_SendFlattenedMessage(void *data, int32 size, port_id port,
// send the message
BMessenger messenger;
return message._send_(port, token, preferred, timeout, false,
return message._send_(port, token, timeout, false,
messenger);
}
// set the target token and replace the header
header.SetTarget(token, preferred);
header.SetTarget(token);
stream.Seek(0LL, SEEK_SET);
error = header.WriteTo(stream);
if (error != B_OK)
@@ -2235,3 +2236,5 @@ min_hdr_size()
return size;
}
#endif // USING_MESSAGE4
+114 -86
View File
@@ -6,6 +6,7 @@
* Michael Lotz <[email protected]>
*/
#include <Message.h>
#include <MessagePrivate.h>
#include <MessageUtils.h>
@@ -343,58 +344,48 @@ BMessage::IsReply() const
}
#define PRINT_SOME_TYPE(type, typeCode) \
case typeCode: { \
sprintf(buffer + strlen(buffer), "size=%2ld, ", size); \
printf("%s", buffer); \
memset(buffer, ' ', strlen(buffer)); \
\
type *item = (type *)(fData + field->offset + field->nameLength); \
for (int32 i = 0; i < field->count; i++, item++) { \
if (i > 0) /* indent */ \
printf(buffer); \
\
printf("data[%ld]: ", i); \
item->PrintToStream(); \
} \
} break
template<typename Type> static void
print_to_stream_type(char* buffer, Type* item, int32 count,
uint32 size)
{
sprintf(buffer + strlen(buffer), "size=%2ld, ", size);
printf("%s", buffer);
memset(buffer, ' ', strlen(buffer));
#define PRINT_INT_TYPE(type, typeCode, format, swap) \
case typeCode: { \
sprintf(buffer + strlen(buffer), "size=%2ld, ", size); \
printf("%s", buffer); \
memset(buffer, ' ', strlen(buffer)); \
\
type *item = (type *)(fData + field->offset + field->nameLength); \
for (int32 i = 0; i < field->count; i++, item++) { \
if (i > 0) /* indent */ \
printf(buffer); \
\
printf("data[%ld]: ", i); \
type value = swap(*item); \
printf(format, *item, *item, &value); \
} \
} break
for (int32 i = 0; i < count; i++, item++) {
if (i > 0) /* indent */
printf(buffer);
printf("data[%ld]: ", i);
item->PrintToStream();
}
}
#define PRINT_FLOAT_TYPE(type, typeCode, format) \
case typeCode: { \
sprintf(buffer + strlen(buffer), "size=%2ld, ", size); \
printf("%s", buffer); \
memset(buffer, ' ', strlen(buffer)); \
\
type *item = (type *)(fData + field->offset + field->nameLength); \
for (int32 i = 0; i < field->count; i++, item++) { \
if (i > 0) /* indent */ \
printf(buffer); \
\
printf("data[%ld]: ", i); \
printf(format, *item); \
} \
} break
template<typename Type> static void
print_type(char* buffer, const char* format, Type* item, int32 count,
uint32 size, type_code typeCode)
{
sprintf(buffer + strlen(buffer), "size=%2ld, ", size);
printf("%s", buffer);
memset(buffer, ' ', strlen(buffer));
for (int32 i = 0; i < count; i++, item++) {
if (i > 0) /* indent */
printf(buffer);
#define REMOVE_BELOW_20(x) (x >= 0x20 ? x : 0x20)
printf("data[%ld]: ", i);
Type value = *item;
if (typeCode == B_BOOL_TYPE) {
printf("%s (%d)\n", value != 0 ? "true" : "false", (int8)value);
} else {
if (typeCode == B_INT8_TYPE && value < ' ')
value = ' ';
swap_data(typeCode, &value, sizeof(Type), B_SWAP_BENDIAN_TO_HOST);
printf(format, *item, *item, &value);
}
}
}
void
@@ -419,10 +410,20 @@ BMessage::PrintToStream() const
size = field->dataSize / field->count;
switch (field->type) {
PRINT_SOME_TYPE(BRect, B_RECT_TYPE);
PRINT_SOME_TYPE(BPoint, B_POINT_TYPE);
case B_RECT_TYPE:
print_to_stream_type<BRect>(buffer,
(BRect *)(fData + field->offset + field->nameLength),
field->count, size);
break;
case B_STRING_TYPE: {
case B_POINT_TYPE:
print_to_stream_type<BPoint>(buffer,
(BPoint *)(fData + field->offset + field->nameLength),
field->count, size);
break;
case B_STRING_TYPE:
{
printf("%s", buffer);
memset(buffer, ' ', strlen(buffer));
@@ -433,20 +434,54 @@ BMessage::PrintToStream() const
ssize_t size = *(ssize_t *)pointer;
pointer += sizeof(ssize_t);
printf("size=%ld, data[%ld]: ", size, i);
printf("size=%2ld, data[%ld]: ", size, i);
printf("\"%s\"\n", (char *)pointer);
pointer += size;
}
} break;
break;
}
PRINT_INT_TYPE(int8, B_INT8_TYPE, "0x%hx (%d \'%.1s\')\n", REMOVE_BELOW_20);
PRINT_INT_TYPE(int16, B_INT16_TYPE, "0x%lx (%d, \'%.2s\')\n", B_BENDIAN_TO_HOST_INT16);
PRINT_INT_TYPE(int32, B_INT32_TYPE, "0x%lx (%ld, \'%.4s\')\n", B_BENDIAN_TO_HOST_INT32);
PRINT_INT_TYPE(int64, B_INT64_TYPE, "0x%Lx (%lld, \'%.4s\')\n", B_BENDIAN_TO_HOST_INT64);
case B_INT8_TYPE:
print_type<int8>(buffer, "0x%hx (%d \'%.1s\')\n",
(int8 *)(fData + field->offset + field->nameLength),
field->count, size, B_INT8_TYPE);
break;
PRINT_FLOAT_TYPE(bool, B_BOOL_TYPE, "%d\n");
PRINT_FLOAT_TYPE(float, B_FLOAT_TYPE, "%.4f\n");
PRINT_FLOAT_TYPE(double, B_DOUBLE_TYPE, "%.8f\n");
case B_INT16_TYPE:
print_type<int16>(buffer, "0x%x (%d \'%.2s\')\n",
(int16 *)(fData + field->offset + field->nameLength),
field->count, size, B_INT16_TYPE);
break;
case B_INT32_TYPE:
print_type<int32>(buffer, "0x%lx (%ld \'%.4s\')\n",
(int32 *)(fData + field->offset + field->nameLength),
field->count, size, B_INT32_TYPE);
break;
case B_INT64_TYPE:
print_type<int64>(buffer, "0x%Lx (%Ld \'%.8s\')\n",
(int64 *)(fData + field->offset + field->nameLength),
field->count, size, B_INT64_TYPE);
break;
case B_BOOL_TYPE:
print_type<int8>(buffer, NULL,
(int8 *)(fData + field->offset + field->nameLength),
field->count, size, B_BOOL_TYPE);
break;
case B_FLOAT_TYPE:
print_type<float>(buffer, "%.4f\n",
(float *)(fData + field->offset + field->nameLength),
field->count, size, B_FLOAT_TYPE);
break;
case B_DOUBLE_TYPE:
print_type<double>(buffer, "%.8f\n",
(double *)(fData + field->offset + field->nameLength),
field->count, size, B_DOUBLE_TYPE);
break;
case B_REF_TYPE: {
printf("%s", buffer);
@@ -462,7 +497,7 @@ BMessage::PrintToStream() const
entry_ref ref;
BPrivate::entry_ref_unflatten(&ref, (char *)pointer, size);
printf("size=%ld, data[%ld]: ", size, i);
printf("size=%2ld, data[%ld]: ", size, i);
printf("device=%ld, directory=%lld, name=\"%s\", ",
ref.device, ref.directory, ref.name);
@@ -470,7 +505,8 @@ BMessage::PrintToStream() const
printf("path=\"%s\"\n", path.Path());
pointer += size;
}
} break;
break;
}
default: {
sprintf(buffer + strlen(buffer), "size=%2ld, \n", size);
@@ -481,11 +517,6 @@ BMessage::PrintToStream() const
}
#undef PRINT_FLOAT_TYPE
#undef PRINT_INT_TYPE
#undef PRINT_SOME_TYPE
status_t
BMessage::Rename(const char *oldEntry, const char *newEntry)
{
@@ -559,8 +590,7 @@ BMessage::ReturnAddress() const
if (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) {
BMessenger messenger;
BMessenger::Private(messenger).SetTo(fHeader->replyTeam,
fHeader->replyPort, fHeader->replyTarget,
fHeader->replyTarget == B_PREFERRED_TOKEN);
fHeader->replyPort, fHeader->replyTarget);
return messenger;
}
@@ -631,7 +661,7 @@ BMessage::SendReply(BMessage *reply, BMessenger replyTo, bigtime_t timeout)
BMessenger messenger;
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(fHeader->replyTeam, fHeader->replyPort,
fHeader->replyTarget, fHeader->replyTarget == B_PREFERRED_TOKEN);
fHeader->replyTarget);
if (fHeader->flags & MESSAGE_FLAG_REPLY_REQUIRED) {
if (fHeader->flags & MESSAGE_FLAG_REPLY_DONE)
@@ -682,7 +712,7 @@ BMessage::SendReply(BMessage *reply, BMessage *replyToReply,
BMessenger messenger;
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(fHeader->replyTeam, fHeader->replyPort,
fHeader->replyTarget, fHeader->replyTarget == B_PREFERRED_TOKEN);
fHeader->replyTarget);
if (fHeader->flags & MESSAGE_FLAG_REPLY_REQUIRED) {
if (fHeader->flags & MESSAGE_FLAG_REPLY_DONE)
@@ -843,7 +873,8 @@ BMessage::Unflatten(const char *flatBuffer)
return BPrivate::R5MessageUnflatten(this, flatBuffer);
if (format == kMessageMagicDano) {
BMemoryIO stream(flatBuffer, BPrivate::dano_message_size(flatBuffer));
BMemoryIO stream(flatBuffer + sizeof(uint32),
BPrivate::dano_message_size(flatBuffer));
return BPrivate::unflatten_dano_message(format, stream, *this);
}
}
@@ -1625,8 +1656,8 @@ BMessage::_StaticGetCachedReplyPort()
status_t
BMessage::_SendMessage(port_id port, int32 token, bool preferred,
bigtime_t timeout, bool replyRequired, BMessenger &replyTo) const
BMessage::_SendMessage(port_id port, int32 token, bigtime_t timeout,
bool replyRequired, BMessenger &replyTo) const
{
DEBUG_FUNCTION_ENTER;
uint32 oldFlags = fHeader->flags;
@@ -1637,8 +1668,7 @@ BMessage::_SendMessage(port_id port, int32 token, bool preferred,
if (!replyTo.IsValid()) {
BMessenger::Private(replyTo).SetTo(fHeader->replyTeam,
fHeader->replyPort, fHeader->replyTarget,
fHeader->replyTarget == B_PREFERRED_TOKEN);
fHeader->replyPort, fHeader->replyTarget);
if (!replyTo.IsValid())
replyTo = be_app_messenger;
@@ -1651,11 +1681,10 @@ BMessage::_SendMessage(port_id port, int32 token, bool preferred,
else
fHeader->flags &= ~MESSAGE_FLAG_REPLY_REQUIRED;
fHeader->target = (preferred ? B_PREFERRED_TOKEN : token);
fHeader->target = token;
fHeader->replyTeam = replyToPrivate.Team();
fHeader->replyPort = replyToPrivate.Port();
fHeader->replyTarget = (replyToPrivate.IsPreferredTarget()
? B_PREFERRED_TOKEN : replyToPrivate.Token());
fHeader->replyTarget = replyToPrivate.Token();
fHeader->flags |= MESSAGE_FLAG_WAS_DELIVERED;
/* ToDo: we can use _kern_writev_port to send the three parts directly:
@@ -1698,8 +1727,7 @@ error:
status_t
BMessage::_SendMessage(port_id port, team_id portOwner, int32 token,
bool preferred, BMessage *reply, bigtime_t sendTimeout,
bigtime_t replyTimeout) const
BMessage *reply, bigtime_t sendTimeout, bigtime_t replyTimeout) const
{
DEBUG_FUNCTION_ENTER;
const int32 cachedReplyPort = _StaticGetCachedReplyPort();
@@ -1735,8 +1763,8 @@ BMessage::_SendMessage(port_id port, team_id portOwner, int32 token,
{
BMessenger messenger;
BMessenger::Private(messenger).SetTo(team, replyPort,
B_PREFERRED_TOKEN, true);
result = _SendMessage(port, token, preferred, sendTimeout, true,
B_PREFERRED_TOKEN);
result = _SendMessage(port, token, sendTimeout, true,
messenger);
}
@@ -1766,7 +1794,7 @@ error:
status_t
BMessage::_SendFlattenedMessage(void *data, int32 size, port_id port,
int32 token, bool preferred, bigtime_t timeout)
int32 token, bigtime_t timeout)
{
DEBUG_FUNCTION_ENTER;
if (!data)
@@ -1776,16 +1804,16 @@ BMessage::_SendFlattenedMessage(void *data, int32 size, port_id port,
if (magic == kMessageMagic4 || magic == kMessageMagic4Swapped) {
MessageHeader *header = (MessageHeader *)data;
header->target = (preferred ? B_PREFERRED_TOKEN : token);
header->target = token;
} else if (magic == kMessageMagicR5) {
uint8 *header = (uint8 *)data;
header += sizeof(uint32) /* magic */ + sizeof(uint32) /* checksum */
+ sizeof(ssize_t) /* flattenedSize */ + sizeof(int32) /* what */
+ sizeof(uint8) /* flags */;
*(int32 *)header = (preferred ? B_PREFERRED_TOKEN : token);
*(int32 *)header = token;
} else if (((KMessage::Header *)data)->magic == KMessage::kMessageHeaderMagic) {
KMessage::Header *header = (KMessage::Header *)data;
header->targetToken = (preferred ? B_PREFERRED_TOKEN : token);
header->targetToken = token;
} else {
return B_NOT_A_MESSAGE;
}
+3 -7
View File
@@ -25,6 +25,8 @@
// BMessage.
//------------------------------------------------------------------------------
#ifndef USING_MESSAGE4
// Standard Includes -----------------------------------------------------------
#include <stdio.h>
@@ -395,10 +397,4 @@ BMessageField* BMessageBody::FindData(const char* name, type_code type,
} // namespace BPrivate
/*
* $Log $
*
* $Id $
*
*/
#endif // USING_MESSAGE4
+2 -7
View File
@@ -1,3 +1,4 @@
#ifndef USING_MESSAGE4
//------------------------------------------------------------------------------
// MessageField.cpp
//
@@ -41,10 +42,4 @@ void BMessageField::PrintToStream(const char* name) const
} // namespace BPrivate
/*
* $Log $
*
* $Id $
*
*/
#endif // USING_MESSAGE4
+5
View File
@@ -6,6 +6,10 @@
* Erik Jaesler (erik@cgsoftware.com)
*/
#ifdef USING_MESSAGE4
# include "MessageUtils4.cpp"
#else
/** Extra messaging utility functions */
#include <string.h>
@@ -128,3 +132,4 @@ TChecksumHelper::CheckSum()
return _checksum_(fBuffer, fBufPtr - fBuffer);
}
#endif // USING_MESSAGE4
+71 -82
View File
@@ -71,18 +71,17 @@ enum {
};
// constructor
/*! \brief Creates an unitialized BMessenger.
*/
BMessenger::BMessenger()
: fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1),
fPreferredTarget(false)
:
fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1)
{
}
// constructor
/*! \brief Creates a BMessenger and initializes it to target the already
running application identified by its signature and/or team ID.
@@ -98,15 +97,15 @@ BMessenger::BMessenger()
the result of the initialization is written.
*/
BMessenger::BMessenger(const char *signature, team_id team, status_t *result)
: fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1),
fPreferredTarget(false)
:
fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1)
{
InitData(signature, team, result);
_InitData(signature, team, result);
}
// constructor
/*! \brief Creates a BMessenger and initializes it to target the local
BHandler and/or BLooper.
@@ -121,12 +120,12 @@ BMessenger::BMessenger(const char *signature, team_id team, status_t *result)
\param result An optional pointer to a pre-allocated status_t into which
the result of the initialization is written.
*/
BMessenger::BMessenger(const BHandler *handler, const BLooper *looper,
status_t *result)
: fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1),
fPreferredTarget(false)
BMessenger::BMessenger(const BHandler* handler, const BLooper* looper,
status_t* _result)
:
fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1)
{
status_t error = (handler || looper ? B_OK : B_BAD_VALUE);
if (error == B_OK) {
@@ -148,31 +147,30 @@ BMessenger::BMessenger(const BHandler *handler, const BLooper *looper,
fPort = looper->fMsgPort;
fHandlerToken = (handler
? _get_object_token_(handler) : B_PREFERRED_TOKEN);
fPreferredTarget = !handler;
fTeam = looper->Team();
} else
error = B_BAD_VALUE;
}
}
if (result)
*result = error;
if (_result)
*_result = error;
}
// copy constructor
/*! \brief Creates a BMessenger and initializes it to have the same target
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),
fPreferredTarget(from.fPreferredTarget)
BMessenger::BMessenger(const BMessenger& from)
:
fPort(from.fPort),
fHandlerToken(from.fHandlerToken),
fTeam(from.fTeam)
{
}
// destructor
/*! \brief Frees all resources associated with this object.
*/
BMessenger::~BMessenger()
@@ -180,9 +178,9 @@ BMessenger::~BMessenger()
}
// Target
// #pragma mark - Target
// IsTargetLocal
/*! \brief Returns whether or not the messenger's target lives within the team
of the caller.
@@ -193,11 +191,11 @@ bool
BMessenger::IsTargetLocal() const
{
thread_info info;
return (get_thread_info(find_thread(NULL), &info) == B_OK
&& fTeam == info.team);
return get_thread_info(find_thread(NULL), &info) == B_OK
&& fTeam == info.team;
}
// Target
/*! \brief Returns the handler and looper targeted by the messenger, if the
target is local.
@@ -212,22 +210,21 @@ BMessenger::IsTargetLocal() const
\return The BHandler targeted by the messenger.
*/
BHandler *
BMessenger::Target(BLooper **looper) const
BMessenger::Target(BLooper** _looper) const
{
BHandler *handler = NULL;
if (IsTargetLocal()) {
if (!fPreferredTarget) {
gDefaultTokens.GetToken(fHandlerToken, B_HANDLER_TOKEN,
(void**)&handler);
}
if (looper)
*looper = BPrivate::gLooperList.LooperForPort(fPort);
} else if (looper)
*looper = NULL;
if (IsTargetLocal() && fHandlerToken > B_NULL_TOKEN) {
gDefaultTokens.GetToken(fHandlerToken, B_HANDLER_TOKEN,
(void**)&handler);
if (_looper)
*_looper = BPrivate::gLooperList.LooperForPort(fPort);
} else if (_looper)
*_looper = NULL;
return handler;
}
// LockTarget
/*! \brief Locks the BLooper targeted by the messenger, if the target is local.
This method is a shorthand for retrieving the targeted looper via
@@ -244,10 +241,10 @@ BMessenger::LockTarget() const
{
BLooper *looper = NULL;
Target(&looper);
return (looper && looper->Lock());
return looper && looper->Lock();
}
// LockTargetWithTimeout
/*! \brief Locks the BLooper targeted by the messenger, if the target is local.
This method is a shorthand for retrieving the targeted looper via
@@ -266,14 +263,15 @@ BMessenger::LockTargetWithTimeout(bigtime_t timeout) const
{
BLooper *looper = NULL;
Target(&looper);
status_t error = (looper ? B_OK : B_BAD_VALUE);
status_t error = looper ? B_OK : B_BAD_VALUE;
if (error == B_OK)
error = looper->LockWithTimeout(timeout);
return error;
}
// Message sending
// #pragma mark - Message sending
// SendMessage
/*! \brief Delivers a BMessage synchronously to the messenger's target.
@@ -358,11 +356,10 @@ BMessenger::SendMessage(BMessage *message, BMessenger replyTo,
return B_BAD_VALUE;
#ifndef USING_MESSAGE4
return message->_send_(fPort, fHandlerToken, fPreferredTarget,
timeout, false, replyTo);
return message->_send_(fPort, fHandlerToken, timeout, false, replyTo);
#else
return BMessage::Private(message).SendMessage(fPort, fHandlerToken,
fPreferredTarget, timeout, false, replyTo);
timeout, false, replyTo);
#endif
}
@@ -418,18 +415,16 @@ BMessenger::SendMessage(uint32 command, BMessage *reply) const
*/
status_t
BMessenger::SendMessage(BMessage *message, BMessage *reply,
bigtime_t deliveryTimeout, bigtime_t replyTimeout) const
bigtime_t deliveryTimeout, bigtime_t replyTimeout) const
{
status_t error = (message && reply ? B_OK : B_BAD_VALUE);
if (error == B_OK) {
#ifndef USING_MESSAGE4
error = message->send_message(fPort, fTeam, fHandlerToken,
fPreferredTarget, reply, deliveryTimeout,
replyTimeout);
reply, deliveryTimeout, replyTimeout);
#else
error = BMessage::Private(message).SendMessage(fPort, fTeam,
fHandlerToken, fPreferredTarget, reply, deliveryTimeout,
replyTimeout);
fHandlerToken, reply, deliveryTimeout, replyTimeout);
#endif
// Map this error for now:
if (error == B_BAD_TEAM_ID)
@@ -439,9 +434,9 @@ BMessenger::SendMessage(BMessage *message, BMessage *reply,
}
// Operators and misc
// #pragma mark - Operators and misc
// =
/*! \brief Makes this BMessenger a copy of the supplied one.
\param from the messenger to be copied.
@@ -454,12 +449,11 @@ BMessenger::operator=(const BMessenger &from)
fPort = from.fPort;
fHandlerToken = from.fHandlerToken;
fTeam = from.fTeam;
fPreferredTarget = from.fPreferredTarget;
}
return *this;
}
// ==
/*! \brief Returns whether this and the supplied messenger have the same
target.
@@ -471,12 +465,11 @@ bool
BMessenger::operator==(const BMessenger &other) const
{
// Note: The fTeam fields are not compared.
return (fPort == other.fPort
&& fHandlerToken == other.fHandlerToken
&& fPreferredTarget == other.fPreferredTarget);
return fPort == other.fPort
&& fHandlerToken == other.fHandlerToken;
}
// IsValid
/*! \brief Returns whether the messenger's target looper does still exist.
It is not checked whether the target handler is also still existing.
@@ -488,10 +481,10 @@ bool
BMessenger::IsValid() const
{
port_info info;
return (fPort >= 0 && get_port_info(fPort, &info) == B_OK);
return fPort >= 0 && get_port_info(fPort, &info) == B_OK;
}
// Team
/*! \brief Returns the ID of the team the messenger's target lives in.
\return The team of the messenger's target.
@@ -503,29 +496,26 @@ BMessenger::Team() const
}
//----- Private or reserved -----------------------------------------
// #pragma mark - Private or reserved
// SetTo
/*! \brief Sets the messenger's team, target looper port and handler token.
If \a preferred is \c true, \a token is ignored.
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.
\param preferred \c true to rather use the looper's preferred handler
instead of the one specified by \a token.
*/
void
BMessenger::SetTo(team_id team, port_id port, int32 token, bool preferred)
BMessenger::_SetTo(team_id team, port_id port, int32 token)
{
fTeam = team;
fPort = port;
fHandlerToken = (preferred ? B_PREFERRED_TOKEN : token);
fPreferredTarget = preferred;
fHandlerToken = token;
}
// InitData
/*! \brief Initializes the BMessenger object's data given the signature and/or
team ID of a target.
@@ -541,7 +531,7 @@ BMessenger::SetTo(team_id team, port_id port, int32 token, bool preferred)
the result of the initialization is written.
*/
void
BMessenger::InitData(const char *signature, team_id team, status_t *result)
BMessenger::_InitData(const char* signature, team_id team, status_t* _result)
{
status_t error = B_OK;
// get an app_info
@@ -576,14 +566,14 @@ BMessenger::InitData(const char *signature, team_id team, status_t *result)
fTeam = team;
fPort = info.port;
fHandlerToken = B_PREFERRED_TOKEN;
fPreferredTarget = true;
}
// return the error
if (result)
*result = error;
if (_result)
*_result = error;
}
// <
/*! \brief Returns whether the first one of two BMessengers is less than the
second one.
@@ -599,7 +589,6 @@ operator<(const BMessenger &_a, const BMessenger &_b)
{
BMessenger::Private a(const_cast<BMessenger&>(_a));
BMessenger::Private b(const_cast<BMessenger&>(_b));
// significance:
// 1. fPort
@@ -614,7 +603,7 @@ operator<(const BMessenger &_a, const BMessenger &_b)
&& b.IsPreferredTarget()));
}
// !=
/*! \brief Returns whether two BMessengers have not the same target.
\param a The first messenger.
+74 -91
View File
@@ -1,31 +1,17 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Roster.cpp
// Author: Ingo Weinhold ([email protected])
// Description: BRoster class lets you launch apps and keeps
// track of apps that are running.
// Global be_roster represents the default BRoster.
// app_info structure provides info for a running app.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold (bonefish@users.sf.net)
*/
/*! BRoster class lets you launch apps and keeps track of apps
that are running.
Global be_roster represents the default BRoster.
app_info structure provides info for a running app.
*/
#include <new>
#include <stdio.h>
#include <stdlib.h>
@@ -80,23 +66,27 @@ static int32 compare_version_infos(const version_info &info1,
static int32 compare_app_versions(const entry_ref *app1,
const entry_ref *app2);
/*-------------------------------------------------------------*/
/* --------- app_info Struct and Values ------------------------ */
// constructor
const BRoster *be_roster;
// #pragma mark - app_info
/*! \brief Creates an uninitialized app_info.
*/
app_info::app_info()
: thread(-1),
team(-1),
port(-1),
flags(B_REG_DEFAULT_APP_FLAGS),
ref()
:
thread(-1),
team(-1),
port(-1),
flags(B_REG_DEFAULT_APP_FLAGS),
ref()
{
signature[0] = '\0';
}
// destructor
/*! \brief Does nothing.
*/
app_info::~app_info()
@@ -104,37 +94,39 @@ app_info::~app_info()
}
/*-------------------------------------------------------------*/
/* --------- BRoster::ArgVector class------------------------- */
// #pragma mark - BRoster::ArgVector
class BRoster::ArgVector {
public:
ArgVector();
~ArgVector();
status_t Init(int argc, const char *const *args, const entry_ref *appRef,
const entry_ref *docRef);
void Unset();
inline int Count() const { return fArgc; }
inline const char *const *Args() const { return fArgs; }
private:
int fArgc;
const char **fArgs;
BPath fAppPath;
BPath fDocPath;
public:
ArgVector();
~ArgVector();
status_t Init(int argc, const char *const *args, const entry_ref *appRef,
const entry_ref *docRef);
void Unset();
inline int Count() const { return fArgc; }
inline const char *const *Args() const { return fArgs; }
private:
int fArgc;
const char **fArgs;
BPath fAppPath;
BPath fDocPath;
};
// constructor
/*! \brief Creates an uninitialized ArgVector.
*/
BRoster::ArgVector::ArgVector()
: fArgc(0),
fArgs(NULL),
fAppPath(),
fDocPath()
:
fArgc(0),
fArgs(NULL),
fAppPath(),
fDocPath()
{
}
// destructor
/*! \brief Frees all resources associated with the ArgVector.
*/
BRoster::ArgVector::~ArgVector()
@@ -142,7 +134,7 @@ BRoster::ArgVector::~ArgVector()
Unset();
}
// Init
/*! \brief Initilizes the object according to the supplied parameters.
If the initialization succeeds, the methods Count() and Args() grant
@@ -174,7 +166,7 @@ BRoster::ArgVector::~ArgVector()
*/
status_t
BRoster::ArgVector::Init(int argc, const char *const *args,
const entry_ref *appRef, const entry_ref *docRef)
const entry_ref *appRef, const entry_ref *docRef)
{
// unset old values
Unset();
@@ -226,30 +218,26 @@ BRoster::ArgVector::Unset()
}
/*-------------------------------------------------------------*/
/* --------- BRoster class----------------------------------- */
// #pragma mark - BRoster
// constructor
/*! \brief Creates and initializes a BRoster.
*/
BRoster::BRoster()
: fMess(),
fMimeMess()
:
fMess(),
fMimeMess()
{
InitMessengers();
}
// destructor
/*! \brief Does nothing.
*/
BRoster::~BRoster()
{
}
/* Querying for apps */
// #pragma mark - Querying for apps
// IsRunning
/*! \brief Returns whether or not an application with the supplied signature
is currently running.
\param mimeSig The app signature
@@ -605,7 +593,7 @@ BRoster::FindApp(entry_ref *ref, entry_ref *app) const
}
/* Launching, activating, and broadcasting to apps */
// #pragma mark - Launching, activating, and broadcasting to apps
// Broadcast
/*! \brief Sends a message to all running applications.
@@ -1098,7 +1086,7 @@ BRoster::Launch(const entry_ref *ref, int argc, const char * const *args,
}
/* Recent document and app support */
// #pragma mark - Recent document and app support
// GetRecentDocuments
void
@@ -1324,9 +1312,9 @@ BRoster::AddToRecentFolders(const entry_ref *folder, const char *appSig) const
}
/*----- Private or reserved ------------------------------*/
// #pragma mark - Private or reserved
// ShutDown
/*! \brief Shuts down the system.
When \c synchronous is \c true and the method succeeds, it doesn't return.
@@ -2222,7 +2210,7 @@ BRoster::send_to_running(team_id team, int argc, const char *const *args,
error = GetRunningAppInfo(team, &info);
if (error == B_OK) {
BMessenger messenger;
BMessenger::Private(messenger).SetTo(team, info.port, 0, true);
BMessenger::Private(messenger).SetTo(team, info.port, B_PREFERRED_TOKEN);
// send messages from the list
if (messageList) {
for (int32 i = 0;
@@ -2252,22 +2240,23 @@ BRoster::send_to_running(team_id team, int argc, const char *const *args,
return error;
}
// InitMessengers
void
BRoster::InitMessengers()
{
DBG(OUT("BRoster::InitMessengers()\n"));
DBG(OUT("BRoster::InitMessengers()\n"));
// find the registrar port
port_id rosterPort = find_port(BPrivate::get_roster_port_name());
port_info info;
if (rosterPort >= 0 && get_port_info(rosterPort, &info) == B_OK) {
DBG(OUT(" found roster port\n"));
DBG(OUT(" found roster port\n"));
// ask for the MIME messenger
BMessenger::Private(fMess).SetTo(info.team, rosterPort, 0, true);
BMessenger::Private(fMess).SetTo(info.team, rosterPort, B_PREFERRED_TOKEN);
BMessage reply;
status_t error = fMess.SendMessage(B_REG_GET_MIME_MESSENGER, &reply);
if (error == B_OK && reply.what == B_REG_SUCCESS) {
DBG(OUT(" got reply from roster\n"));
DBG(OUT(" got reply from roster\n"));
reply.FindMessenger("messenger", &fMimeMess);
} else {
DBG(OUT(" no (useful) reply from roster: error: %lx: %s\n", error,
@@ -2276,10 +2265,10 @@ DBG(OUT(" got reply from roster\n"));
DBG(reply.PrintToStream());
}
}
DBG(OUT("BRoster::InitMessengers() done\n"));
DBG(OUT("BRoster::InitMessengers() done\n"));
}
// AddToRecentApps
/*! \brief Sends a request to the roster to add the application with the
given signature to the front of the recent apps list.
*/
@@ -2402,16 +2391,10 @@ BRoster::SaveRecentLists(const char *filename) const
// return error;
}
/*-----------------------------------------------------*/
/*----- Global be_roster ------------------------------*/
const BRoster *be_roster;
// #pragma mark - Helper functions
/*-----------------------------------------------------*/
/*----- Helper functions ------------------------------*/
// find_message_app_info
/*! \brief Extracts an app_info from a BMessage.
The function searchs for a field "app_info" typed B_REG_APP_INFO_TYPE
+5 -11
View File
@@ -92,22 +92,16 @@ BTokenSpace::GetToken(int32 token, int16 type, void** _object,
{
BAutolock locker(const_cast<BTokenSpace&>(*this));
if (token < 1) {
*_object = NULL;
if (token < 1)
return B_ENTRY_NOT_FOUND;
}
TokenMap::const_iterator iterator = fTokenMap.find(token);
if (iterator == fTokenMap.end() || iterator->second.type != type) {
*_object = NULL;
return B_ERROR;
}
if (iterator == fTokenMap.end() || iterator->second.type != type)
return B_ENTRY_NOT_FOUND;
if (callback && !callback(iterator->second.type, iterator->second.object)) {
*_object = NULL;
return B_ERROR;
}
if (callback && !callback(iterator->second.type, iterator->second.object))
return B_ENTRY_NOT_FOUND;
*_object = iterator->second.object;
return B_OK;
+4
View File
@@ -1,3 +1,5 @@
#ifdef USING_MESSAGE4
#include <DataIO.h>
#include <MessagePrivate.h>
#include <MessageUtils.h>
@@ -394,3 +396,5 @@ R5MessageUnflatten(BMessage *message, BDataIO *stream)
}
} // namespace BPrivate
#endif // USING_MESSAGE4
+210 -42
View File
@@ -925,7 +925,7 @@ BWindow::DispatchMessage(BMessage *msg, BHandler *target)
msg->FindPoint("where", i, &frameLeftTop);
msg->FindFloat("width", i, &width);
msg->FindFloat("height", i, &height);
if ((view = findView(fTopView, token))) {
if ((view = _FindView(token)) != NULL) {
// update the views offset in parent
if (view->LeftTop() != frameLeftTop) {
view->fParentOffset = frameLeftTop;
@@ -1330,16 +1330,16 @@ BWindow::UpdateIfNeeded()
BView *
BWindow::FindView(const char *viewName) const
{
// TODO: What about locking?!?
return findView(fTopView, viewName);
BAutolock _(const_cast<BWindow*>(this));
return fTopView->FindView(viewName);
}
BView *
BWindow::FindView(BPoint point) const
{
// TODO: What about locking?!?
return findView(fTopView, point);
BAutolock _(const_cast<BWindow*>(this));
return _FindView(fTopView, point);
}
@@ -2134,7 +2134,7 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
port_id sendPort;
int32 code;
if (fLink->FlushWithReply(code) == B_OK
&& code == SERVER_TRUE
&& code == B_OK
&& fLink->Read<port_id>(&sendPort) == B_OK) {
fLink->SetSenderPort(sendPort);
@@ -2194,7 +2194,118 @@ BWindow::task_looper()
{
STRACE(("info: BWindow::task_looper() started.\n"));
BLooper::task_looper();
// Check that looper is locked (should be)
AssertLocked();
// Unlock the looper
Unlock();
if (IsLocked())
debugger("window must not be locked!");
// loop: As long as we are not terminating.
while (!fTerminating) {
// TODO: timeout determination algo
// Read from message port (how do we determine what the timeout is?)
BMessage* msg = MessageFromPort();
// Did we get a message?
if (msg) {
// Add to queue
fQueue->AddMessage(msg);
} else
continue;
// Get message count from port
int32 msgCount = port_count(fMsgPort);
for (int32 i = 0; i < msgCount; ++i) {
// Read 'count' messages from port (so we will not block)
// We use zero as our timeout since we know there is stuff there
msg = MessageFromPort(0);
// Add messages to queue
if (msg)
fQueue->AddMessage(msg);
}
// loop: As long as there are messages in the queue and the port is
// empty... and we are not terminating, of course.
bool dispatchNextMessage = true;
while (!fTerminating && dispatchNextMessage) {
// Get next message from queue (assign to fLastMessage)
fLastMessage = fQueue->NextMessage();
// Lock the looper
Lock();
if (!fLastMessage) {
// No more messages: Unlock the looper and terminate the
// dispatch loop.
dispatchNextMessage = false;
} else {
// Get the target handler
#ifdef USING_MESSAGE4
// Use the private BMessage accessor to determine if we are
// using the preferred handler, or if a target has been
// specified
BHandler *handler = NULL;
BMessage::Private messagePrivate(fLastMessage);
bool usePreferred = messagePrivate.UsePreferredTarget();
#else
// Use BMessage friend functions to determine if we are using the
// preferred handler, or if a target has been specified
BHandler* handler = NULL;
bool usePreferred = _use_preferred_target_(fLastMessage);
#endif
if (usePreferred) {
handler = PreferredHandler();
} else {
#ifndef USING_MESSAGE4
gDefaultTokens.GetToken(_get_message_target_(fLastMessage),
B_HANDLER_TOKEN, (void **)&handler);
#else
gDefaultTokens.GetToken(messagePrivate.GetTarget(),
B_HANDLER_TOKEN, (void **)&handler);
#endif
}
//printf("handler = %p, usePreferred = %s\n", handler, usePreferred ? "yes" : "no");
if (!usePreferred || _DistributeMessage(fLastMessage)) {
// if a target was given, and we should not use the preferred
// handler, we can just use that one
if (handler == NULL || usePreferred)
handler = _DetermineTarget(fLastMessage, handler);
if (handler == NULL)
handler = this;
// Is this a scripting message? (BMessage::HasSpecifiers())
if (fLastMessage->HasSpecifiers()) {
int32 index = 0;
// Make sure the current specifier is kosher
if (fLastMessage->GetCurrentSpecifier(&index) == B_OK)
handler = resolve_specifier(handler, fLastMessage);
}
if (handler) {
// Do filtering and dispatch message
handler = top_level_filter(fLastMessage, handler);
if (handler && handler->Looper() == this)
DispatchMessage(fLastMessage, handler);
}
}
}
Unlock();
// Delete the current message (fLastMessage)
delete fLastMessage;
fLastMessage = NULL;
// Are any messages on the port?
if (port_count(fMsgPort) > 0) {
// Do outer loop
dispatchNextMessage = false;
}
}
}
}
@@ -2349,6 +2460,85 @@ BWindow::handleActivation(bool active)
fTopView->_Activate(active);
}
/*!
\brief Determines the target of a message received.
*/
BHandler *
BWindow::_DetermineTarget(BMessage *message, BHandler *target)
{
// TODO: this is mostly guessed; check for correctness.
switch (message->what) {
case B_KEY_DOWN:
case B_KEY_UP:
case B_UNMAPPED_KEY_DOWN:
case B_UNMAPPED_KEY_UP:
case B_MODIFIERS_CHANGED:
// these messages will be dispatched by the focus view later
return CurrentFocus();
case B_MOUSE_DOWN:
case B_MOUSE_UP:
case B_MOUSE_MOVED:
case B_MOUSE_WHEEL_CHANGED:
// TODO: the app_server should tell us which view is the target
break;
case B_PULSE:
case B_QUIT_REQUESTED:
// TODO: test wether R5 will let BView dispatch these messages
return this;
case B_VIEW_RESIZED:
case B_VIEW_MOVED:
{
int32 token;
if (message->FindInt32("_token", &token) != B_OK)
token = B_NULL_TOKEN;
BView *view = _FindView(token);
if (view)
return view;
break;
}
default:
break;
}
return target;
}
/*!
\brief Distributes the message to its intended targets. This is done for
all messages that should go to the preferred handler.
Returns \c false in case the message needs no more processing.
*/
bool
BWindow::_DistributeMessage(BMessage* message)
{
message->PrintToStream();
int32 index = 0, count = 0;
int32 token;
for (; message->FindInt32("_token_", index, &token) == B_OK; index++) {
printf(" token = %ld\n", token);
BView* target = _FindView(token);
if (target == NULL)
continue;
printf("distribute message %lx to: %s\n", message->what, target->Name());
BMessenger messenger(target);
if (messenger.SendMessage(message) == B_OK)
count++;
}
return count == 0;
}
bool
BWindow::_HandleKeyDown(char key, uint32 modifiers)
{
@@ -2478,45 +2668,23 @@ BWindow::_FindShortcut(uint32 key, uint32 modifiers)
BView *
BWindow::findView(BView *view, int32 token)
BWindow::_FindView(int32 token)
{
if (_get_object_token_(view) == token)
BHandler* handler;
if (gDefaultTokens.GetToken(token, B_HANDLER_TOKEN, (void**)&handler) != B_OK)
return NULL;
// the view must belong to us in order to be found by this method
BView* view = dynamic_cast<BView*>(handler);
if (view != NULL && view->Window() == this)
return view;
BView *child = view->fFirstChild;
while (child != NULL) {
if ((view = findView(child, token)) != NULL)
return view;
child = child->fNextSibling;
}
return NULL;
}
BView *
BWindow::findView(BView *view, const char *name) const
{
if (!strcmp(name, view->Name()))
return view;
BView *child = view->fFirstChild;
while (child != NULL) {
if ((view = findView(child, name)) != NULL)
return view;
child = child->fNextSibling;
}
return NULL;
}
BView *
BWindow::findView(BView *view, BPoint point) const
BWindow::_FindView(BView *view, BPoint point) const
{
if (view->Bounds().Contains(point) && !view->fFirstChild)
return view;
@@ -2524,7 +2692,7 @@ BWindow::findView(BView *view, BPoint point) const
BView *child = view->fFirstChild;
while (child != NULL) {
if ((view = findView(child, point)) != NULL)
if ((view = _FindView(child, point)) != NULL)
return view;
child = child->fNextSibling;
@@ -2577,7 +2745,7 @@ BWindow::_FindPreviousNavigable(BView *focus, uint32 flags)
// Search the tree for views that accept focus
while (true) {
BView *view;
if ((view = findLastChild(prevFocus)) != NULL)
if ((view = _LastViewChild(prevFocus)) != NULL)
prevFocus = view;
else if (prevFocus->fPreviousSibling)
prevFocus = prevFocus->fPreviousSibling;
@@ -2586,7 +2754,7 @@ BWindow::_FindPreviousNavigable(BView *focus, uint32 flags)
prevFocus = prevFocus->fParent;
if (prevFocus == fTopView)
prevFocus = findLastChild(prevFocus);
prevFocus = _LastViewChild(prevFocus);
else
prevFocus = prevFocus->fPreviousSibling;
}
@@ -2603,7 +2771,7 @@ BWindow::_FindPreviousNavigable(BView *focus, uint32 flags)
BView *
BWindow::findLastChild(BView *parent)
BWindow::_LastViewChild(BView *parent)
{
BView *last = parent->fFirstChild;
if (last == NULL)
-1
View File
@@ -31,7 +31,6 @@
#include "ServerProtocol.h"
#include "ServerWindow.h"
#include "SystemPalette.h"
#include "Utils.h"
#include "WinBorder.h"
#include <Accelerant.h>
+2 -2
View File
@@ -455,7 +455,7 @@ bool RootLayer::SetActiveWorkspace(int32 index)
wks |= (0x00000001 << fActiveWksIndex);
changedMsg.AddInt32("new", wks);
draggedWinBorder->QuietlySetWorkspaces(wks);
draggedWinBorder->Window()->SendMessageToClient(&changedMsg, B_NULL_TOKEN, false);
draggedWinBorder->Window()->SendMessageToClient(&changedMsg, B_NULL_TOKEN);
}
RevealNewWMState(oldWMState);
@@ -678,7 +678,7 @@ RootLayer::RevealNewWMState(Workspace::State &oldWMState)
oldWMState.Active->Activated(false);
if (fWMState.Active) {
fWMState.Active->Activated(true);
fDesktop->EventDispatcher().SetFocus(&fWMState.Active->Window()->Messenger());
fDesktop->EventDispatcher().SetFocus(&fWMState.Active->Window()->FocusMessenger());
} else
fDesktop->EventDispatcher().SetFocus(NULL);
}
+6 -5
View File
@@ -56,7 +56,6 @@
#include "ServerTokenSpace.h"
#include "ServerWindow.h"
#include "SystemPalette.h"
#include "Utils.h"
#include "WinBorder.h"
//#define DEBUG_SERVERAPP
@@ -122,8 +121,8 @@ ServerApp::ServerApp(Desktop* desktop, port_id clientReplyPort,
return;
}
BMessenger::Private(fClientMessenger).SetTo(fClientTeam,
clientLooperPort, clientToken, false);
BMessenger::Private(fHandlerMessenger).SetTo(fClientTeam,
clientLooperPort, clientToken);
ServerCursor *defaultCursor =
fDesktop->GetCursorManager().GetCursor(B_CURSOR_DEFAULT);
@@ -278,7 +277,9 @@ ServerApp::Quit(sem_id shutdownSemaphore)
void
ServerApp::SendMessageToClient(BMessage *msg) const
{
fClientMessenger.SendMessage(msg);
status_t status = fHandlerMessenger.SendMessage(msg, (BHandler*)NULL, 100000);
if (status != B_OK)
printf("app %s send to client failed: %s\n", Signature(), strerror(status));
}
@@ -404,7 +405,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
switch (code) {
case AS_REGISTER_INPUT_SERVER:
{
EventStream* stream = new (nothrow) InputServerStream(fClientMessenger);
EventStream* stream = new (nothrow) InputServerStream(fHandlerMessenger);
if (stream != NULL
&& (!stream->IsValid() || !gInputManager->AddStream(stream))) {
delete stream;
+1 -1
View File
@@ -86,7 +86,7 @@ class ServerApp : public MessageLooper {
port_id fClientReplyPort;
// our BApplication's event port
BMessenger fClientMessenger;
BMessenger fHandlerMessenger;
port_id fClientLooperPort;
int32 fClientToken;
// To send a BMessage to the client (port + token)
+16 -13
View File
@@ -35,6 +35,8 @@
#include <WindowInfo.h>
#include <WindowPrivate.h>
#include <MessagePrivate.h>
#include "AppServer.h"
#include "BGet++.h"
#include "DebugInfoManager.h"
@@ -42,7 +44,6 @@
#include "DrawingEngine.h"
#include "HWInterface.h"
#include "Layer.h"
#include "MessagePrivate.h"
#include "RAMLinkMsgReader.h"
#include "RenderingBuffer.h"
#include "RootLayer.h"
@@ -50,7 +51,6 @@
#include "ServerBitmap.h"
#include "ServerPicture.h"
#include "ServerProtocol.h"
#include "Utils.h"
#include "WinBorder.h"
#include "Workspace.h"
#include "WorkspacesLayer.h"
@@ -150,8 +150,10 @@ ServerWindow::ServerWindow(const char *title, ServerApp *app,
SetTitle(title);
fServerToken = BPrivate::gDefaultTokens.NewToken(B_SERVER_TOKEN, this);
BMessenger::Private(fClientMessenger).SetTo(fClientTeam,
looperPort, clientToken, false);
BMessenger::Private(fFocusMessenger).SetTo(fClientTeam,
looperPort, B_PREFERRED_TOKEN);
BMessenger::Private(fHandlerMessenger).SetTo(fClientTeam,
looperPort, clientToken);
}
@@ -670,7 +672,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
}
if (fCurrentLayer->EventMask() != 0) {
fDesktop->EventDispatcher().RemoveListener(Messenger(),
fDesktop->EventDispatcher().RemoveListener(FocusMessenger(),
fCurrentLayer->ViewToken());
}
@@ -716,14 +718,15 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint32>(&eventMask);
if (link.Read<uint32>(&options) == B_OK) {
printf("got %s: eventMask = %ld, options = %ld\n", fCurrentLayer->Name(), eventMask, options);
fCurrentLayer->QuietlySetEventMask(eventMask);
fCurrentLayer->QuietlySetEventOptions(options);
if (eventMask != 0 || options != 0) {
fDesktop->EventDispatcher().AddListener(Messenger(),
fDesktop->EventDispatcher().AddListener(FocusMessenger(),
fCurrentLayer->ViewToken(), eventMask, options);
} else {
fDesktop->EventDispatcher().RemoveListener(Messenger(),
fDesktop->EventDispatcher().RemoveListener(FocusMessenger(),
fCurrentLayer->ViewToken());
}
}
@@ -738,10 +741,10 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint32>(&eventMask);
if (link.Read<uint32>(&options) == B_OK) {
if (eventMask != 0 || options != 0) {
fDesktop->EventDispatcher().AddTemporaryListener(Messenger(),
fDesktop->EventDispatcher().AddTemporaryListener(FocusMessenger(),
fCurrentLayer->ViewToken(), eventMask, options);
} else {
fDesktop->EventDispatcher().RemoveTemporaryListener(Messenger(),
fDesktop->EventDispatcher().RemoveTemporaryListener(FocusMessenger(),
fCurrentLayer->ViewToken());
}
}
@@ -2111,7 +2114,7 @@ ServerWindow::_MessageLooper()
status_t
ServerWindow::SendMessageToClient(const BMessage* msg, int32 target, bool usePreferred) const
ServerWindow::SendMessageToClient(const BMessage* msg, int32 target) const
{
#ifndef USING_MESSAGE4
ssize_t size = msg->FlattenedSize();
@@ -2120,7 +2123,7 @@ ServerWindow::SendMessageToClient(const BMessage* msg, int32 target, bool usePre
if ((ret = msg->Flatten(buffer, size)) == B_OK) {
ret = BMessage::Private::SendFlattenedMessage(buffer, size,
fClientLooperPort, target, usePreferred, 100000);
fClientLooperPort, target, 100000);
if (ret < B_OK)
fprintf(stderr, "ServerWindow::SendMessageToClient(): %s\n", strerror(ret));
} else
@@ -2131,8 +2134,8 @@ ServerWindow::SendMessageToClient(const BMessage* msg, int32 target, bool usePre
#else
BMessenger reply;
BMessage::Private messagePrivate((BMessage *)msg);
return messagePrivate.SendMessage(fClientLooperPort, target, usePreferred,
100000, false, reply);
return messagePrivate.SendMessage(fClientLooperPort, target, 100000,
false, reply);
#endif
}
+6 -4
View File
@@ -72,10 +72,11 @@ public:
const color_space cspace);
// util methods.
const BMessenger& Messenger() const { return fClientMessenger; }
const BMessenger& FocusMessenger() const { return fFocusMessenger; }
const BMessenger& HandlerMessenger() const { return fHandlerMessenger; }
status_t SendMessageToClient(const BMessage* msg,
int32 target = B_NULL_TOKEN,
bool usePreferred = false) const;
int32 target = B_NULL_TOKEN) const;
virtual WinBorder* MakeWinBorder(BRect frame,
const char* name,
@@ -140,7 +141,8 @@ private:
port_id fMessagePort;
port_id fClientReplyPort;
port_id fClientLooperPort;
BMessenger fClientMessenger;
BMessenger fFocusMessenger;
BMessenger fHandlerMessenger;
BMessage fClientViewsWithInvalidCoords;
+2 -2
View File
@@ -610,7 +610,7 @@ MessageDeliverer::DeliverMessage(BMessage *message, MessagingTargetSet &targets,
// It will be set when sending the message anyway, but if it is not set
// before flattening, the header will not contain room for it, and it
// will not possible to send the message flattened later.
BMessage::Private(message).SetTarget(0, false);
BMessage::Private(message).SetTarget(B_NULL_TOKEN);
// flatten the message
BMallocIO mallocIO;
@@ -747,7 +747,7 @@ status_t
MessageDeliverer::_SendMessage(Message *message, port_id portID, int32 token)
{
status_t error = BMessage::Private::SendFlattenedMessage(message->Data(),
message->DataSize(), portID, token, (token < 0), 0);
message->DataSize(), portID, token, 0);
//PRINT(("MessageDeliverer::_SendMessage(%p, port: %ld, token: %ld): %lx\n",
//message, portID, token, error));
return error;
+6 -5
View File
@@ -1,11 +1,12 @@
/*
* Copyright 2001-2005, Ingo Weinhold, bonefish@users.sf.net.
* Distributed under the terms of the MIT License.
*
* TRoster is the incarnation of The Roster. It manages the running
* applications.
*/
/*! TRoster is the incarnation of The Roster. It manages the running
applications.
*/
#include <new>
#include <Application.h>
@@ -1444,7 +1445,7 @@ TRoster::_AppActivated(RosterAppInfo *info)
// send B_APP_ACTIVATED to the app
BMessenger messenger;
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(info->team, info->port, 0, true);
messengerPrivate.SetTo(info->team, info->port, B_NULL_TOKEN);
BMessage message(B_APP_ACTIVATED);
message.AddBool("active", true);
// not sure, if it makes sense to use the MessageDeliverer here
@@ -1472,7 +1473,7 @@ TRoster::_AppDeactivated(RosterAppInfo *info)
// send B_APP_ACTIVATED to the app
BMessenger messenger;
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(info->team, info->port, 0, true);
messengerPrivate.SetTo(info->team, info->port, B_NULL_TOKEN);
BMessage message(B_APP_ACTIVATED);
message.AddBool("active", false);
// not sure, if it makes sense to use the MessageDeliverer here