2005-11-20 19:24:23 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Haiku Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Michael Lotz <mmlr@mlotz.ch>
|
|
|
|
*/
|
2005-11-13 14:31:07 +03:00
|
|
|
#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
|
|
|
|
|
|
|
|
|
2006-02-23 12:02:03 +03:00
|
|
|
static const int32 kPortMessageCode = 'pjpp';
|
2006-02-18 15:29:05 +03:00
|
|
|
|
|
|
|
|
2005-11-13 14:31:07 +03:00
|
|
|
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,
|
2006-02-23 12:02:03 +03:00
|
|
|
MESSAGE_FLAG_WAS_DROPPED = 0x0080,
|
|
|
|
MESSAGE_FLAG_PASS_BY_AREA = 0x0100
|
2005-11-13 14:31:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FIELD_FLAG_VALID = 0x0001,
|
|
|
|
FIELD_FLAG_FIXED_SIZE = 0x0002,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-21 01:24:03 +03:00
|
|
|
struct BMessage::field_header {
|
2005-11-13 14:31:07 +03:00
|
|
|
uint32 flags;
|
|
|
|
type_code type;
|
2005-11-21 01:24:03 +03:00
|
|
|
int32 name_length;
|
2005-11-13 14:31:07 +03:00
|
|
|
int32 count;
|
2005-11-21 01:24:03 +03:00
|
|
|
ssize_t data_size;
|
2005-11-13 14:31:07 +03:00
|
|
|
ssize_t allocated;
|
|
|
|
int32 offset;
|
2005-11-21 01:24:03 +03:00
|
|
|
int32 next_field;
|
|
|
|
};
|
2005-11-13 14:31:07 +03:00
|
|
|
|
|
|
|
|
2005-11-21 01:24:03 +03:00
|
|
|
struct BMessage::message_header {
|
2005-11-13 14:31:07 +03:00
|
|
|
uint32 format;
|
|
|
|
uint32 what;
|
|
|
|
uint32 flags;
|
|
|
|
|
2005-11-21 01:24:03 +03:00
|
|
|
ssize_t fields_size;
|
|
|
|
ssize_t data_size;
|
|
|
|
ssize_t fields_available;
|
|
|
|
ssize_t data_available;
|
2005-11-13 14:31:07 +03:00
|
|
|
|
2006-02-21 01:05:39 +03:00
|
|
|
uint32 fields_checksum;
|
|
|
|
uint32 data_checksum;
|
|
|
|
|
2005-11-13 14:31:07 +03:00
|
|
|
int32 target;
|
2005-11-21 01:24:03 +03:00
|
|
|
int32 current_specifier;
|
2006-02-18 15:29:05 +03:00
|
|
|
area_id shared_area;
|
2005-11-13 14:31:07 +03:00
|
|
|
|
|
|
|
// reply info
|
2005-11-21 01:24:03 +03:00
|
|
|
port_id reply_port;
|
|
|
|
int32 reply_target;
|
|
|
|
team_id reply_team;
|
2005-11-13 14:31:07 +03:00
|
|
|
|
|
|
|
// body info
|
2005-11-21 01:24:03 +03:00
|
|
|
int32 field_count;
|
|
|
|
int32 hash_table_size;
|
|
|
|
int32 hash_table[MESSAGE_BODY_HASH_TABLE_SIZE];
|
2005-11-13 14:31:07 +03:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2005-11-21 01:24:03 +03:00
|
|
|
};
|
2005-11-13 14:31:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
class BMessage::Private {
|
2005-11-20 19:24:23 +03:00
|
|
|
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);
|
2005-11-21 01:24:03 +03:00
|
|
|
fMessage->fHeader->reply_port = messengerPrivate.Port();
|
|
|
|
fMessage->fHeader->reply_target = messengerPrivate.Token();
|
|
|
|
fMessage->fHeader->reply_team = messengerPrivate.Team();
|
2005-11-20 19:24:23 +03:00
|
|
|
}
|
|
|
|
|
2006-03-12 16:21:08 +03:00
|
|
|
void
|
|
|
|
SetReply(team_id team, port_id port, int32 target)
|
|
|
|
{
|
|
|
|
fMessage->fHeader->reply_port = port;
|
|
|
|
fMessage->fHeader->reply_target = target;
|
|
|
|
fMessage->fHeader->reply_team = team;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:23 +03:00
|
|
|
int32
|
|
|
|
GetTarget()
|
|
|
|
{
|
|
|
|
return fMessage->fHeader->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UsePreferredTarget()
|
|
|
|
{
|
|
|
|
return fMessage->fHeader->target == B_PREFERRED_TOKEN;
|
|
|
|
}
|
|
|
|
|
2006-04-11 01:22:05 +04:00
|
|
|
void
|
|
|
|
SetWasDropped(bool wasDropped)
|
|
|
|
{
|
|
|
|
if (wasDropped)
|
|
|
|
fMessage->fHeader->flags |= MESSAGE_FLAG_WAS_DROPPED;
|
|
|
|
else
|
|
|
|
fMessage->fHeader->flags &= ~MESSAGE_FLAG_WAS_DROPPED;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:23 +03:00
|
|
|
status_t
|
|
|
|
Clear()
|
|
|
|
{
|
|
|
|
return fMessage->_Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
InitHeader()
|
|
|
|
{
|
|
|
|
return fMessage->_InitHeader();
|
|
|
|
}
|
|
|
|
|
2005-11-21 01:24:03 +03:00
|
|
|
BMessage::message_header*
|
2005-11-20 19:24:23 +03:00
|
|
|
GetMessageHeader()
|
|
|
|
{
|
|
|
|
return fMessage->fHeader;
|
|
|
|
}
|
|
|
|
|
2005-11-21 01:24:03 +03:00
|
|
|
BMessage::field_header*
|
2005-11-20 19:24:23 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-02-18 15:29:05 +03:00
|
|
|
status_t
|
|
|
|
FlattenToArea(message_header **header) const
|
|
|
|
{
|
|
|
|
return fMessage->_FlattenToArea(header);
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:23 +03:00
|
|
|
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;
|
2005-11-13 14:31:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _MESSAGE_PRIVATE_H_
|