MessageAdapter: cleanup, no functional change.
This commit is contained in:
parent
0efd0f54d3
commit
4d50aa327c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007, Haiku Inc. All rights reserved.
|
||||
* Copyright 2007-2015, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -8,9 +8,11 @@
|
||||
#ifndef _MESSAGE_ADAPTER_H_
|
||||
#define _MESSAGE_ADAPTER_H_
|
||||
|
||||
|
||||
#include <Message.h>
|
||||
#include <util/KMessage.h>
|
||||
|
||||
|
||||
// message formats
|
||||
#define MESSAGE_FORMAT_R5 'FOB1'
|
||||
#define MESSAGE_FORMAT_R5_SWAPPED '1BOF'
|
||||
@ -19,36 +21,43 @@
|
||||
#define MESSAGE_FORMAT_HAIKU '1FMH'
|
||||
#define MESSAGE_FORMAT_HAIKU_SWAPPED 'HMF1'
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class MessageAdapter {
|
||||
public:
|
||||
static ssize_t FlattenedSize(uint32 format, const BMessage *from);
|
||||
static ssize_t FlattenedSize(uint32 format,
|
||||
const BMessage* from);
|
||||
|
||||
static status_t Flatten(uint32 format, const BMessage *from,
|
||||
char *buffer, ssize_t *size);
|
||||
static status_t Flatten(uint32 format, const BMessage *from,
|
||||
BDataIO *stream, ssize_t *size);
|
||||
static status_t Flatten(uint32 format, const BMessage* from,
|
||||
char* buffer, ssize_t* size);
|
||||
static status_t Flatten(uint32 format, const BMessage* from,
|
||||
BDataIO* stream, ssize_t* size);
|
||||
|
||||
static status_t Unflatten(uint32 format, BMessage *into,
|
||||
const char *buffer);
|
||||
static status_t Unflatten(uint32 format, BMessage *into,
|
||||
BDataIO *stream);
|
||||
static status_t Unflatten(uint32 format, BMessage* into,
|
||||
const char* buffer);
|
||||
static status_t Unflatten(uint32 format, BMessage* into,
|
||||
BDataIO* stream);
|
||||
|
||||
private:
|
||||
static status_t _ConvertKMessage(const KMessage *from, BMessage *to);
|
||||
static status_t _ConvertFromKMessage(const KMessage* from,
|
||||
BMessage* to);
|
||||
|
||||
static ssize_t _R5FlattenedSize(const BMessage *from);
|
||||
static ssize_t _R5FlattenedSize(const BMessage* from);
|
||||
|
||||
static status_t _FlattenR5Message(uint32 format, const BMessage *from,
|
||||
char *buffer, ssize_t *size);
|
||||
static status_t _FlattenR5Message(uint32 format,
|
||||
const BMessage* from, char* buffer,
|
||||
ssize_t* size);
|
||||
|
||||
static status_t _UnflattenR5Message(uint32 format, BMessage *into,
|
||||
BDataIO *stream);
|
||||
static status_t _UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
BDataIO *stream);
|
||||
static status_t _UnflattenR5Message(uint32 format,
|
||||
BMessage* into, BDataIO* stream);
|
||||
static status_t _UnflattenDanoMessage(uint32 format,
|
||||
BMessage* into, BDataIO* stream);
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _MESSAGE_ADAPTER_H_
|
||||
|
@ -98,7 +98,7 @@ pad_to_8(int32 value)
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
/*static*/ ssize_t
|
||||
MessageAdapter::FlattenedSize(uint32 format, const BMessage *from)
|
||||
{
|
||||
switch (format) {
|
||||
@ -111,7 +111,7 @@ MessageAdapter::FlattenedSize(uint32 format, const BMessage *from)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::Flatten(uint32 format, const BMessage *from, char *buffer,
|
||||
ssize_t *size)
|
||||
{
|
||||
@ -125,7 +125,7 @@ MessageAdapter::Flatten(uint32 format, const BMessage *from, char *buffer,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::Flatten(uint32 format, const BMessage *from, BDataIO *stream,
|
||||
ssize_t *size)
|
||||
{
|
||||
@ -163,7 +163,7 @@ MessageAdapter::Flatten(uint32 format, const BMessage *from, BDataIO *stream,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::Unflatten(uint32 format, BMessage *into, const char *buffer)
|
||||
{
|
||||
if (format == KMessage::kMessageHeaderMagic) {
|
||||
@ -173,7 +173,7 @@ MessageAdapter::Unflatten(uint32 format, BMessage *into, const char *buffer)
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
return _ConvertKMessage(&message, into);
|
||||
return _ConvertFromKMessage(&message, into);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -215,7 +215,7 @@ MessageAdapter::Unflatten(uint32 format, BMessage *into, const char *buffer)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::Unflatten(uint32 format, BMessage *into, BDataIO *stream)
|
||||
{
|
||||
try {
|
||||
@ -237,8 +237,8 @@ MessageAdapter::Unflatten(uint32 format, BMessage *into, BDataIO *stream)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MessageAdapter::_ConvertKMessage(const KMessage *fromMessage,
|
||||
/*static*/ status_t
|
||||
MessageAdapter::_ConvertFromKMessage(const KMessage *fromMessage,
|
||||
BMessage *toMessage)
|
||||
{
|
||||
if (!fromMessage || !toMessage)
|
||||
@ -253,7 +253,7 @@ MessageAdapter::_ConvertKMessage(const KMessage *fromMessage,
|
||||
toPrivate.SetReply(B_SYSTEM_TEAM, fromMessage->ReplyPort(),
|
||||
fromMessage->ReplyToken());
|
||||
|
||||
// iterate through the fields and import them in the target message
|
||||
// Iterate through the fields and import them in the target message
|
||||
KMessageField field;
|
||||
while (fromMessage->GetNextField(&field) == B_OK) {
|
||||
int32 elementCount = field.CountElements();
|
||||
@ -268,7 +268,7 @@ MessageAdapter::_ConvertKMessage(const KMessage *fromMessage,
|
||||
KMessage message;
|
||||
if (message.SetTo(data, size) == B_OK) {
|
||||
BMessage bMessage;
|
||||
result = _ConvertKMessage(&message, &bMessage);
|
||||
result = _ConvertFromKMessage(&message, &bMessage);
|
||||
if (result < B_OK)
|
||||
return result;
|
||||
|
||||
@ -294,7 +294,7 @@ MessageAdapter::_ConvertKMessage(const KMessage *fromMessage,
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
/*static*/ ssize_t
|
||||
MessageAdapter::_R5FlattenedSize(const BMessage *from)
|
||||
{
|
||||
BMessage::Private messagePrivate((BMessage *)from);
|
||||
@ -357,7 +357,7 @@ MessageAdapter::_R5FlattenedSize(const BMessage *from)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::_FlattenR5Message(uint32 format, const BMessage *from,
|
||||
char *buffer, ssize_t *size)
|
||||
{
|
||||
@ -500,7 +500,7 @@ MessageAdapter::_FlattenR5Message(uint32 format, const BMessage *from,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
|
||||
BDataIO *stream)
|
||||
{
|
||||
@ -552,7 +552,7 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
|
||||
|
||||
uint8 flags;
|
||||
reader(flags);
|
||||
while (flags & R5_FIELD_FLAG_VALID) {
|
||||
while ((flags & R5_FIELD_FLAG_VALID) != 0) {
|
||||
bool fixedSize = flags & R5_FIELD_FLAG_FIXED_SIZE;
|
||||
bool miniData = flags & R5_FIELD_FLAG_MINI_DATA;
|
||||
bool singleItem = flags & R5_FIELD_FLAG_SINGLE_ITEM;
|
||||
@ -616,8 +616,10 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
|
||||
|
||||
if (fixedSize)
|
||||
pointer += itemSize;
|
||||
else
|
||||
pointer += pad_to_8(itemSize + sizeof(int32)) - sizeof(int32);
|
||||
else {
|
||||
pointer += pad_to_8(itemSize + sizeof(int32))
|
||||
- sizeof(int32);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int32 i = 0; i < itemCount; i++) {
|
||||
@ -637,8 +639,10 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
|
||||
|
||||
if (fixedSize)
|
||||
pointer += itemSize;
|
||||
else
|
||||
pointer += pad_to_8(itemSize + sizeof(int32)) - sizeof(int32);
|
||||
else {
|
||||
pointer += pad_to_8(itemSize + sizeof(int32))
|
||||
- sizeof(int32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -652,7 +656,7 @@ MessageAdapter::_UnflattenR5Message(uint32 format, BMessage *into,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
/*static*/ status_t
|
||||
MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
BDataIO *stream)
|
||||
{
|
||||
@ -704,7 +708,8 @@ MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
// discard
|
||||
break;
|
||||
|
||||
case SECTION_SINGLE_ITEM_DATA: {
|
||||
case SECTION_SINGLE_ITEM_DATA:
|
||||
{
|
||||
dano_single_item *field = (dano_single_item *)fieldBuffer;
|
||||
|
||||
int32 dataOffset = sizeof(dano_single_item)
|
||||
@ -737,7 +742,7 @@ MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
status_t result = into->AddData(field->name, field->type,
|
||||
fieldBuffer + dataOffset, field->item_size, fixedSize);
|
||||
|
||||
if (result < B_OK) {
|
||||
if (result != B_OK) {
|
||||
free(fieldBuffer);
|
||||
throw result;
|
||||
}
|
||||
@ -763,7 +768,7 @@ MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
fieldBuffer + dataOffset, field->size_per_item, true,
|
||||
count);
|
||||
|
||||
if (result < B_OK) {
|
||||
if (result != B_OK) {
|
||||
free(fieldBuffer);
|
||||
throw result;
|
||||
}
|
||||
@ -796,7 +801,7 @@ MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
fieldBuffer + dataOffset + itemOffset,
|
||||
endPoints[i] - itemOffset, false, count);
|
||||
|
||||
if (result < B_OK) {
|
||||
if (result != B_OK) {
|
||||
free(fieldBuffer);
|
||||
throw result;
|
||||
}
|
||||
@ -812,4 +817,5 @@ MessageAdapter::_UnflattenDanoMessage(uint32 format, BMessage *into,
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
Loading…
Reference in New Issue
Block a user