Updated the messaging related build platform code with the current Haiku

version.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34259 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-11-25 21:34:59 +00:00
parent e6604f4804
commit 7870a9ffc7
10 changed files with 772 additions and 506 deletions
+41 -8
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2007, Haiku Inc. All Rights Reserved.
* Copyright 2005-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -106,9 +106,13 @@ class BMessage {
status_t AddString(const char *name, const char *aString);
status_t AddString(const char *name, const BString &aString);
status_t AddInt8(const char *name, int8 value);
status_t AddUInt8(const char *name, uint8 value);
status_t AddInt16(const char *name, int16 value);
status_t AddUInt16(const char *name, uint16 value);
status_t AddInt32(const char *name, int32 value);
status_t AddUInt32(const char *name, uint32 value);
status_t AddInt64(const char *name, int64 value);
status_t AddUInt64(const char *name, uint64 value);
status_t AddBool(const char *name, bool aBoolean);
status_t AddFloat(const char *name, float aFloat);
status_t AddDouble(const char *name, double aDouble);
@@ -138,12 +142,20 @@ class BMessage {
status_t FindString(const char *name, int32 index, BString *string) const;
status_t FindInt8(const char *name, int8 *value) const;
status_t FindInt8(const char *name, int32 index, int8 *value) const;
status_t FindUInt8(const char *name, uint8 *value) const;
status_t FindUInt8(const char *name, int32 index, uint8 *value) const;
status_t FindInt16(const char *name, int16 *value) const;
status_t FindInt16(const char *name, int32 index, int16 *value) const;
status_t FindUInt16(const char *name, uint16 *value) const;
status_t FindUInt16(const char *name, int32 index, uint16 *value) const;
status_t FindInt32(const char *name, int32 *value) const;
status_t FindInt32(const char *name, int32 index, int32 *value) const;
status_t FindUInt32(const char *name, uint32 *value) const;
status_t FindUInt32(const char *name, int32 index, uint32 *value) const;
status_t FindInt64(const char *name, int64 *value) const;
status_t FindInt64(const char *name, int32 index, int64 *value) const;
status_t FindUInt64(const char *name, uint64 *value) const;
status_t FindUInt64(const char *name, int32 index, uint64 *value) const;
status_t FindBool(const char *name, bool *value) const;
status_t FindBool(const char *name, int32 index, bool *value) const;
status_t FindFloat(const char *name, float *value) const;
@@ -176,12 +188,20 @@ class BMessage {
status_t ReplaceString(const char *name, int32 index, const BString &aString);
status_t ReplaceInt8(const char *name, int8 value);
status_t ReplaceInt8(const char *name, int32 index, int8 value);
status_t ReplaceUInt8(const char *name, uint8 value);
status_t ReplaceUInt8(const char *name, int32 index, uint8 value);
status_t ReplaceInt16(const char *name, int16 value);
status_t ReplaceInt16(const char *name, int32 index, int16 value);
status_t ReplaceUInt16(const char *name, uint16 value);
status_t ReplaceUInt16(const char *name, int32 index, uint16 value);
status_t ReplaceInt32(const char *name, int32 value);
status_t ReplaceInt32(const char *name, int32 index, int32 value);
status_t ReplaceUInt32(const char *name, uint32 value);
status_t ReplaceUInt32(const char *name, int32 index, uint32 value);
status_t ReplaceInt64(const char *name, int64 value);
status_t ReplaceInt64(const char *name, int32 index, int64 value);
status_t ReplaceUInt64(const char *name, uint64 value);
status_t ReplaceUInt64(const char *name, int32 index, uint64 value);
status_t ReplaceBool(const char *name, bool aBoolean);
status_t ReplaceBool(const char *name, int32 index, bool aBoolean);
status_t ReplaceFloat(const char *name, float aFloat);
@@ -203,6 +223,10 @@ class BMessage {
status_t ReplaceData(const char *name, type_code type, int32 index,
const void *data, ssize_t numBytes);
// Comparing data - Haiku experimental API
bool HasSameData(const BMessage &other,
bool ignoreFieldOrder = true, bool deep = false) const;
void *operator new(size_t size);
void *operator new(size_t, void *pointer);
void operator delete(void *pointer, size_t size);
@@ -212,9 +236,13 @@ class BMessage {
bool HasPoint(const char *, int32 n = 0) const;
bool HasString(const char *, int32 n = 0) const;
bool HasInt8(const char *, int32 n = 0) const;
bool HasUInt8(const char *, int32 n = 0) const;
bool HasInt16(const char *, int32 n = 0) const;
bool HasUInt16(const char *, int32 n = 0) const;
bool HasInt32(const char *, int32 n = 0) const;
bool HasUInt32(const char *, int32 n = 0) const;
bool HasInt64(const char *, int32 n = 0) const;
bool HasUInt64(const char *, int32 n = 0) const;
bool HasBool(const char *, int32 n = 0) const;
bool HasFloat(const char *, int32 n = 0) const;
bool HasDouble(const char *, int32 n = 0) const;
@@ -244,11 +272,13 @@ class BMessage {
friend class Private;
friend class BMessageQueue;
status_t _InitCommon();
status_t _InitCommon(bool initHeader);
status_t _InitHeader();
status_t _Clear();
status_t _ResizeData(int32 offset, int32 change);
status_t _ValidateMessage();
status_t _ResizeData(uint32 offset, int32 change);
uint32 _HashName(const char* name) const;
status_t _FindField(const char* name, type_code type,
@@ -257,26 +287,29 @@ class BMessage {
bool isFixedSize, field_header** _result);
status_t _RemoveField(field_header* field);
ssize_t _NativeFlattenedSize() const;
status_t _NativeFlatten(char *buffer, ssize_t size) const;
status_t _NativeFlatten(BDataIO *stream, ssize_t *size = NULL) const;
void _PrintToStream(const char* indent) const;
private:
message_header* fHeader;
field_header* fFields;
uint8* fData;
area_id fClonedArea;
uint32 fFieldsAvailable;
size_t fDataAvailable;
mutable BMessage* fOriginal;
BMessage* fQueueLink;
// fQueueLink is used by BMessageQueue to build a linked list
uint32 fReserved[9];
// deprecated
BMessage(BMessage *message);
static void _StaticCacheCleanup();
virtual void _ReservedMessage1();
virtual void _ReservedMessage2();
virtual void _ReservedMessage3();
static BBlockCache* sMsgCache;
};
+15 -49
View File
@@ -1,54 +1,24 @@
//------------------------------------------------------------------------------
// 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-2007, 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:
public:
BMessenger();
BMessenger(const BMessenger &from);
~BMessenger();
@@ -67,22 +37,18 @@ public:
private:
friend class Private;
void SetTo(team_id team, port_id port, int32 token, bool preferred);
void _SetTo(team_id team, port_id port, int32 token);
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);
_IMPEXP_BE bool operator!=(const BMessenger &a, const BMessenger &b);
bool operator<(const BMessenger &a, const BMessenger &b);
bool operator!=(const BMessenger &a, const BMessenger &b);
#endif // _MESSENGER_H
+38 -52
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2007, Haiku Inc. All rights reserved.
* Copyright 2005-2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -9,13 +9,14 @@
#define _MESSAGE_PRIVATE_H_
#include <Message.h>
#include <Messenger.h>
#include <MessengerPrivate.h>
#include <TokenSpace.h>
#define MESSAGE_BODY_HASH_TABLE_SIZE 10
#define MESSAGE_BODY_HASH_TABLE_SIZE 5
#define MAX_DATA_PREALLOCATION B_PAGE_SIZE * 10
#define MAX_FIELD_PREALLOCATION 50
#define MAX_ITEM_PREALLOCATION B_PAGE_SIZE
static const int32 kPortMessageCode = 'pjpp';
@@ -28,8 +29,8 @@ enum {
MESSAGE_FLAG_IS_REPLY = 0x0008,
MESSAGE_FLAG_WAS_DELIVERED = 0x0010,
MESSAGE_FLAG_HAS_SPECIFIERS = 0x0020,
MESSAGE_FLAG_WAS_DROPPED = 0x0080,
MESSAGE_FLAG_PASS_BY_AREA = 0x0100
MESSAGE_FLAG_WAS_DROPPED = 0x0040,
MESSAGE_FLAG_PASS_BY_AREA = 0x0080
};
@@ -40,15 +41,14 @@ enum {
struct BMessage::field_header {
uint32 flags;
uint16 flags;
uint16 name_length;
type_code type;
int32 name_length;
int32 count;
ssize_t data_size;
ssize_t allocated;
int32 offset;
uint32 count;
uint32 data_size;
uint32 offset;
int32 next_field;
};
} _PACKED;
struct BMessage::message_header {
@@ -56,17 +56,9 @@ struct BMessage::message_header {
uint32 what;
uint32 flags;
ssize_t fields_size;
ssize_t data_size;
ssize_t fields_available;
ssize_t data_available;
uint32 fields_checksum;
uint32 data_checksum;
int32 target;
int32 current_specifier;
area_id shared_area;
area_id message_area;
// reply info
port_id reply_port;
@@ -74,8 +66,9 @@ struct BMessage::message_header {
team_id reply_team;
// body info
int32 field_count;
int32 hash_table_size;
uint32 data_size;
uint32 field_count;
uint32 hash_table_size;
int32 hash_table[MESSAGE_BODY_HASH_TABLE_SIZE];
/* The hash table does contain indexes into the field list and
@@ -84,18 +77,20 @@ struct BMessage::message_header {
The hash table must be reevaluated when we remove a field
though.
*/
};
} _PACKED;
class BMessage::Private {
public:
Private(BMessage *msg)
: fMessage(msg)
:
fMessage(msg)
{
}
Private(BMessage &msg)
: fMessage(&msg)
:
fMessage(&msg)
{
}
@@ -105,6 +100,23 @@ class BMessage::Private {
fMessage->fHeader->target = token;
}
void
SetReply(BMessenger messenger)
{
BMessenger::Private messengerPrivate(messenger);
fMessage->fHeader->reply_port = messengerPrivate.Port();
fMessage->fHeader->reply_target = messengerPrivate.Token();
fMessage->fHeader->reply_team = messengerPrivate.Team();
}
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;
}
int32
GetTarget()
{
@@ -156,32 +168,6 @@ class BMessage::Private {
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);
}
// static methods
static void
StaticCacheCleanup()
{
BMessage::_StaticCacheCleanup();
}
private:
BMessage* fMessage;
};
+16 -10
View File
@@ -1,25 +1,31 @@
/*
* Copyright 2003-2005, Haiku.
* Distributed under the terms of the MIT License.
*/
#ifndef MESSENGER_PRIVATE_H
#define MESSENGER_PRIVATE_H
#include <Messenger.h>
class BMessenger::Private
{
#include <Messenger.h>
#include <TokenSpace.h>
class BMessenger::Private {
public:
Private(BMessenger* msnger) : fMessenger(msnger) {;}
Private(BMessenger& msnger) : fMessenger(&msnger) {;}
Private(BMessenger* messenger) : fMessenger(messenger) {}
Private(BMessenger& messenger) : fMessenger(&messenger) {}
port_id Port()
{ return fMessenger->fPort; }
int32 Token()
int32 Token()
{ return fMessenger->fHandlerToken; }
team_id Team()
{ return fMessenger->fTeam; }
bool IsPreferredTarget()
{ return fMessenger->fPreferredTarget; }
bool IsPreferredTarget()
{ 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;
-17
View File
@@ -1,17 +0,0 @@
SubDir HAIKU_TOP src build libbe app ;
UseHeaders [ FDirName $(HAIKU_TOP) headers build private app ] : true ;
UseHeaders [ FDirName $(HAIKU_TOP) headers build private shared ] : true ;
USES_BE_API on <libbe_build>app_kit.o = true ;
BuildPlatformMergeObjectPIC <libbe_build>app_kit.o :
Application.cpp
AppMisc.cpp
Message.cpp
MessageAdapter.cpp
Messenger.cpp
MessageUtils.cpp
TypeConstants.cpp
;
File diff suppressed because it is too large Load Diff
+45 -43
View File
@@ -6,12 +6,12 @@
* Axel Dörfler, axeld@pinc-software.de
* Michael Lotz <mmlr@mlotz.ch>
*/
#include <stdlib.h>
#include <MessageAdapter.h>
#include <MessagePrivate.h>
#include <MessageUtils.h>
#include <stdlib.h>
namespace BPrivate {
@@ -41,7 +41,7 @@ enum {
struct r5_message_header {
uint32 magic;
uint32 checksum;
ssize_t flattened_size;
int32 flattened_size;
int32 what;
uint8 flags;
} _PACKED;
@@ -49,7 +49,7 @@ struct r5_message_header {
struct dano_section_header {
uint32 code;
ssize_t size;
int32 size;
uint8 data[0];
} _PACKED;
@@ -69,7 +69,7 @@ typedef struct offset_table_s {
struct dano_single_item {
type_code type;
ssize_t item_size;
int32 item_size;
uint8 name_length;
char name[0];
} _PACKED;
@@ -77,7 +77,7 @@ struct dano_single_item {
struct dano_fixed_size_array {
type_code type;
ssize_t size_per_item;
int32 size_per_item;
uint8 name_length;
char name[0];
} _PACKED;
@@ -250,7 +250,7 @@ MessageAdapter::_R5FlattenedSize(const BMessage *from)
uint8 *data = messagePrivate.GetMessageData();
BMessage::field_header *field = messagePrivate.GetMessageFields();
for (int32 i = 0; i < header->field_count; i++, field++) {
for (uint32 i = 0; i < header->field_count; i++, field++) {
// flags and type
flattenedSize += 1 + sizeof(type_code);
@@ -277,7 +277,7 @@ MessageAdapter::_R5FlattenedSize(const BMessage *from)
else {
uint8 *source = data + field->offset + field->name_length;
for (int32 i = 0; i < field->count; i++) {
for (uint32 i = 0; i < field->count; i++) {
ssize_t itemSize = *(ssize_t *)source + sizeof(ssize_t);
flattenedSize += pad_to_8(itemSize);
source += itemSize;
@@ -344,11 +344,11 @@ MessageAdapter::_FlattenR5Message(uint32 format, const BMessage *from,
r5header->flags = flags;
// store the header size - used for the checksum later
ssize_t headerSize = (addr_t)pointer - (addr_t)buffer;
ssize_t headerSize = (uint32)pointer - (uint32)buffer;
// collect and add the data
BMessage::field_header *field = messagePrivate.GetMessageFields();
for (int32 i = 0; i < header->field_count; i++, field++) {
for (uint32 i = 0; i < header->field_count; i++, field++) {
flags = R5_FIELD_FLAG_VALID;
if (field->count == 1)
@@ -400,10 +400,12 @@ MessageAdapter::_FlattenR5Message(uint32 format, const BMessage *from,
pointer += field->data_size;
} else {
uint8 *previous = pointer;
for (int32 i = 0; i < field->count; i++) {
for (uint32 i = 0; i < field->count; i++) {
ssize_t itemSize = *(ssize_t *)source + sizeof(ssize_t);
memcpy(pointer, source, itemSize);
pointer += pad_to_8(itemSize);
ssize_t paddedSize = pad_to_8(itemSize);
memset(pointer + itemSize, 0, paddedSize - itemSize);
pointer += paddedSize;
source += itemSize;
}
@@ -420,7 +422,7 @@ MessageAdapter::_FlattenR5Message(uint32 format, const BMessage *from,
pointer++;
// calculate the flattened size from the pointers
r5header->flattened_size = (addr_t)pointer - (addr_t)buffer;
r5header->flattened_size = (uint32)pointer - (uint32)buffer;
r5header->checksum = CalculateChecksum((uint8 *)(buffer + 8),
headerSize - 8);
@@ -451,13 +453,13 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
header->what = into->what = r5header.what;
if (r5header.flags & R5_MESSAGE_FLAG_INCLUDE_TARGET)
reader(header->target);
reader(&header->target, sizeof(header->target));
if (r5header.flags & R5_MESSAGE_FLAG_INCLUDE_REPLY) {
// reply info
reader(header->reply_port);
reader(header->reply_target);
reader(header->reply_team);
reader(&header->reply_port, sizeof(header->reply_port));
reader(&header->reply_target, sizeof(header->reply_target));
reader(&header->reply_team, sizeof(header->reply_team));
// big flags
uint8 bigFlag;
@@ -530,25 +532,13 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
if (fixedSize)
itemSize = dataSize / itemCount;
if (fixedSize) {
if (format == MESSAGE_FORMAT_R5) {
for (int32 i = 0; i < itemCount; i++) {
// ToDo: what if we are swapped? need B_INT32_TYPEs and the
// like be swapped here?
result = into->AddData(nameBuffer, type, pointer, itemSize,
fixedSize, itemCount);
if (result < B_OK) {
free(buffer);
return result;
if (!fixedSize) {
itemSize = *(ssize_t *)pointer;
pointer += sizeof(ssize_t);
}
pointer += itemSize;
}
} else if (format == MESSAGE_FORMAT_R5_SWAPPED) {
for (int32 i = 0; i < itemCount; i++) {
itemSize = __swap_int32(*(ssize_t *)pointer);
pointer += sizeof(ssize_t);
result = into->AddData(nameBuffer, type, pointer, itemSize,
fixedSize, itemCount);
@@ -557,13 +547,19 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
return result;
}
pointer += pad_to_8(itemSize + sizeof(ssize_t)) - sizeof(ssize_t);
if (fixedSize)
pointer += itemSize;
else
pointer += pad_to_8(itemSize + sizeof(ssize_t)) - sizeof(ssize_t);
}
} else {
for (int32 i = 0; i < itemCount; i++) {
itemSize = *(ssize_t *)pointer;
pointer += sizeof(ssize_t);
if (!fixedSize) {
itemSize = __swap_int32(*(ssize_t *)pointer);
pointer += sizeof(ssize_t);
}
swap_data(type, pointer, itemSize, B_SWAP_ALWAYS);
result = into->AddData(nameBuffer, type, pointer, itemSize,
fixedSize, itemCount);
@@ -572,7 +568,10 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
return result;
}
pointer += pad_to_8(itemSize + sizeof(ssize_t)) - sizeof(ssize_t);
if (fixedSize)
pointer += itemSize;
else
pointer += pad_to_8(itemSize + sizeof(ssize_t)) - sizeof(ssize_t);
}
}
@@ -618,15 +617,18 @@ MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
ssize_t fieldSize = sectionHeader.size - sizeof(dano_section_header);
uint8 *fieldBuffer = NULL;
if (fieldSize > 0) {
if (fieldSize <= 0) {
// there may be no data. we shouldn't fail because of that
fieldBuffer = (uint8 *)malloc(fieldSize);
if (fieldBuffer == NULL)
throw (status_t)B_NO_MEMORY;
reader(fieldBuffer, fieldSize);
offset += sectionHeader.size;
continue;
}
fieldBuffer = (uint8 *)malloc(fieldSize);
if (fieldBuffer == NULL)
throw (status_t)B_NO_MEMORY;
reader(fieldBuffer, fieldSize);
switch (sectionHeader.code) {
case SECTION_OFFSET_TABLE:
case SECTION_TARGET_INFORMATION:
+9 -2
View File
@@ -44,14 +44,21 @@ CalculateChecksum(const uint8 *buffer, int32 size)
status_t
entry_ref_flatten(char *buffer, size_t *size, const entry_ref *ref)
{
if (*size < sizeof(ref->device) + sizeof(ref->directory))
return B_BUFFER_OVERFLOW;
memcpy((void *)buffer, (const void *)&ref->device, sizeof(ref->device));
buffer += sizeof(ref->device);
memcpy((void *)buffer, (const void *)&ref->directory, sizeof(ref->directory));
buffer += sizeof (ref->directory);
*size -= sizeof(ref->device) + sizeof(ref->directory);
size_t nameLength = 0;
if (ref->name) {
nameLength = strlen(ref->name) + 1;
if (*size < nameLength)
return B_BUFFER_OVERFLOW;
memcpy((void *)buffer, (const void *)ref->name, nameLength);
}
@@ -73,8 +80,8 @@ entry_ref_unflatten(entry_ref *ref, const char *buffer, size_t size)
memcpy((void *)&ref->directory, (const void *)buffer, sizeof(ref->directory));
buffer += sizeof(ref->directory);
if (ref->device != ~(dev_t)0 && size > sizeof(ref->device)
+ sizeof(ref->directory)) {
if (ref->device != -1 && size > sizeof(ref->device)
+ sizeof(ref->directory)) {
ref->set_name(buffer);
if (ref->name == NULL) {
*ref = entry_ref();
+40 -46
View File
@@ -1,46 +1,41 @@
/*
* Copyright 2001-2008, Haiku Inc. All rights reserved.
* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold, bonefish@users.sf.net
* Ingo Weinhold (bonefish@users.sf.net)
*/
/*!
\class BMessenger
Delivers messages to local or remote targets.
*/
#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>
#include <Application.h>
#include <Handler.h>
#include <Looper.h>
#include <Message.h>
#include <OS.h>
#include <Roster.h>
#include <AppMisc.h>
#include <LooperList.h>
#include <MessageUtils.h>
#include <MessengerPrivate.h>
#include <ObjectLocker.h>
#include <TokenSpace.h>
// debugging
//#define DBG(x) x
#define DBG(x)
#define OUT printf
using BPrivate::gDefaultTokens;
using BPrivate::gLooperList;
using BPrivate::BLooperList;
using BPrivate::BObjectLocker;
// #pragma mark -
enum {
NOT_IMPLEMENTED = B_ERROR,
};
/*! \brief Creates an unitialized BMessenger.
@@ -49,8 +44,7 @@ BMessenger::BMessenger()
:
fPort(-1),
fHandlerToken(B_NULL_TOKEN),
fTeam(-1),
fPreferredTarget(false)
fTeam(-1)
{
}
@@ -60,12 +54,11 @@ BMessenger::BMessenger()
\param from The messenger to be copied.
*/
BMessenger::BMessenger(const BMessenger &from)
BMessenger::BMessenger(const BMessenger& from)
:
fPort(from.fPort),
fHandlerToken(from.fHandlerToken),
fTeam(from.fTeam),
fPreferredTarget(from.fPreferredTarget)
fTeam(from.fTeam)
{
}
@@ -77,6 +70,9 @@ BMessenger::~BMessenger()
}
// #pragma mark - Operators and misc
/*! \brief Makes this BMessenger a copy of the supplied one.
\param from the messenger to be copied.
@@ -89,7 +85,6 @@ BMessenger::operator=(const BMessenger &from)
fPort = from.fPort;
fHandlerToken = from.fHandlerToken;
fTeam = from.fTeam;
fPreferredTarget = from.fPreferredTarget;
}
return *this;
}
@@ -107,8 +102,7 @@ BMessenger::operator==(const BMessenger &other) const
{
// Note: The fTeam fields are not compared.
return fPort == other.fPort
&& fHandlerToken == other.fHandlerToken
&& fPreferredTarget == other.fPreferredTarget;
&& fHandlerToken == other.fHandlerToken;
}
@@ -123,7 +117,6 @@ bool
BMessenger::IsValid() const
{
return fPort >= 0;
// for the build version, we don't actually check the port
}
@@ -138,23 +131,23 @@ BMessenger::Team() const
}
// #pragma mark - Private or reserved
/*! \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;
}
@@ -179,12 +172,12 @@ operator<(const BMessenger &_a, const BMessenger &_b)
// 2. fHandlerToken
// 3. fPreferredTarget
// fTeam is insignificant
return a.Port() < b.Port()
|| (a.Port() == b.Port()
&& (a.Token() < b.Token()
|| (a.Token() == b.Token()
&& !a.IsPreferredTarget()
&& b.IsPreferredTarget())));
return (a.Port() < b.Port()
|| (a.Port() == b.Port()
&& (a.Token() < b.Token()
|| (a.Token() == b.Token()
&& !a.IsPreferredTarget()
&& b.IsPreferredTarget()))));
}
@@ -200,3 +193,4 @@ operator!=(const BMessenger &a, const BMessenger &b)
{
return !(a == b);
}
+2 -3
View File
@@ -1,4 +1,4 @@
/*
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
@@ -114,8 +114,7 @@ swap_data(type_code type, void *_data, size_t length, swap_action action)
messengerPrivate.SetTo(
__swap_int32(messengerPrivate.Team()),
__swap_int32(messengerPrivate.Port()),
__swap_int32(messengerPrivate.Token()),
messengerPrivate.IsPreferredTarget());
__swap_int32(messengerPrivate.Token()));
messenger++;
}
break;