Style cleanup. No functional change.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34152 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2007, Ingo Weinhold, [email protected]. All rights reserved.
|
* Copyright 2005-2009, Ingo Weinhold, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef KMESSAGE_H
|
#ifndef _KERNEL_UTIL_KMESSAGE_H
|
||||||
#define KMESSAGE_H
|
#define _KERNEL_UTIL_KMESSAGE_H
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -16,219 +17,267 @@
|
|||||||
|
|
||||||
class BMessage;
|
class BMessage;
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
class KMessageField;
|
class KMessageField;
|
||||||
class MessageAdapter;
|
class MessageAdapter;
|
||||||
|
|
||||||
// KMessage
|
|
||||||
class KMessage {
|
class KMessage {
|
||||||
public:
|
public:
|
||||||
enum {
|
enum {
|
||||||
KMESSAGE_OWNS_BUFFER = 0x01,
|
KMESSAGE_OWNS_BUFFER = 0x01,
|
||||||
KMESSAGE_INIT_FROM_BUFFER = 0x02,
|
KMESSAGE_INIT_FROM_BUFFER = 0x02,
|
||||||
KMESSAGE_READ_ONLY = 0x04,
|
KMESSAGE_READ_ONLY = 0x04,
|
||||||
|
|
||||||
KMESSAGE_FLAG_MASK = 0x07,
|
KMESSAGE_FLAG_MASK = 0x07,
|
||||||
};
|
};
|
||||||
|
|
||||||
KMessage();
|
public:
|
||||||
KMessage(uint32 what);
|
KMessage();
|
||||||
~KMessage();
|
KMessage(uint32 what);
|
||||||
|
~KMessage();
|
||||||
|
|
||||||
status_t SetTo(uint32 what, uint32 flags = 0);
|
status_t SetTo(uint32 what, uint32 flags = 0);
|
||||||
status_t SetTo(void *buffer, int32 bufferSize, uint32 what,
|
status_t SetTo(void* buffer, int32 bufferSize,
|
||||||
uint32 flags = 0);
|
uint32 what, uint32 flags = 0);
|
||||||
status_t SetTo(const void *buffer, int32 bufferSize = -1);
|
status_t SetTo(const void* buffer,
|
||||||
void Unset();
|
int32 bufferSize = -1);
|
||||||
|
void Unset();
|
||||||
|
|
||||||
void SetWhat(uint32 what);
|
void SetWhat(uint32 what);
|
||||||
uint32 What() const;
|
uint32 What() const;
|
||||||
|
|
||||||
const void *Buffer() const;
|
const void* Buffer() const;
|
||||||
int32 BufferCapacity() const;
|
int32 BufferCapacity() const;
|
||||||
int32 ContentSize() const;
|
int32 ContentSize() const;
|
||||||
|
|
||||||
status_t AddField(const char *name, type_code type, int32 elementSize = -1,
|
status_t AddField(const char* name, type_code type,
|
||||||
KMessageField *field = NULL);
|
int32 elementSize = -1,
|
||||||
status_t FindField(const char *name, KMessageField *field) const;
|
KMessageField* field = NULL);
|
||||||
status_t FindField(const char *name, type_code type,
|
status_t FindField(const char* name,
|
||||||
KMessageField *field) const;
|
KMessageField* field) const;
|
||||||
status_t GetNextField(KMessageField *field) const;
|
status_t FindField(const char* name, type_code type,
|
||||||
bool IsEmpty() const;
|
KMessageField* field) const;
|
||||||
|
status_t GetNextField(KMessageField* field) const;
|
||||||
|
bool IsEmpty() const;
|
||||||
|
|
||||||
status_t AddData(const char *name, type_code type, const void *data,
|
status_t AddData(const char* name, type_code type,
|
||||||
int32 numBytes, bool isFixedSize = true);
|
const void* data, int32 numBytes,
|
||||||
status_t AddArray(const char *name, type_code type, const void *data,
|
bool isFixedSize = true);
|
||||||
int32 elementSize, int32 elementCount);
|
status_t AddArray(const char* name, type_code type,
|
||||||
inline status_t AddBool(const char *name, bool value);
|
const void* data, int32 elementSize,
|
||||||
inline status_t AddInt8(const char *name, int8 value);
|
int32 elementCount);
|
||||||
inline status_t AddInt16(const char *name, int16 value);
|
inline status_t AddBool(const char* name, bool value);
|
||||||
inline status_t AddInt32(const char *name, int32 value);
|
inline status_t AddInt8(const char* name, int8 value);
|
||||||
inline status_t AddInt64(const char *name, int64 value);
|
inline status_t AddInt16(const char* name, int16 value);
|
||||||
inline status_t AddPointer(const char *name, const void* value);
|
inline status_t AddInt32(const char* name, int32 value);
|
||||||
inline status_t AddString(const char *name, const char *value);
|
inline status_t AddInt64(const char* name, int64 value);
|
||||||
|
inline status_t AddPointer(const char* name, const void* value);
|
||||||
|
inline status_t AddString(const char* name, const char* value);
|
||||||
|
|
||||||
status_t FindData(const char *name, type_code type,
|
status_t FindData(const char* name, type_code type,
|
||||||
const void **data, int32 *numBytes) const;
|
const void** data, int32* numBytes) const;
|
||||||
status_t FindData(const char *name, type_code type, int32 index,
|
status_t FindData(const char* name, type_code type,
|
||||||
const void **data, int32 *numBytes) const;
|
int32 index, const void** data,
|
||||||
inline status_t FindBool(const char *name, bool *value) const;
|
int32* numBytes) const;
|
||||||
inline status_t FindBool(const char *name, int32 index, bool *value) const;
|
inline status_t FindBool(const char* name, bool* value) const;
|
||||||
inline status_t FindInt8(const char *name, int8 *value) const;
|
inline status_t FindBool(const char* name, int32 index,
|
||||||
inline status_t FindInt8(const char *name, int32 index, int8 *value) const;
|
bool* value) const;
|
||||||
inline status_t FindInt16(const char *name, int16 *value) const;
|
inline status_t FindInt8(const char* name, int8* value) const;
|
||||||
inline status_t FindInt16(const char *name, int32 index, int16 *value) const;
|
inline status_t FindInt8(const char* name, int32 index,
|
||||||
inline status_t FindInt32(const char *name, int32 *value) const;
|
int8* value) const;
|
||||||
inline status_t FindInt32(const char *name, int32 index, int32 *value) const;
|
inline status_t FindInt16(const char* name, int16* value) const;
|
||||||
inline status_t FindInt64(const char *name, int64 *value) const;
|
inline status_t FindInt16(const char* name, int32 index,
|
||||||
inline status_t FindInt64(const char *name, int32 index, int64 *value) const;
|
int16* value) const;
|
||||||
inline status_t FindPointer(const char *name, void** value) const;
|
inline status_t FindInt32(const char* name, int32* value) const;
|
||||||
inline status_t FindPointer(const char *name, int32 index,
|
inline status_t FindInt32(const char* name, int32 index,
|
||||||
void** value) const;
|
int32* value) const;
|
||||||
inline status_t FindString(const char *name, const char **value) const;
|
inline status_t FindInt64(const char* name, int64* value) const;
|
||||||
inline status_t FindString(const char *name, int32 index,
|
inline status_t FindInt64(const char* name, int32 index,
|
||||||
const char **value) const;
|
int64* value) const;
|
||||||
|
inline status_t FindPointer(const char* name,
|
||||||
|
void** value) const;
|
||||||
|
inline status_t FindPointer(const char* name, int32 index,
|
||||||
|
void** value) const;
|
||||||
|
inline status_t FindString(const char* name,
|
||||||
|
const char** value) const;
|
||||||
|
inline status_t FindString(const char* name, int32 index,
|
||||||
|
const char** value) const;
|
||||||
|
|
||||||
inline bool GetBool(const char* name, bool defaultValue) const;
|
inline bool GetBool(const char* name,
|
||||||
inline bool GetBool(const char* name, int32 index, bool defaultValue) const;
|
bool defaultValue) const;
|
||||||
inline int8 GetInt8(const char* name, int8 defaultValue) const;
|
inline bool GetBool(const char* name, int32 index,
|
||||||
inline int8 GetInt8(const char* name, int32 index, int8 defaultValue) const;
|
bool defaultValue) const;
|
||||||
inline int16 GetInt16(const char* name, int16 defaultValue) const;
|
inline int8 GetInt8(const char* name,
|
||||||
inline int16 GetInt16(const char* name, int32 index,
|
int8 defaultValue) const;
|
||||||
int16 defaultValue) const;
|
inline int8 GetInt8(const char* name, int32 index,
|
||||||
inline int32 GetInt32(const char* name, int32 defaultValue) const;
|
int8 defaultValue) const;
|
||||||
inline int32 GetInt32(const char* name, int32 index,
|
inline int16 GetInt16(const char* name,
|
||||||
int32 defaultValue) const;
|
int16 defaultValue) const;
|
||||||
inline int64 GetInt64(const char* name, int64 defaultValue) const;
|
inline int16 GetInt16(const char* name, int32 index,
|
||||||
inline int64 GetInt64(const char* name, int32 index,
|
int16 defaultValue) const;
|
||||||
int64 defaultValue) const;
|
inline int32 GetInt32(const char* name,
|
||||||
inline void* GetPointer(const char* name, const void* defaultValue) const;
|
int32 defaultValue) const;
|
||||||
inline void* GetPointer(const char* name, int32 index,
|
inline int32 GetInt32(const char* name, int32 index,
|
||||||
const void* defaultValue) const;
|
int32 defaultValue) const;
|
||||||
inline const char* GetString(const char* name,
|
inline int64 GetInt64(const char* name,
|
||||||
const char* defaultValue) const;
|
int64 defaultValue) const;
|
||||||
inline const char* GetString(const char* name, int32 index,
|
inline int64 GetInt64(const char* name, int32 index,
|
||||||
const char* defaultValue) const;
|
int64 defaultValue) const;
|
||||||
|
inline void* GetPointer(const char* name,
|
||||||
|
const void* defaultValue) const;
|
||||||
|
inline void* GetPointer(const char* name, int32 index,
|
||||||
|
const void* defaultValue) const;
|
||||||
|
inline const char* GetString(const char* name,
|
||||||
|
const char* defaultValue) const;
|
||||||
|
inline const char* GetString(const char* name, int32 index,
|
||||||
|
const char* defaultValue) const;
|
||||||
|
|
||||||
// fixed size fields only
|
// fixed size fields only
|
||||||
status_t SetData(const char* name, type_code type, const void* data,
|
status_t SetData(const char* name, type_code type,
|
||||||
int32 numBytes);
|
const void* data, int32 numBytes);
|
||||||
inline status_t SetBool(const char* name, bool value);
|
inline status_t SetBool(const char* name, bool value);
|
||||||
inline status_t SetInt8(const char* name, int8 value);
|
inline status_t SetInt8(const char* name, int8 value);
|
||||||
inline status_t SetInt16(const char* name, int16 value);
|
inline status_t SetInt16(const char* name, int16 value);
|
||||||
inline status_t SetInt32(const char* name, int32 value);
|
inline status_t SetInt32(const char* name, int32 value);
|
||||||
inline status_t SetInt64(const char* name, int64 value);
|
inline status_t SetInt64(const char* name, int64 value);
|
||||||
inline status_t SetPointer(const char* name, const void* value);
|
inline status_t SetPointer(const char* name, const void* value);
|
||||||
|
|
||||||
// message delivery
|
// message delivery
|
||||||
team_id Sender() const;
|
team_id Sender() const;
|
||||||
int32 TargetToken() const;
|
int32 TargetToken() const;
|
||||||
port_id ReplyPort() const;
|
port_id ReplyPort() const;
|
||||||
int32 ReplyToken() const;
|
int32 ReplyToken() const;
|
||||||
|
|
||||||
void SetDeliveryInfo(int32 targetToken, port_id replyPort,
|
void SetDeliveryInfo(int32 targetToken,
|
||||||
int32 replyToken, team_id senderTeam);
|
port_id replyPort, int32 replyToken,
|
||||||
|
team_id senderTeam);
|
||||||
|
|
||||||
status_t SendTo(port_id targetPort, int32 targetToken = -1,
|
status_t SendTo(port_id targetPort,
|
||||||
port_id replyPort = -1, int32 replyToken = -1, bigtime_t timeout = -1,
|
int32 targetToken = -1,
|
||||||
team_id senderTeam = -1);
|
port_id replyPort = -1,
|
||||||
status_t SendTo(port_id targetPort, int32 targetToken,
|
int32 replyToken = -1,
|
||||||
KMessage* reply, bigtime_t deliveryTimeout = -1,
|
bigtime_t timeout = -1,
|
||||||
bigtime_t replyTimeout = -1, team_id senderTeam = -1);
|
team_id senderTeam = -1);
|
||||||
status_t SendReply(KMessage* message, port_id replyPort = -1,
|
status_t SendTo(port_id targetPort, int32 targetToken,
|
||||||
int32 replyToken = -1, bigtime_t timeout = -1, team_id senderTeam = -1);
|
KMessage* reply,
|
||||||
status_t SendReply(KMessage* message, KMessage* reply,
|
bigtime_t deliveryTimeout = -1,
|
||||||
bigtime_t deliveryTimeout = -1, bigtime_t replyTimeout = -1,
|
bigtime_t replyTimeout = -1,
|
||||||
team_id senderTeam = -1);
|
team_id senderTeam = -1);
|
||||||
status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1,
|
status_t SendReply(KMessage* message,
|
||||||
port_message_info* messageInfo = NULL);
|
port_id replyPort = -1,
|
||||||
|
int32 replyToken = -1,
|
||||||
|
bigtime_t timeout = -1,
|
||||||
|
team_id senderTeam = -1);
|
||||||
|
status_t SendReply(KMessage* message, KMessage* reply,
|
||||||
|
bigtime_t deliveryTimeout = -1,
|
||||||
|
bigtime_t replyTimeout = -1,
|
||||||
|
team_id senderTeam = -1);
|
||||||
|
status_t ReceiveFrom(port_id fromPort,
|
||||||
|
bigtime_t timeout = -1,
|
||||||
|
port_message_info* messageInfo = NULL);
|
||||||
|
|
||||||
void Dump(void (*printFunc)(const char*, ...)) const;
|
void Dump(void (*printFunc)(const char*, ...)) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class KMessageField;
|
friend class KMessageField;
|
||||||
friend class MessageAdapter;
|
friend class MessageAdapter;
|
||||||
friend class ::BMessage; // not so nice, but makes things easier
|
friend class ::BMessage; // not so nice, but makes things easier
|
||||||
|
|
||||||
struct Header {
|
struct Header {
|
||||||
uint32 magic;
|
uint32 magic;
|
||||||
int32 size;
|
int32 size;
|
||||||
uint32 what;
|
uint32 what;
|
||||||
team_id sender;
|
team_id sender;
|
||||||
int32 targetToken;
|
int32 targetToken;
|
||||||
port_id replyPort;
|
port_id replyPort;
|
||||||
int32 replyToken;
|
int32 replyToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FieldHeader;
|
struct FieldHeader;
|
||||||
struct FieldValueHeader;
|
struct FieldValueHeader;
|
||||||
|
|
||||||
Header *_Header() const;
|
private:
|
||||||
int32 _BufferOffsetFor(const void* data) const;
|
Header* _Header() const;
|
||||||
FieldHeader *_FirstFieldHeader() const;
|
int32 _BufferOffsetFor(const void* data) const;
|
||||||
FieldHeader *_LastFieldHeader() const;
|
FieldHeader* _FirstFieldHeader() const;
|
||||||
FieldHeader *_FieldHeaderForOffset(int32 offset) const;
|
FieldHeader* _LastFieldHeader() const;
|
||||||
status_t _AddField(const char *name, type_code type, int32 elementSize,
|
FieldHeader* _FieldHeaderForOffset(int32 offset) const;
|
||||||
KMessageField *field);
|
status_t _AddField(const char* name, type_code type,
|
||||||
status_t _AddFieldData(KMessageField *field, const void *data,
|
int32 elementSize, KMessageField* field);
|
||||||
int32 elementSize, int32 elementCount);
|
status_t _AddFieldData(KMessageField* field,
|
||||||
|
const void* data, int32 elementSize,
|
||||||
|
int32 elementCount);
|
||||||
|
|
||||||
status_t _InitFromBuffer(bool sizeFromBuffer);
|
status_t _InitFromBuffer(bool sizeFromBuffer);
|
||||||
void _InitBuffer(uint32 what);
|
void _InitBuffer(uint32 what);
|
||||||
|
|
||||||
void _CheckBuffer(); // debugging only
|
void _CheckBuffer(); // debugging only
|
||||||
|
|
||||||
status_t _AllocateSpace(int32 size, bool alignAddress, bool alignSize,
|
status_t _AllocateSpace(int32 size, bool alignAddress,
|
||||||
void **address, int32 *alignedSize);
|
bool alignSize, void** address,
|
||||||
int32 _CapacityFor(int32 size);
|
int32* alignedSize);
|
||||||
template<typename T> inline status_t _FindType(const char* name,
|
int32 _CapacityFor(int32 size);
|
||||||
type_code type, int32 index, T *value) const;
|
|
||||||
template<typename T> inline T _GetType(const char* name, type_code type,
|
|
||||||
int32 index, const T& defaultValue) const;
|
|
||||||
|
|
||||||
Header fHeader; // pointed to by fBuffer, if nothing is
|
template<typename T>
|
||||||
// allocated
|
inline status_t _FindType(const char* name, type_code type,
|
||||||
void* fBuffer;
|
int32 index, T* value) const;
|
||||||
int32 fBufferCapacity;
|
|
||||||
uint32 fFlags;
|
|
||||||
int32 fLastFieldOffset;
|
|
||||||
|
|
||||||
static const uint32 kMessageHeaderMagic;
|
template<typename T>
|
||||||
|
inline T _GetType(const char* name, type_code type,
|
||||||
|
int32 index, const T& defaultValue) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Header fHeader; // pointed to by fBuffer, if nothing
|
||||||
|
// is allocated
|
||||||
|
void* fBuffer;
|
||||||
|
int32 fBufferCapacity;
|
||||||
|
uint32 fFlags;
|
||||||
|
int32 fLastFieldOffset;
|
||||||
|
|
||||||
|
static const uint32 kMessageHeaderMagic;
|
||||||
};
|
};
|
||||||
|
|
||||||
// KMessageField
|
// KMessageField
|
||||||
class KMessageField {
|
class KMessageField {
|
||||||
public:
|
public:
|
||||||
KMessageField();
|
KMessageField();
|
||||||
|
|
||||||
void Unset();
|
void Unset();
|
||||||
|
|
||||||
KMessage *Message() const;
|
KMessage* Message() const;
|
||||||
|
|
||||||
const char *Name() const;
|
const char* Name() const;
|
||||||
type_code TypeCode() const;
|
type_code TypeCode() const;
|
||||||
bool HasFixedElementSize() const;
|
bool HasFixedElementSize() const;
|
||||||
int32 ElementSize() const; // if HasFixedElementSize()
|
int32 ElementSize() const;
|
||||||
|
// only if HasFixedElementSize()
|
||||||
|
|
||||||
status_t AddElement(const void *data, int32 size = -1);
|
status_t AddElement(const void* data, int32 size = -1);
|
||||||
status_t AddElements(const void *data, int32 count, int32 elementSize = -1);
|
status_t AddElements(const void* data, int32 count,
|
||||||
const void *ElementAt(int32 index, int32 *size = NULL) const;
|
int32 elementSize = -1);
|
||||||
int32 CountElements() const;
|
const void* ElementAt(int32 index,
|
||||||
|
int32* size = NULL) const;
|
||||||
|
int32 CountElements() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetTo(KMessage *message, int32 headerOffset);
|
friend class KMessage;
|
||||||
|
|
||||||
KMessage::FieldHeader* _Header() const;
|
private:
|
||||||
|
void SetTo(KMessage* message, int32 headerOffset);
|
||||||
|
|
||||||
friend class KMessage;
|
KMessage::FieldHeader* _Header() const;
|
||||||
|
|
||||||
KMessage *fMessage;
|
private:
|
||||||
int32 fHeaderOffset;
|
KMessage* fMessage;
|
||||||
|
int32 fHeaderOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|
||||||
using BPrivate::KMessage;
|
using BPrivate::KMessage;
|
||||||
using BPrivate::KMessageField;
|
using BPrivate::KMessageField;
|
||||||
|
|
||||||
@@ -239,7 +288,7 @@ using BPrivate::KMessageField;
|
|||||||
// AddBool
|
// AddBool
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddBool(const char *name, bool value)
|
KMessage::AddBool(const char* name, bool value)
|
||||||
{
|
{
|
||||||
return AddData(name, B_BOOL_TYPE, &value, sizeof(bool), true);
|
return AddData(name, B_BOOL_TYPE, &value, sizeof(bool), true);
|
||||||
}
|
}
|
||||||
@@ -247,7 +296,7 @@ KMessage::AddBool(const char *name, bool value)
|
|||||||
// AddInt8
|
// AddInt8
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddInt8(const char *name, int8 value)
|
KMessage::AddInt8(const char* name, int8 value)
|
||||||
{
|
{
|
||||||
return AddData(name, B_INT8_TYPE, &value, sizeof(int8), true);
|
return AddData(name, B_INT8_TYPE, &value, sizeof(int8), true);
|
||||||
}
|
}
|
||||||
@@ -255,7 +304,7 @@ KMessage::AddInt8(const char *name, int8 value)
|
|||||||
// AddInt16
|
// AddInt16
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddInt16(const char *name, int16 value)
|
KMessage::AddInt16(const char* name, int16 value)
|
||||||
{
|
{
|
||||||
return AddData(name, B_INT16_TYPE, &value, sizeof(int16), true);
|
return AddData(name, B_INT16_TYPE, &value, sizeof(int16), true);
|
||||||
}
|
}
|
||||||
@@ -263,14 +312,14 @@ KMessage::AddInt16(const char *name, int16 value)
|
|||||||
// AddInt32
|
// AddInt32
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddInt32(const char *name, int32 value)
|
KMessage::AddInt32(const char* name, int32 value)
|
||||||
{
|
{
|
||||||
return AddData(name, B_INT32_TYPE, &value, sizeof(int32), true);
|
return AddData(name, B_INT32_TYPE, &value, sizeof(int32), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddInt64
|
// AddInt64
|
||||||
inline status_t
|
inline status_t
|
||||||
KMessage::AddInt64(const char *name, int64 value)
|
KMessage::AddInt64(const char* name, int64 value)
|
||||||
{
|
{
|
||||||
return AddData(name, B_INT64_TYPE, &value, sizeof(int64), true);
|
return AddData(name, B_INT64_TYPE, &value, sizeof(int64), true);
|
||||||
}
|
}
|
||||||
@@ -278,7 +327,7 @@ KMessage::AddInt64(const char *name, int64 value)
|
|||||||
|
|
||||||
// AddPointer
|
// AddPointer
|
||||||
inline status_t
|
inline status_t
|
||||||
KMessage::AddPointer(const char *name, const void* value)
|
KMessage::AddPointer(const char* name, const void* value)
|
||||||
{
|
{
|
||||||
return AddData(name, B_POINTER_TYPE, &value, sizeof(value), true);
|
return AddData(name, B_POINTER_TYPE, &value, sizeof(value), true);
|
||||||
}
|
}
|
||||||
@@ -287,7 +336,7 @@ KMessage::AddPointer(const char *name, const void* value)
|
|||||||
// AddString
|
// AddString
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddString(const char *name, const char *value)
|
KMessage::AddString(const char* name, const char* value)
|
||||||
{
|
{
|
||||||
if (!value)
|
if (!value)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -302,9 +351,9 @@ KMessage::AddString(const char *name, const char *value)
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline status_t
|
inline status_t
|
||||||
KMessage::_FindType(const char* name, type_code type, int32 index,
|
KMessage::_FindType(const char* name, type_code type, int32 index,
|
||||||
T *value) const
|
T* value) const
|
||||||
{
|
{
|
||||||
const void *data;
|
const void* data;
|
||||||
int32 size;
|
int32 size;
|
||||||
status_t error = FindData(name, type, index, &data, &size);
|
status_t error = FindData(name, type, index, &data, &size);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
@@ -321,7 +370,7 @@ KMessage::_FindType(const char* name, type_code type, int32 index,
|
|||||||
// FindBool
|
// FindBool
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindBool(const char *name, bool *value) const
|
KMessage::FindBool(const char* name, bool* value) const
|
||||||
{
|
{
|
||||||
return FindBool(name, 0, value);
|
return FindBool(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -329,7 +378,7 @@ KMessage::FindBool(const char *name, bool *value) const
|
|||||||
// FindBool
|
// FindBool
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindBool(const char *name, int32 index, bool *value) const
|
KMessage::FindBool(const char* name, int32 index, bool* value) const
|
||||||
{
|
{
|
||||||
return _FindType(name, B_BOOL_TYPE, index, value);
|
return _FindType(name, B_BOOL_TYPE, index, value);
|
||||||
}
|
}
|
||||||
@@ -337,7 +386,7 @@ KMessage::FindBool(const char *name, int32 index, bool *value) const
|
|||||||
// FindInt8
|
// FindInt8
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt8(const char *name, int8 *value) const
|
KMessage::FindInt8(const char* name, int8* value) const
|
||||||
{
|
{
|
||||||
return FindInt8(name, 0, value);
|
return FindInt8(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -345,7 +394,7 @@ KMessage::FindInt8(const char *name, int8 *value) const
|
|||||||
// FindInt8
|
// FindInt8
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt8(const char *name, int32 index, int8 *value) const
|
KMessage::FindInt8(const char* name, int32 index, int8* value) const
|
||||||
{
|
{
|
||||||
return _FindType(name, B_INT8_TYPE, index, value);
|
return _FindType(name, B_INT8_TYPE, index, value);
|
||||||
}
|
}
|
||||||
@@ -353,7 +402,7 @@ KMessage::FindInt8(const char *name, int32 index, int8 *value) const
|
|||||||
// FindInt16
|
// FindInt16
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt16(const char *name, int16 *value) const
|
KMessage::FindInt16(const char* name, int16* value) const
|
||||||
{
|
{
|
||||||
return FindInt16(name, 0, value);
|
return FindInt16(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -361,7 +410,7 @@ KMessage::FindInt16(const char *name, int16 *value) const
|
|||||||
// FindInt16
|
// FindInt16
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt16(const char *name, int32 index, int16 *value) const
|
KMessage::FindInt16(const char* name, int32 index, int16* value) const
|
||||||
{
|
{
|
||||||
return _FindType(name, B_INT16_TYPE, index, value);
|
return _FindType(name, B_INT16_TYPE, index, value);
|
||||||
}
|
}
|
||||||
@@ -369,7 +418,7 @@ KMessage::FindInt16(const char *name, int32 index, int16 *value) const
|
|||||||
// FindInt32
|
// FindInt32
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt32(const char *name, int32 *value) const
|
KMessage::FindInt32(const char* name, int32* value) const
|
||||||
{
|
{
|
||||||
return FindInt32(name, 0, value);
|
return FindInt32(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -377,7 +426,7 @@ KMessage::FindInt32(const char *name, int32 *value) const
|
|||||||
// FindInt32
|
// FindInt32
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt32(const char *name, int32 index, int32 *value) const
|
KMessage::FindInt32(const char* name, int32 index, int32* value) const
|
||||||
{
|
{
|
||||||
return _FindType(name, B_INT32_TYPE, index, value);
|
return _FindType(name, B_INT32_TYPE, index, value);
|
||||||
}
|
}
|
||||||
@@ -385,7 +434,7 @@ KMessage::FindInt32(const char *name, int32 index, int32 *value) const
|
|||||||
// FindInt64
|
// FindInt64
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt64(const char *name, int64 *value) const
|
KMessage::FindInt64(const char* name, int64* value) const
|
||||||
{
|
{
|
||||||
return FindInt64(name, 0, value);
|
return FindInt64(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -393,7 +442,7 @@ KMessage::FindInt64(const char *name, int64 *value) const
|
|||||||
// FindInt64
|
// FindInt64
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindInt64(const char *name, int32 index, int64 *value) const
|
KMessage::FindInt64(const char* name, int32 index, int64* value) const
|
||||||
{
|
{
|
||||||
return _FindType(name, B_INT64_TYPE, index, value);
|
return _FindType(name, B_INT64_TYPE, index, value);
|
||||||
}
|
}
|
||||||
@@ -401,7 +450,7 @@ KMessage::FindInt64(const char *name, int32 index, int64 *value) const
|
|||||||
|
|
||||||
// FindPointer
|
// FindPointer
|
||||||
inline status_t
|
inline status_t
|
||||||
KMessage::FindPointer(const char *name, void** value) const
|
KMessage::FindPointer(const char* name, void** value) const
|
||||||
{
|
{
|
||||||
return FindPointer(name, 0, value);
|
return FindPointer(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -409,7 +458,7 @@ KMessage::FindPointer(const char *name, void** value) const
|
|||||||
|
|
||||||
// FindPointer
|
// FindPointer
|
||||||
inline status_t
|
inline status_t
|
||||||
KMessage::FindPointer(const char *name, int32 index, void** value) const
|
KMessage::FindPointer(const char* name, int32 index, void** value) const
|
||||||
{
|
{
|
||||||
return _FindType(name, B_POINTER_TYPE, index, value);
|
return _FindType(name, B_POINTER_TYPE, index, value);
|
||||||
}
|
}
|
||||||
@@ -418,7 +467,7 @@ KMessage::FindPointer(const char *name, int32 index, void** value) const
|
|||||||
// FindString
|
// FindString
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindString(const char *name, const char **value) const
|
KMessage::FindString(const char* name, const char** value) const
|
||||||
{
|
{
|
||||||
return FindString(name, 0, value);
|
return FindString(name, 0, value);
|
||||||
}
|
}
|
||||||
@@ -426,7 +475,7 @@ KMessage::FindString(const char *name, const char **value) const
|
|||||||
// FindString
|
// FindString
|
||||||
inline
|
inline
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindString(const char *name, int32 index, const char **value) const
|
KMessage::FindString(const char* name, int32 index, const char** value) const
|
||||||
{
|
{
|
||||||
int32 size;
|
int32 size;
|
||||||
return FindData(name, B_STRING_TYPE, index, (const void**)value, &size);
|
return FindData(name, B_STRING_TYPE, index, (const void**)value, &size);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2007, Ingo Weinhold, [email protected].
|
* Copyright 2005-2009, Ingo Weinhold, [email protected].
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <util/KMessage.h>
|
#include <util/KMessage.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -13,17 +14,18 @@
|
|||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(_BOOT_MODE) || defined(_LOADER_MODE)
|
#if defined(_BOOT_MODE) || defined(_LOADER_MODE)
|
||||||
# include <util/kernel_cpp.h>
|
# include <util/kernel_cpp.h>
|
||||||
#else
|
#else
|
||||||
# include <new>
|
# include <new>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using std::nothrow;
|
|
||||||
|
|
||||||
// TODO: Add a field index using a hash map, so that lookup improves to O(1)
|
// TODO: Add a field index using a hash map, so that lookup improves to O(1)
|
||||||
// (is now O(n)).
|
// (is now O(n)).
|
||||||
|
|
||||||
|
|
||||||
// define the PANIC macro
|
// define the PANIC macro
|
||||||
#ifndef PANIC
|
#ifndef PANIC
|
||||||
# ifdef _KERNEL_MODE
|
# ifdef _KERNEL_MODE
|
||||||
@@ -33,43 +35,49 @@ using std::nothrow;
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static const int32 kMessageReallocChunkSize = 64;
|
static const int32 kMessageReallocChunkSize = 64;
|
||||||
|
|
||||||
// kMessageHeaderMagic
|
|
||||||
const uint32 KMessage::kMessageHeaderMagic = 'kMsG';
|
const uint32 KMessage::kMessageHeaderMagic = 'kMsG';
|
||||||
|
|
||||||
// _Align
|
|
||||||
static inline
|
// #pragma mark - Helper Functions
|
||||||
int32
|
|
||||||
|
static inline int32
|
||||||
_Align(int32 offset)
|
_Align(int32 offset)
|
||||||
{
|
{
|
||||||
return (offset + 3) & ~0x3;
|
return (offset + 3) & ~0x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _Align
|
|
||||||
static inline
|
static inline void*
|
||||||
void*
|
_Align(void* address, int32 offset = 0)
|
||||||
_Align(void *address, int32 offset = 0)
|
|
||||||
{
|
{
|
||||||
return (void*)(((uint32)address + offset + 3) & ~0x3);
|
return (void*)(((uint32)address + offset + 3) & ~0x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FieldValueHeader
|
|
||||||
|
// #pragma mark - FieldValueHeader
|
||||||
|
|
||||||
|
|
||||||
struct KMessage::FieldValueHeader {
|
struct KMessage::FieldValueHeader {
|
||||||
int32 size;
|
int32 size;
|
||||||
|
|
||||||
void *Data()
|
void* Data()
|
||||||
{
|
{
|
||||||
return _Align(this, sizeof(FieldValueHeader));
|
return _Align(this, sizeof(FieldValueHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldValueHeader *NextFieldValueHeader()
|
FieldValueHeader* NextFieldValueHeader()
|
||||||
{
|
{
|
||||||
return (FieldValueHeader*)_Align(Data(), size);
|
return (FieldValueHeader*)_Align(Data(), size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// FieldHeader
|
|
||||||
|
// #pragma mark - FieldHeader
|
||||||
|
|
||||||
|
|
||||||
struct KMessage::FieldHeader {
|
struct KMessage::FieldHeader {
|
||||||
type_code type;
|
type_code type;
|
||||||
int32 elementSize; // if < 0: non-fixed size
|
int32 elementSize; // if < 0: non-fixed size
|
||||||
@@ -78,64 +86,72 @@ struct KMessage::FieldHeader {
|
|||||||
int16 headerSize;
|
int16 headerSize;
|
||||||
char name[1];
|
char name[1];
|
||||||
|
|
||||||
void *Data()
|
void* Data()
|
||||||
{
|
{
|
||||||
return (uint8*)this + headerSize;
|
return (uint8*)this + headerSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasFixedElementSize() { return (elementSize >= 0); }
|
bool HasFixedElementSize()
|
||||||
|
{
|
||||||
|
return elementSize >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
void *ElementAt(int32 index, int32 *size)
|
void* ElementAt(int32 index, int32* size)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= elementCount)
|
if (index < 0 || index >= elementCount)
|
||||||
return NULL;
|
return NULL;
|
||||||
uint8 *data = (uint8*)this + headerSize;
|
uint8* data = (uint8*)this + headerSize;
|
||||||
if (HasFixedElementSize()) {
|
if (HasFixedElementSize()) {
|
||||||
*size = elementSize;
|
*size = elementSize;
|
||||||
return data + elementSize * index;
|
return data + elementSize * index;
|
||||||
}
|
}
|
||||||
// non-fixed element size: we need to iterate
|
// non-fixed element size: we need to iterate
|
||||||
FieldValueHeader *valueHeader = (FieldValueHeader *)data;
|
FieldValueHeader* valueHeader = (FieldValueHeader*)data;
|
||||||
for (int i = 0; i < index; i++)
|
for (int i = 0; i < index; i++)
|
||||||
valueHeader = valueHeader->NextFieldValueHeader();
|
valueHeader = valueHeader->NextFieldValueHeader();
|
||||||
*size = valueHeader->size;
|
*size = valueHeader->size;
|
||||||
return valueHeader->Data();
|
return valueHeader->Data();
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldHeader *NextFieldHeader()
|
FieldHeader* NextFieldHeader()
|
||||||
{
|
{
|
||||||
return (FieldHeader*)_Align(this, fieldSize);
|
return (FieldHeader*)_Align(this, fieldSize);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor
|
|
||||||
|
// #pragma mark - KMessage
|
||||||
|
|
||||||
|
|
||||||
KMessage::KMessage()
|
KMessage::KMessage()
|
||||||
: fBuffer(NULL),
|
:
|
||||||
fBufferCapacity(0),
|
fBuffer(NULL),
|
||||||
fFlags(0),
|
fBufferCapacity(0),
|
||||||
fLastFieldOffset(0)
|
fFlags(0),
|
||||||
|
fLastFieldOffset(0)
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
KMessage::KMessage(uint32 what)
|
KMessage::KMessage(uint32 what)
|
||||||
: fBuffer(NULL),
|
:
|
||||||
fBufferCapacity(0),
|
fBuffer(NULL),
|
||||||
fFlags(0),
|
fBufferCapacity(0),
|
||||||
fLastFieldOffset(0)
|
fFlags(0),
|
||||||
|
fLastFieldOffset(0)
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
SetWhat(what);
|
SetWhat(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
KMessage::~KMessage()
|
KMessage::~KMessage()
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTo
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SetTo(uint32 what, uint32 flags)
|
KMessage::SetTo(uint32 what, uint32 flags)
|
||||||
{
|
{
|
||||||
@@ -145,9 +161,9 @@ KMessage::SetTo(uint32 what, uint32 flags)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTo
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SetTo(void *buffer, int32 bufferSize, uint32 what, uint32 flags)
|
KMessage::SetTo(void* buffer, int32 bufferSize, uint32 what, uint32 flags)
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
|
|
||||||
@@ -180,15 +196,15 @@ KMessage::SetTo(void *buffer, int32 bufferSize, uint32 what, uint32 flags)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTo
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SetTo(const void *buffer, int32 bufferSize)
|
KMessage::SetTo(const void* buffer, int32 bufferSize)
|
||||||
{
|
{
|
||||||
return SetTo(const_cast<void*>(buffer), bufferSize, 0,
|
return SetTo(const_cast<void*>(buffer), bufferSize, 0,
|
||||||
KMESSAGE_INIT_FROM_BUFFER | KMESSAGE_READ_ONLY);
|
KMESSAGE_INIT_FROM_BUFFER | KMESSAGE_READ_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset
|
|
||||||
void
|
void
|
||||||
KMessage::Unset()
|
KMessage::Unset()
|
||||||
{
|
{
|
||||||
@@ -200,44 +216,44 @@ KMessage::Unset()
|
|||||||
_InitBuffer(0);
|
_InitBuffer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWhat
|
|
||||||
void
|
void
|
||||||
KMessage::SetWhat(uint32 what)
|
KMessage::SetWhat(uint32 what)
|
||||||
{
|
{
|
||||||
_Header()->what = what;
|
_Header()->what = what;
|
||||||
}
|
}
|
||||||
|
|
||||||
// What
|
|
||||||
uint32
|
uint32
|
||||||
KMessage::What() const
|
KMessage::What() const
|
||||||
{
|
{
|
||||||
return _Header()->what;
|
return _Header()->what;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffer
|
|
||||||
const void *
|
const void*
|
||||||
KMessage::Buffer() const
|
KMessage::Buffer() const
|
||||||
{
|
{
|
||||||
return fBuffer;
|
return fBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BufferCapacity
|
|
||||||
int32
|
int32
|
||||||
KMessage::BufferCapacity() const
|
KMessage::BufferCapacity() const
|
||||||
{
|
{
|
||||||
return fBufferCapacity;
|
return fBufferCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContentSize
|
|
||||||
int32
|
int32
|
||||||
KMessage::ContentSize() const
|
KMessage::ContentSize() const
|
||||||
{
|
{
|
||||||
return _Header()->size;
|
return _Header()->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddField
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddField(const char *name, type_code type, int32 elementSize,
|
KMessage::AddField(const char* name, type_code type, int32 elementSize,
|
||||||
KMessageField* field)
|
KMessageField* field)
|
||||||
{
|
{
|
||||||
if (!name || type == B_ANY_TYPE)
|
if (!name || type == B_ANY_TYPE)
|
||||||
@@ -248,17 +264,17 @@ KMessage::AddField(const char *name, type_code type, int32 elementSize,
|
|||||||
return _AddField(name, type, elementSize, field);
|
return _AddField(name, type, elementSize, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindField
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindField(const char *name, KMessageField *field) const
|
KMessage::FindField(const char* name, KMessageField* field) const
|
||||||
{
|
{
|
||||||
return FindField(name, B_ANY_TYPE, field);
|
return FindField(name, B_ANY_TYPE, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindField
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindField(const char *name, type_code type,
|
KMessage::FindField(const char* name, type_code type,
|
||||||
KMessageField *field) const
|
KMessageField* field) const
|
||||||
{
|
{
|
||||||
if (!name)
|
if (!name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -276,13 +292,13 @@ KMessage::FindField(const char *name, type_code type,
|
|||||||
return B_NAME_NOT_FOUND;
|
return B_NAME_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNextField
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::GetNextField(KMessageField *field) const
|
KMessage::GetNextField(KMessageField* field) const
|
||||||
{
|
{
|
||||||
if (!field || (field->Message() != NULL && field->Message() != this))
|
if (!field || (field->Message() != NULL && field->Message() != this))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
FieldHeader *fieldHeader = field->_Header();
|
FieldHeader* fieldHeader = field->_Header();
|
||||||
FieldHeader* lastField = _LastFieldHeader();
|
FieldHeader* lastField = _LastFieldHeader();
|
||||||
if (!lastField)
|
if (!lastField)
|
||||||
return B_NAME_NOT_FOUND;
|
return B_NAME_NOT_FOUND;
|
||||||
@@ -309,9 +325,8 @@ KMessage::IsEmpty() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// AddData
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddData(const char *name, type_code type, const void *data,
|
KMessage::AddData(const char* name, type_code type, const void* data,
|
||||||
int32 numBytes, bool isFixedSize)
|
int32 numBytes, bool isFixedSize)
|
||||||
{
|
{
|
||||||
if (!name || type == B_ANY_TYPE || !data || numBytes < 0)
|
if (!name || type == B_ANY_TYPE || !data || numBytes < 0)
|
||||||
@@ -331,9 +346,9 @@ KMessage::AddData(const char *name, type_code type, const void *data,
|
|||||||
return _AddFieldData(&field, data, numBytes, 1);
|
return _AddFieldData(&field, data, numBytes, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddArray
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::AddArray(const char *name, type_code type, const void *data,
|
KMessage::AddArray(const char* name, type_code type, const void* data,
|
||||||
int32 elementSize, int32 elementCount)
|
int32 elementSize, int32 elementCount)
|
||||||
{
|
{
|
||||||
if (!name || type == B_ANY_TYPE || !data || elementSize < 0
|
if (!name || type == B_ANY_TYPE || !data || elementSize < 0
|
||||||
@@ -355,7 +370,6 @@ KMessage::AddArray(const char *name, type_code type, const void *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetData
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SetData(const char* name, type_code type, const void* data,
|
KMessage::SetData(const char* name, type_code type, const void* data,
|
||||||
int32 numBytes)
|
int32 numBytes)
|
||||||
@@ -390,18 +404,17 @@ KMessage::SetData(const char* name, type_code type, const void* data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FindData
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindData(const char *name, type_code type, const void **data,
|
KMessage::FindData(const char* name, type_code type, const void** data,
|
||||||
int32 *numBytes) const
|
int32* numBytes) const
|
||||||
{
|
{
|
||||||
return FindData(name, type, 0, data, numBytes);
|
return FindData(name, type, 0, data, numBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindData
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::FindData(const char *name, type_code type, int32 index,
|
KMessage::FindData(const char* name, type_code type, int32 index,
|
||||||
const void **data, int32 *numBytes) const
|
const void** data, int32* numBytes) const
|
||||||
{
|
{
|
||||||
if (!name || !data || !numBytes)
|
if (!name || !data || !numBytes)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -409,7 +422,7 @@ KMessage::FindData(const char *name, type_code type, int32 index,
|
|||||||
status_t error = FindField(name, type, &field);
|
status_t error = FindField(name, type, &field);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
const void *foundData = field.ElementAt(index, numBytes);
|
const void* foundData = field.ElementAt(index, numBytes);
|
||||||
if (!foundData)
|
if (!foundData)
|
||||||
return B_BAD_INDEX;
|
return B_BAD_INDEX;
|
||||||
if (data)
|
if (data)
|
||||||
@@ -417,35 +430,35 @@ KMessage::FindData(const char *name, type_code type, int32 index,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sender
|
|
||||||
team_id
|
team_id
|
||||||
KMessage::Sender() const
|
KMessage::Sender() const
|
||||||
{
|
{
|
||||||
return _Header()->sender;
|
return _Header()->sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TargetToken
|
|
||||||
int32
|
int32
|
||||||
KMessage::TargetToken() const
|
KMessage::TargetToken() const
|
||||||
{
|
{
|
||||||
return _Header()->targetToken;
|
return _Header()->targetToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyPort
|
|
||||||
port_id
|
port_id
|
||||||
KMessage::ReplyPort() const
|
KMessage::ReplyPort() const
|
||||||
{
|
{
|
||||||
return _Header()->replyPort;
|
return _Header()->replyPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyToken
|
|
||||||
int32
|
int32
|
||||||
KMessage::ReplyToken() const
|
KMessage::ReplyToken() const
|
||||||
{
|
{
|
||||||
return _Header()->replyToken;
|
return _Header()->replyToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeliveryInfo
|
|
||||||
void
|
void
|
||||||
KMessage::SetDeliveryInfo(int32 targetToken, port_id replyPort,
|
KMessage::SetDeliveryInfo(int32 targetToken, port_id replyPort,
|
||||||
int32 replyToken, team_id senderTeam)
|
int32 replyToken, team_id senderTeam)
|
||||||
@@ -458,9 +471,10 @@ KMessage::SetDeliveryInfo(int32 targetToken, port_id replyPort,
|
|||||||
header->sender = senderTeam;
|
header->sender = senderTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef KMESSAGE_CONTAINER_ONLY
|
#ifndef KMESSAGE_CONTAINER_ONLY
|
||||||
|
|
||||||
// SendTo
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SendTo(port_id targetPort, int32 targetToken, port_id replyPort,
|
KMessage::SendTo(port_id targetPort, int32 targetToken, port_id replyPort,
|
||||||
int32 replyToken, bigtime_t timeout, team_id senderTeam)
|
int32 replyToken, bigtime_t timeout, team_id senderTeam)
|
||||||
@@ -485,7 +499,7 @@ KMessage::SendTo(port_id targetPort, int32 targetToken, port_id replyPort,
|
|||||||
B_RELATIVE_TIMEOUT, timeout);
|
B_RELATIVE_TIMEOUT, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTo
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SendTo(port_id targetPort, int32 targetToken, KMessage* reply,
|
KMessage::SendTo(port_id targetPort, int32 targetToken, KMessage* reply,
|
||||||
bigtime_t deliveryTimeout, bigtime_t replyTimeout, team_id senderTeam)
|
bigtime_t deliveryTimeout, bigtime_t replyTimeout, team_id senderTeam)
|
||||||
@@ -540,7 +554,7 @@ KMessage::SendTo(port_id targetPort, int32 targetToken, KMessage* reply,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendReply
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SendReply(KMessage* message, port_id replyPort, int32 replyToken,
|
KMessage::SendReply(KMessage* message, port_id replyPort, int32 replyToken,
|
||||||
bigtime_t timeout, team_id senderTeam)
|
bigtime_t timeout, team_id senderTeam)
|
||||||
@@ -551,7 +565,7 @@ KMessage::SendReply(KMessage* message, port_id replyPort, int32 replyToken,
|
|||||||
timeout, senderTeam);
|
timeout, senderTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendReply
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::SendReply(KMessage* message, KMessage* reply,
|
KMessage::SendReply(KMessage* message, KMessage* reply,
|
||||||
bigtime_t deliveryTimeout, bigtime_t replyTimeout, team_id senderTeam)
|
bigtime_t deliveryTimeout, bigtime_t replyTimeout, team_id senderTeam)
|
||||||
@@ -563,7 +577,6 @@ KMessage::SendReply(KMessage* message, KMessage* reply,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ReceiveFrom
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::ReceiveFrom(port_id fromPort, bigtime_t timeout,
|
KMessage::ReceiveFrom(port_id fromPort, bigtime_t timeout,
|
||||||
port_message_info* messageInfo)
|
port_message_info* messageInfo)
|
||||||
@@ -606,6 +619,7 @@ KMessage::ReceiveFrom(port_id fromPort, bigtime_t timeout,
|
|||||||
KMESSAGE_OWNS_BUFFER | KMESSAGE_INIT_FROM_BUFFER);
|
KMESSAGE_OWNS_BUFFER | KMESSAGE_INIT_FROM_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // !KMESSAGE_CONTAINER_ONLY
|
#endif // !KMESSAGE_CONTAINER_ONLY
|
||||||
|
|
||||||
|
|
||||||
@@ -671,38 +685,37 @@ KMessage::Dump(void (*printFunc)(const char*, ...)) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _Header
|
KMessage::Header*
|
||||||
KMessage::Header *
|
|
||||||
KMessage::_Header() const
|
KMessage::_Header() const
|
||||||
{
|
{
|
||||||
return (Header*)fBuffer;
|
return (Header*)fBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _BufferOffsetFor
|
|
||||||
int32
|
int32
|
||||||
KMessage::_BufferOffsetFor(const void* data) const
|
KMessage::_BufferOffsetFor(const void* data) const
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data)
|
||||||
return -1;
|
return -1;
|
||||||
return ((uint8*)data - (uint8*)fBuffer);
|
return (uint8*)data - (uint8*)fBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _FirstFieldHeader
|
|
||||||
KMessage::FieldHeader *
|
KMessage::FieldHeader*
|
||||||
KMessage::_FirstFieldHeader() const
|
KMessage::_FirstFieldHeader() const
|
||||||
{
|
{
|
||||||
return (FieldHeader*)_Align(fBuffer, sizeof(Header));
|
return (FieldHeader*)_Align(fBuffer, sizeof(Header));
|
||||||
}
|
}
|
||||||
|
|
||||||
// _LastFieldHeader
|
|
||||||
KMessage::FieldHeader *
|
KMessage::FieldHeader*
|
||||||
KMessage::_LastFieldHeader() const
|
KMessage::_LastFieldHeader() const
|
||||||
{
|
{
|
||||||
return _FieldHeaderForOffset(fLastFieldOffset);
|
return _FieldHeaderForOffset(fLastFieldOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _FieldHeaderForOffset
|
|
||||||
KMessage::FieldHeader *
|
KMessage::FieldHeader*
|
||||||
KMessage::_FieldHeaderForOffset(int32 offset) const
|
KMessage::_FieldHeaderForOffset(int32 offset) const
|
||||||
{
|
{
|
||||||
if (offset <= 0 || offset >= _Header()->size)
|
if (offset <= 0 || offset >= _Header()->size)
|
||||||
@@ -710,12 +723,12 @@ KMessage::_FieldHeaderForOffset(int32 offset) const
|
|||||||
return (FieldHeader*)((uint8*)fBuffer + offset);
|
return (FieldHeader*)((uint8*)fBuffer + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _AddField
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::_AddField(const char *name, type_code type, int32 elementSize,
|
KMessage::_AddField(const char* name, type_code type, int32 elementSize,
|
||||||
KMessageField *field)
|
KMessageField* field)
|
||||||
{
|
{
|
||||||
FieldHeader *fieldHeader;
|
FieldHeader* fieldHeader;
|
||||||
int32 alignedSize;
|
int32 alignedSize;
|
||||||
status_t error = _AllocateSpace(sizeof(FieldHeader) + strlen(name), true,
|
status_t error = _AllocateSpace(sizeof(FieldHeader) + strlen(name), true,
|
||||||
true, (void**)&fieldHeader, &alignedSize);
|
true, (void**)&fieldHeader, &alignedSize);
|
||||||
@@ -733,14 +746,14 @@ KMessage::_AddField(const char *name, type_code type, int32 elementSize,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _AddFieldData
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::_AddFieldData(KMessageField *field, const void *data,
|
KMessage::_AddFieldData(KMessageField* field, const void* data,
|
||||||
int32 elementSize, int32 elementCount)
|
int32 elementSize, int32 elementCount)
|
||||||
{
|
{
|
||||||
if (!field)
|
if (!field)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
FieldHeader *fieldHeader = field->_Header();
|
FieldHeader* fieldHeader = field->_Header();
|
||||||
FieldHeader* lastField = _LastFieldHeader();
|
FieldHeader* lastField = _LastFieldHeader();
|
||||||
if (!fieldHeader || fieldHeader != lastField || !data
|
if (!fieldHeader || fieldHeader != lastField || !data
|
||||||
|| elementSize < 0 || elementCount < 0) {
|
|| elementSize < 0 || elementCount < 0) {
|
||||||
@@ -752,7 +765,7 @@ KMessage::_AddFieldData(KMessageField *field, const void *data,
|
|||||||
if (fieldHeader->HasFixedElementSize()) {
|
if (fieldHeader->HasFixedElementSize()) {
|
||||||
if (elementSize != fieldHeader->elementSize)
|
if (elementSize != fieldHeader->elementSize)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
void *address;
|
void* address;
|
||||||
int32 alignedSize;
|
int32 alignedSize;
|
||||||
status_t error = _AllocateSpace(elementSize * elementCount,
|
status_t error = _AllocateSpace(elementSize * elementCount,
|
||||||
(fieldHeader->elementCount == 0), false, &address, &alignedSize);
|
(fieldHeader->elementCount == 0), false, &address, &alignedSize);
|
||||||
@@ -770,14 +783,14 @@ KMessage::_AddFieldData(KMessageField *field, const void *data,
|
|||||||
int32 valueHeaderSize = _Align(sizeof(FieldValueHeader));
|
int32 valueHeaderSize = _Align(sizeof(FieldValueHeader));
|
||||||
int32 entrySize = valueHeaderSize + elementSize;
|
int32 entrySize = valueHeaderSize + elementSize;
|
||||||
for (int32 i = 0; i < elementCount; i++) {
|
for (int32 i = 0; i < elementCount; i++) {
|
||||||
void *address;
|
void* address;
|
||||||
int32 alignedSize;
|
int32 alignedSize;
|
||||||
status_t error = _AllocateSpace(entrySize, true, false, &address,
|
status_t error = _AllocateSpace(entrySize, true, false, &address,
|
||||||
&alignedSize);
|
&alignedSize);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
fieldHeader = field->_Header(); // might have been relocated
|
fieldHeader = field->_Header(); // might have been relocated
|
||||||
FieldValueHeader *valueHeader = (FieldValueHeader*)address;
|
FieldValueHeader* valueHeader = (FieldValueHeader*)address;
|
||||||
valueHeader->size = elementSize;
|
valueHeader->size = elementSize;
|
||||||
memcpy(valueHeader->Data(), (const uint8*)data + i * elementSize,
|
memcpy(valueHeader->Data(), (const uint8*)data + i * elementSize,
|
||||||
elementSize);
|
elementSize);
|
||||||
@@ -788,13 +801,13 @@ KMessage::_AddFieldData(KMessageField *field, const void *data,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _InitFromBuffer
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::_InitFromBuffer(bool sizeFromBuffer)
|
KMessage::_InitFromBuffer(bool sizeFromBuffer)
|
||||||
{
|
{
|
||||||
if (!fBuffer || _Align(fBuffer) != fBuffer)
|
if (!fBuffer || _Align(fBuffer) != fBuffer)
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
Header *header = _Header();
|
Header* header = _Header();
|
||||||
|
|
||||||
if (sizeFromBuffer)
|
if (sizeFromBuffer)
|
||||||
fBufferCapacity = header->size;
|
fBufferCapacity = header->size;
|
||||||
@@ -809,8 +822,8 @@ KMessage::_InitFromBuffer(bool sizeFromBuffer)
|
|||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
|
|
||||||
// check the fields
|
// check the fields
|
||||||
FieldHeader *fieldHeader = NULL;
|
FieldHeader* fieldHeader = NULL;
|
||||||
uint8 *data = (uint8*)_FirstFieldHeader();
|
uint8* data = (uint8*)_FirstFieldHeader();
|
||||||
int32 remainingBytes = (uint8*)fBuffer + header->size - data;
|
int32 remainingBytes = (uint8*)fBuffer + header->size - data;
|
||||||
while (remainingBytes > 0) {
|
while (remainingBytes > 0) {
|
||||||
if (remainingBytes < (int)sizeof(FieldHeader))
|
if (remainingBytes < (int)sizeof(FieldHeader))
|
||||||
@@ -842,14 +855,14 @@ KMessage::_InitFromBuffer(bool sizeFromBuffer)
|
|||||||
fieldSize = (uint8*)fieldHeader->Data() + dataSize - data;
|
fieldSize = (uint8*)fieldHeader->Data() + dataSize - data;
|
||||||
} else {
|
} else {
|
||||||
// non-fixed element size
|
// non-fixed element size
|
||||||
FieldValueHeader *valueHeader
|
FieldValueHeader* valueHeader
|
||||||
= (FieldValueHeader *)fieldHeader->Data();
|
= (FieldValueHeader*)fieldHeader->Data();
|
||||||
for (int32 i = 0; i < fieldHeader->elementCount; i++) {
|
for (int32 i = 0; i < fieldHeader->elementCount; i++) {
|
||||||
remainingBytes = (uint8*)fBuffer + header->size
|
remainingBytes = (uint8*)fBuffer + header->size
|
||||||
- (uint8*)valueHeader;
|
- (uint8*)valueHeader;
|
||||||
if (remainingBytes < (int)sizeof(FieldValueHeader))
|
if (remainingBytes < (int)sizeof(FieldValueHeader))
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
uint8 *value = (uint8*)valueHeader->Data();
|
uint8* value = (uint8*)valueHeader->Data();
|
||||||
remainingBytes = (uint8*)fBuffer + header->size - (uint8*)value;
|
remainingBytes = (uint8*)fBuffer + header->size - (uint8*)value;
|
||||||
if (remainingBytes < valueHeader->size)
|
if (remainingBytes < valueHeader->size)
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
@@ -866,11 +879,11 @@ KMessage::_InitFromBuffer(bool sizeFromBuffer)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _InitBuffer
|
|
||||||
void
|
void
|
||||||
KMessage::_InitBuffer(uint32 what)
|
KMessage::_InitBuffer(uint32 what)
|
||||||
{
|
{
|
||||||
Header *header = _Header();
|
Header* header = _Header();
|
||||||
header->magic = kMessageHeaderMagic;
|
header->magic = kMessageHeaderMagic;
|
||||||
header->size = sizeof(Header);
|
header->size = sizeof(Header);
|
||||||
header->what = what;
|
header->what = what;
|
||||||
@@ -881,7 +894,7 @@ KMessage::_InitBuffer(uint32 what)
|
|||||||
fLastFieldOffset = 0;
|
fLastFieldOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _CheckBuffer
|
|
||||||
void
|
void
|
||||||
KMessage::_CheckBuffer()
|
KMessage::_CheckBuffer()
|
||||||
{
|
{
|
||||||
@@ -894,10 +907,10 @@ KMessage::_CheckBuffer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _AllocateSpace
|
|
||||||
status_t
|
status_t
|
||||||
KMessage::_AllocateSpace(int32 size, bool alignAddress, bool alignSize,
|
KMessage::_AllocateSpace(int32 size, bool alignAddress, bool alignSize,
|
||||||
void **address, int32 *alignedSize)
|
void** address, int32* alignedSize)
|
||||||
{
|
{
|
||||||
if (fBuffer != &fHeader && (fFlags & KMESSAGE_READ_ONLY))
|
if (fBuffer != &fHeader && (fFlags & KMESSAGE_READ_ONLY))
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
@@ -911,7 +924,7 @@ KMessage::_AllocateSpace(int32 size, bool alignAddress, bool alignSize,
|
|||||||
// reallocate if necessary
|
// reallocate if necessary
|
||||||
if (fBuffer == &fHeader) {
|
if (fBuffer == &fHeader) {
|
||||||
int32 newCapacity = _CapacityFor(newSize);
|
int32 newCapacity = _CapacityFor(newSize);
|
||||||
void *newBuffer = malloc(newCapacity);
|
void* newBuffer = malloc(newCapacity);
|
||||||
if (!newBuffer)
|
if (!newBuffer)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
fBuffer = newBuffer;
|
fBuffer = newBuffer;
|
||||||
@@ -924,7 +937,7 @@ KMessage::_AllocateSpace(int32 size, bool alignAddress, bool alignSize,
|
|||||||
if (!(fFlags & KMESSAGE_OWNS_BUFFER))
|
if (!(fFlags & KMESSAGE_OWNS_BUFFER))
|
||||||
return B_BUFFER_OVERFLOW;
|
return B_BUFFER_OVERFLOW;
|
||||||
int32 newCapacity = _CapacityFor(newSize);
|
int32 newCapacity = _CapacityFor(newSize);
|
||||||
void *newBuffer = realloc(fBuffer, newCapacity);
|
void* newBuffer = realloc(fBuffer, newCapacity);
|
||||||
if (!newBuffer)
|
if (!newBuffer)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
fBuffer = newBuffer;
|
fBuffer = newBuffer;
|
||||||
@@ -937,7 +950,7 @@ KMessage::_AllocateSpace(int32 size, bool alignAddress, bool alignSize,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _CapacityFor
|
|
||||||
int32
|
int32
|
||||||
KMessage::_CapacityFor(int32 size)
|
KMessage::_CapacityFor(int32 size)
|
||||||
{
|
{
|
||||||
@@ -946,16 +959,17 @@ KMessage::_CapacityFor(int32 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark - KMessageField
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
|
||||||
KMessageField::KMessageField()
|
KMessageField::KMessageField()
|
||||||
: fMessage(NULL),
|
:
|
||||||
fHeaderOffset(0)
|
fMessage(NULL),
|
||||||
|
fHeaderOffset(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset
|
|
||||||
void
|
void
|
||||||
KMessageField::Unset()
|
KMessageField::Unset()
|
||||||
{
|
{
|
||||||
@@ -963,48 +977,48 @@ KMessageField::Unset()
|
|||||||
fHeaderOffset = 0;
|
fHeaderOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message
|
|
||||||
KMessage *
|
KMessage*
|
||||||
KMessageField::Message() const
|
KMessageField::Message() const
|
||||||
{
|
{
|
||||||
return fMessage;
|
return fMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name
|
|
||||||
const char *
|
const char*
|
||||||
KMessageField::Name() const
|
KMessageField::Name() const
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
return (header ? header->name : NULL);
|
return header ? header->name : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeCode
|
|
||||||
type_code
|
type_code
|
||||||
KMessageField::TypeCode() const
|
KMessageField::TypeCode() const
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
return (header ? header->type : 0);
|
return header ? header->type : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasFixedElementSize
|
|
||||||
bool
|
bool
|
||||||
KMessageField::HasFixedElementSize() const
|
KMessageField::HasFixedElementSize() const
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
return (header ? header->HasFixedElementSize() : false);
|
return header ? header->HasFixedElementSize() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ElementSize
|
|
||||||
int32
|
int32
|
||||||
KMessageField::ElementSize() const
|
KMessageField::ElementSize() const
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
return (header ? header->elementSize : -1);
|
return header ? header->elementSize : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddElement
|
|
||||||
status_t
|
status_t
|
||||||
KMessageField::AddElement(const void *data, int32 size)
|
KMessageField::AddElement(const void* data, int32 size)
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
if (!header || !data)
|
if (!header || !data)
|
||||||
@@ -1017,9 +1031,9 @@ KMessageField::AddElement(const void *data, int32 size)
|
|||||||
return fMessage->_AddFieldData(this, data, size, 1);
|
return fMessage->_AddFieldData(this, data, size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddElements
|
|
||||||
status_t
|
status_t
|
||||||
KMessageField::AddElements(const void *data, int32 count, int32 elementSize)
|
KMessageField::AddElements(const void* data, int32 count, int32 elementSize)
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
if (!header || !data || count < 0)
|
if (!header || !data || count < 0)
|
||||||
@@ -1032,34 +1046,33 @@ KMessageField::AddElements(const void *data, int32 count, int32 elementSize)
|
|||||||
return fMessage->_AddFieldData(this, data, elementSize, count);
|
return fMessage->_AddFieldData(this, data, elementSize, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ElementAt
|
|
||||||
const void *
|
const void*
|
||||||
KMessageField::ElementAt(int32 index, int32 *size) const
|
KMessageField::ElementAt(int32 index, int32* size) const
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
return (header ? header->ElementAt(index, size) : NULL);
|
return header ? header->ElementAt(index, size) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountElements
|
|
||||||
int32
|
int32
|
||||||
KMessageField::CountElements() const
|
KMessageField::CountElements() const
|
||||||
{
|
{
|
||||||
KMessage::FieldHeader* header = _Header();
|
KMessage::FieldHeader* header = _Header();
|
||||||
return (header ? header->elementCount : 0);
|
return header ? header->elementCount : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTo
|
|
||||||
void
|
void
|
||||||
KMessageField::SetTo(KMessage *message, int32 headerOffset)
|
KMessageField::SetTo(KMessage* message, int32 headerOffset)
|
||||||
{
|
{
|
||||||
fMessage = message;
|
fMessage = message;
|
||||||
fHeaderOffset = headerOffset;
|
fHeaderOffset = headerOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _GetHeader
|
|
||||||
KMessage::FieldHeader*
|
KMessage::FieldHeader*
|
||||||
KMessageField::_Header() const
|
KMessageField::_Header() const
|
||||||
{
|
{
|
||||||
return (fMessage ? fMessage->_FieldHeaderForOffset(fHeaderOffset) : NULL);
|
return fMessage ? fMessage->_FieldHeaderForOffset(fHeaderOffset) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user