haiku/headers/private/app/MessagePrivate4.h
Axel Dörfler 4ceb1e519c * 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
2005-11-20 16:24:23 +00:00

221 lines
3.9 KiB
C++

/*
* Copyright 2005, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Lotz <mmlr@mlotz.ch>
*/
#ifndef _MESSAGE_PRIVATE_H_
#define _MESSAGE_PRIVATE_H_
#include <Message.h>
#include <Messenger.h>
#include <MessengerPrivate.h>
#include <TokenSpace.h>
#define MESSAGE_BODY_HASH_TABLE_SIZE 10
#define MAX_DATA_PREALLOCATION B_PAGE_SIZE * 10
#define MAX_FIELD_PREALLOCATION 50
#define MAX_ITEM_PREALLOCATION B_PAGE_SIZE
enum {
MESSAGE_FLAG_VALID = 0x0001,
MESSAGE_FLAG_REPLY_REQUIRED = 0x0002,
MESSAGE_FLAG_REPLY_DONE = 0x0004,
MESSAGE_FLAG_IS_REPLY = 0x0008,
MESSAGE_FLAG_WAS_DELIVERED = 0x0010,
MESSAGE_FLAG_HAS_SPECIFIERS = 0x0020,
MESSAGE_FLAG_READ_ONLY = 0x0040
};
enum {
FIELD_FLAG_VALID = 0x0001,
FIELD_FLAG_FIXED_SIZE = 0x0002,
};
typedef struct field_header_s {
uint32 flags;
type_code type;
int32 nameLength;
int32 count;
ssize_t dataSize;
ssize_t allocated;
int32 offset;
int32 nextField;
} FieldHeader;
typedef struct message_header_s {
uint32 format;
uint32 what;
uint32 flags;
ssize_t fieldsSize;
ssize_t dataSize;
ssize_t fieldsAvailable;
ssize_t dataAvailable;
int32 target;
int32 currentSpecifier;
// reply info
port_id replyPort;
int32 replyTarget;
team_id replyTeam;
// body info
int32 fieldCount;
int32 hashTableSize;
int32 hashTable[MESSAGE_BODY_HASH_TABLE_SIZE];
/* The hash table does contain indexes into the field list and
not direct offsets to the fields. This has the advantage
of not needing to update offsets in two locations.
The hash table must be reevaluated when we remove a field
though.
*/
} MessageHeader;
class BMessage::Private {
public:
Private(BMessage *msg)
: fMessage(msg)
{
}
Private(BMessage &msg)
: fMessage(&msg)
{
}
void
SetTarget(int32 token)
{
fMessage->fHeader->target = token;
}
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;
}
bool
UsePreferredTarget()
{
return fMessage->fHeader->target == B_PREFERRED_TOKEN;
}
status_t
Clear()
{
return fMessage->_Clear();
}
status_t
InitHeader()
{
return fMessage->_InitHeader();
}
MessageHeader*
GetMessageHeader()
{
return fMessage->fHeader;
}
FieldHeader*
GetMessageFields()
{
return fMessage->fFields;
}
uint8*
GetMessageData()
{
return fMessage->fData;
}
ssize_t
NativeFlattenedSize() const
{
return fMessage->_NativeFlattenedSize();
}
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);
}
status_t
SendMessage(port_id port, int32 token, bigtime_t timeout,
bool replyRequired, BMessenger &replyTo) const
{
return fMessage->_SendMessage(port, token,
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);
}
// static methods
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 void
StaticInit()
{
BMessage::_StaticInit();
}
static void
StaticCleanup()
{
BMessage::_StaticCleanup();
}
static void
StaticCacheCleanup()
{
BMessage::_StaticCacheCleanup();
}
private:
BMessage* fMessage;
};
#endif // _MESSAGE_PRIVATE_H_