diff --git a/docs/develop/app/bmessage.txt b/docs/develop/app/bmessage.txt new file mode 100644 index 0000000000..5f19220346 --- /dev/null +++ b/docs/develop/app/bmessage.txt @@ -0,0 +1,43 @@ +Data Bytes Meaning + +1BOF(ascii) 4 version +?? 4 ?? +0x76 4 flattened size +DPUQ 4 what(B_QUERY_UPDATE) +?? 5 ?? + +0F 1 fixed chunk size? +GNOL 4 type +04 1 chunk size +06 1 name length +opcode 6 name +1 4 data(B_ENTRY_CREATED) + +0F 1 fixed chunk size? +GNOL 4 type +04 1 chunk size +06 1 name length +device 6 name +4 4 data + +0F 1 fixed chunk size? +GNLL 4 type +08 1 chunk size +09 1 name length +directory 9 name +524992 8 data + +0F 1 fixed chunk size? +GNLL 4 type +08 1 chunk size +04 1 name length +node 4 name +524295 8 data + +0B 1 variable chunk size? +RTSC 4 type +08 1 chunk size +04 1 name length +name 4 name +08 1 chunk size? + 8 padded string? diff --git a/headers/os/app/Message.h b/headers/os/app/Message.h new file mode 100644 index 0000000000..6d2084df4b --- /dev/null +++ b/headers/os/app/Message.h @@ -0,0 +1,455 @@ +//------------------------------------------------------------------------------ +// 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: Message.h +// Author(s): Erik Jaesler (erik@cgsoftware.com) +// Description: BMessage class creates objects that store data and that +// can be processed in a message loop. BMessage objects +// are also used as data containers by the archiving and +// the scripting mechanisms. +//------------------------------------------------------------------------------ + +#ifndef _MESSAGE_H +#define _MESSAGE_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- +#include +#include +#include +#include +#include + +#include /* For convenience */ +#include /* For convenience */ + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + + + +class BBlockCache; +class BMessenger; +class BHandler; +class BString; + +// Private or reserved --------------------------------------------------------- +extern "C" void _msg_cache_cleanup_(); +extern "C" int _init_message_(); +extern "C" int _delete_message_(); +//------------------------------------------------------------------------------ + + +// Name lengths and Scripting specifiers --------------------------------------- +#define B_FIELD_NAME_LENGTH 255 +#define B_PROPERTY_NAME_LENGTH 255 + +enum +{ + B_NO_SPECIFIER = 0, + B_DIRECT_SPECIFIER = 1, + B_INDEX_SPECIFIER, + B_REVERSE_INDEX_SPECIFIER, + B_RANGE_SPECIFIER, + B_REVERSE_RANGE_SPECIFIER, + B_NAME_SPECIFIER, + B_ID_SPECIFIER, + + B_SPECIFIERS_END = 128 + // app-defined specifiers start at B_SPECIFIERS_END+1 +}; + + +// BMessage class -------------------------------------------------------------- +class BMessage +{ +public: + uint32 what; + + BMessage(); + BMessage(uint32 what); + BMessage(const BMessage &a_message); +virtual ~BMessage(); + + BMessage &operator=(const BMessage &msg); + +// Statistics and misc info + status_t GetInfo(type_code typeRequested, int32 which, char **name, + type_code *typeReturned, int32 *count = NULL) const; + + status_t GetInfo(const char *name, type_code *type, int32 *c = 0) const; + status_t GetInfo(const char *name, type_code *type, bool *fixed_size) const; + + int32 CountNames(type_code type) const; + bool IsEmpty() const; + bool IsSystem() const; + bool IsReply() const; + void PrintToStream() const; + + status_t Rename(const char *old_entry, const char *new_entry); + +// Delivery info + bool WasDelivered() const; + bool IsSourceWaiting() const; + bool IsSourceRemote() const; + BMessenger ReturnAddress() const; + const BMessage *Previous() const; + bool WasDropped() const; + BPoint DropPoint(BPoint *offset = NULL) const; + +// Replying + status_t SendReply(uint32 command, BHandler *reply_to = NULL); + status_t SendReply(BMessage *the_reply, BHandler *reply_to = NULL, + bigtime_t timeout = B_INFINITE_TIMEOUT); + status_t SendReply(BMessage *the_reply, BMessenger reply_to, + bigtime_t timeout = B_INFINITE_TIMEOUT); + + status_t SendReply(uint32 command, BMessage *reply_to_reply); + status_t SendReply(BMessage *the_reply, BMessage *reply_to_reply, + bigtime_t send_timeout = B_INFINITE_TIMEOUT, + bigtime_t reply_timeout = B_INFINITE_TIMEOUT); + +// Flattening data + ssize_t FlattenedSize() const; + status_t Flatten(char *buffer, ssize_t size) const; + status_t Flatten(BDataIO *stream, ssize_t *size = NULL) const; + status_t Unflatten(const char *flat_buffer); + status_t Unflatten(BDataIO *stream); + + +// Specifiers (scripting) + status_t AddSpecifier(const char *property); + status_t AddSpecifier(const char *property, int32 index); + status_t AddSpecifier(const char *property, int32 index, int32 range); + status_t AddSpecifier(const char *property, const char *name); + status_t AddSpecifier(const BMessage *specifier); + + status_t SetCurrentSpecifier(int32 index); + status_t GetCurrentSpecifier(int32 *index, BMessage *specifier = NULL, + int32 *form = NULL, const char **property = NULL) const; + bool HasSpecifiers() const; + status_t PopSpecifier(); + +// Adding data + status_t AddRect(const char *name, BRect a_rect); + status_t AddPoint(const char *name, BPoint a_point); + status_t AddString(const char *name, const char *a_string); + status_t AddString(const char *name, const BString& a_string); + status_t AddInt8(const char *name, int8 val); + status_t AddInt16(const char *name, int16 val); + status_t AddInt32(const char *name, int32 val); + status_t AddInt64(const char *name, int64 val); + status_t AddBool(const char *name, bool a_boolean); + status_t AddFloat(const char *name, float a_float); + status_t AddDouble(const char *name, double a_double); + status_t AddPointer(const char *name, const void *ptr); + status_t AddMessenger(const char *name, BMessenger messenger); + status_t AddRef(const char *name, const entry_ref *ref); + status_t AddMessage(const char *name, const BMessage *msg); + status_t AddFlat(const char *name, BFlattenable *obj, int32 count = 1); + status_t AddData(const char *name, type_code type, const void *data, + ssize_t numBytes, bool is_fixed_size = true, int32 count = 1); + +// Removing data + status_t RemoveData(const char *name, int32 index = 0); + status_t RemoveName(const char *name); + status_t MakeEmpty(); + +// Finding data + status_t FindRect(const char *name, BRect *rect) const; + status_t FindRect(const char *name, int32 index, BRect *rect) const; + status_t FindPoint(const char *name, BPoint *pt) const; + status_t FindPoint(const char *name, int32 index, BPoint *pt) const; + status_t FindString(const char *name, const char **str) const; + status_t FindString(const char *name, int32 index, const char **str) const; + status_t FindString(const char *name, BString *str) const; + status_t FindString(const char *name, int32 index, BString *str) const; + status_t FindInt8(const char *name, int8 *value) const; + status_t FindInt8(const char *name, int32 index, int8 *val) const; + status_t FindInt16(const char *name, int16 *value) const; + status_t FindInt16(const char *name, int32 index, int16 *val) const; + status_t FindInt32(const char *name, int32 *value) const; + status_t FindInt32(const char *name, int32 index, int32 *val) const; + status_t FindInt64(const char *name, int64 *value) const; + status_t FindInt64(const char *name, int32 index, int64 *val) 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 *f) const; + status_t FindFloat(const char *name, int32 index, float *f) const; + status_t FindDouble(const char *name, double *d) const; + status_t FindDouble(const char *name, int32 index, double *d) const; + status_t FindPointer(const char *name, void **ptr) const; + status_t FindPointer(const char *name, int32 index, void **ptr) const; + status_t FindMessenger(const char *name, BMessenger *m) const; + status_t FindMessenger(const char *name, int32 index, BMessenger *m) const; + status_t FindRef(const char *name, entry_ref *ref) const; + status_t FindRef(const char *name, int32 index, entry_ref *ref) const; + status_t FindMessage(const char *name, BMessage *msg) const; + status_t FindMessage(const char *name, int32 index, BMessage *msg) const; + status_t FindFlat(const char *name, BFlattenable *obj) const; + status_t FindFlat(const char *name, int32 index, BFlattenable *obj) const; + status_t FindData(const char *name, type_code type, + const void **data, ssize_t *numBytes) const; + status_t FindData(const char *name, type_code type, int32 index, + const void **data, ssize_t *numBytes) const; + +// Replacing data + status_t ReplaceRect(const char *name, BRect a_rect); + status_t ReplaceRect(const char *name, int32 index, BRect a_rect); + status_t ReplacePoint(const char *name, BPoint a_point); + status_t ReplacePoint(const char *name, int32 index, BPoint a_point); + status_t ReplaceString(const char *name, const char *string); + status_t ReplaceString(const char *name, int32 index, const char *string); + status_t ReplaceString(const char *name, const BString& string); + status_t ReplaceString(const char *name, int32 index, const BString& string); + status_t ReplaceInt8(const char *name, int8 val); + status_t ReplaceInt8(const char *name, int32 index, int8 val); + status_t ReplaceInt16(const char *name, int16 val); + status_t ReplaceInt16(const char *name, int32 index, int16 val); + status_t ReplaceInt32(const char *name, int32 val); + status_t ReplaceInt32(const char *name, int32 index, int32 val); + status_t ReplaceInt64(const char *name, int64 val); + status_t ReplaceInt64(const char *name, int32 index, int64 val); + status_t ReplaceBool(const char *name, bool a_bool); + status_t ReplaceBool(const char *name, int32 index, bool a_bool); + status_t ReplaceFloat(const char *name, float a_float); + status_t ReplaceFloat(const char *name, int32 index, float a_float); + status_t ReplaceDouble(const char *name, double a_double); + status_t ReplaceDouble(const char *name, int32 index, double a_double); + status_t ReplacePointer(const char *name, const void *ptr); + status_t ReplacePointer(const char *name,int32 index,const void *ptr); + status_t ReplaceMessenger(const char *name, BMessenger messenger); + status_t ReplaceMessenger(const char *name, int32 index, BMessenger msngr); + status_t ReplaceRef( const char *name,const entry_ref *ref); + status_t ReplaceRef( const char *name, int32 index, const entry_ref *ref); + status_t ReplaceMessage(const char *name, const BMessage *msg); + status_t ReplaceMessage(const char *name, int32 index, const BMessage *msg); + status_t ReplaceFlat(const char *name, BFlattenable *obj); + status_t ReplaceFlat(const char *name, int32 index, BFlattenable *obj); + status_t ReplaceData(const char *name, type_code type, + const void *data, ssize_t data_size); + status_t ReplaceData(const char *name, type_code type, int32 index, + const void *data, ssize_t data_size); + + void *operator new(size_t size); + void operator delete(void *ptr, size_t size); + +// Private, reserved, or obsolete ---------------------------------------------- + bool HasRect(const char *, int32 n = 0) const; + 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 HasInt16(const char *, int32 n = 0) const; + bool HasInt32(const char *, int32 n = 0) const; + bool HasInt64(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; + bool HasPointer(const char *, int32 n = 0) const; + bool HasMessenger(const char *, int32 n = 0) const; + bool HasRef(const char *, int32 n = 0) const; + bool HasMessage(const char *, int32 n = 0) const; + bool HasFlat(const char *, const BFlattenable *) const; + bool HasFlat(const char *,int32 ,const BFlattenable *) const; + bool HasData(const char *, type_code , int32 n = 0) const; + BRect FindRect(const char *, int32 n = 0) const; + BPoint FindPoint(const char *, int32 n = 0) const; + const char *FindString(const char *, int32 n = 0) const; + int8 FindInt8(const char *, int32 n = 0) const; + int16 FindInt16(const char *, int32 n = 0) const; + int32 FindInt32(const char *, int32 n = 0) const; + int64 FindInt64(const char *, int32 n = 0) const; + bool FindBool(const char *, int32 n = 0) const; + float FindFloat(const char *, int32 n = 0) const; + double FindDouble(const char *, int32 n = 0) const; + +private: + +friend class BMessageQueue; +friend class BMessenger; +friend class BApplication; + +friend void _msg_cache_cleanup_(); +friend BMessage *_reconstruct_msg_(uint32,uint32,uint32); +friend inline void _set_message_target_(BMessage *, int32, bool); +friend inline void _set_message_reply_(BMessage *, BMessenger); +friend inline int32 _get_message_target_(BMessage *); +friend inline bool _use_preferred_target_(BMessage *); + + // deprecated + BMessage(BMessage *a_message); + +virtual void _ReservedMessage1(); +virtual void _ReservedMessage2(); +virtual void _ReservedMessage3(); + + void init_data(); + int32 flatten_hdr(uchar *result, + ssize_t size, + uchar flags) const; + status_t real_flatten(char *result, + ssize_t size, + uchar flags) const; + status_t real_flatten(BDataIO *stream, + ssize_t size, + uchar flags) const; + char *stack_flatten(char *stack_ptr, + ssize_t stack_size, + bool incl_reply, + ssize_t *size = NULL) const; + ssize_t calc_size(uchar flags) const; + ssize_t calc_hdr_size(uchar flags) const; + ssize_t min_hdr_size() const; + status_t nfind_data( const char *name, + type_code type, + int32 index, + const void **data, + ssize_t *data_size) const; + status_t copy_data( const char *name, + type_code type, + int32 index, + void *data, + ssize_t data_size) const; + + status_t _send_(port_id port, + int32 token, + bool preferred, + bigtime_t timeout, + bool reply_required, + BMessenger &reply_to) const; + status_t send_message(port_id port, + team_id port_owner, + int32 token, + bool preferred, + BMessage *reply, + bigtime_t send_timeout, + bigtime_t reply_timeout) const; + + enum { sNumReplyPorts = 3 }; +static port_id sReplyPorts[sNumReplyPorts]; +static long sReplyPortInUse[sNumReplyPorts]; +static int32 sGetCachedReplyPort(); + +friend int _init_message_(); +friend int _delete_message_(); +static BBlockCache *sMsgCache; + + struct dyn_array { + int32 fLogicalBytes; + int32 fPhysicalBytes; + int32 fChunkSize; + int32 fCount; + int32 fEntryHdrSize; + }; + + struct entry_hdr : public dyn_array { + entry_hdr *fNext; + uint32 fType; + uchar fNameLength; + char fName[1]; + }; + + struct var_chunk { + int32 fDataSize; + char fData[1]; + }; + + void *da_create(int32 header_size, int32 chunk_size, + bool fixed, int32 nchunks); + status_t da_add_data(dyn_array **da, const void *data, int32 size); + void *da_find_data(dyn_array *da, int32 index, + int32 *size = NULL) const; + status_t da_delete_data(dyn_array **pda, int32 index); + status_t da_replace_data(dyn_array **pda, int32 index, + const void *data, int32 dsize); + int32 da_calc_size(int32 hdr_size, int32 chunksize, + bool is_fixed, int32 nchunks) const; + void *da_grow(dyn_array **pda, int32 increase); + void da_dump(dyn_array *da); + + int32 da_chunk_hdr_size() const + { return sizeof(int32); } + int32 da_chunk_size(var_chunk *v) const + { return (v->fDataSize + da_chunk_hdr_size() + 7) & ~7; } + var_chunk *da_first_chunk(dyn_array *da) const + { return (var_chunk *) da_start_of_data(da); } + var_chunk *da_next_chunk(var_chunk *v) const + { return (var_chunk *) (((char*) v) + da_chunk_size(v)); } + var_chunk *da_chunk_ptr(void *data) const + { return (var_chunk*) (((char *) data) - da_chunk_hdr_size()); } + + int32 da_pad_8(int32 val) const + { return (val + 7) & ~7; } + int32 da_total_size(dyn_array *da) const + { return (int32)sizeof(dyn_array) + da->fEntryHdrSize + + da->fPhysicalBytes; } + char *da_start_of_data(dyn_array *da) const + { return ((char *) da) + (sizeof(dyn_array) + + da->fEntryHdrSize); } + bool da_is_mini_data(dyn_array *da) const + { return ((da->fLogicalBytes <= (int32) UCHAR_MAX) && + (da->fCount <= (int32) UCHAR_MAX));} + void da_swap_var_sized(dyn_array *da); + void da_swap_fixed_sized(dyn_array *da); + + BMessage *link; + int32 fTarget; + BMessage *fOriginal; + uint32 fChangeCount; + int32 fCurSpecifier; + uint32 fPtrOffset; + uint32 _reserved[3]; + + BMessage::entry_hdr *fEntries; + + struct { + port_id port; + int32 target; + team_id team; + bool preferred; + } fReplyTo; + + bool fPreferred; + bool fReplyRequired; + bool fReplyDone; + bool fIsReply; + bool fWasDelivered; + bool fReadOnly; + bool fHasSpecifiers; +}; + +//------------------------------------------------------------------------------ + +#endif // _MESSAGE_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp new file mode 100644 index 0000000000..46e44caac8 --- /dev/null +++ b/src/kits/app/Message.cpp @@ -0,0 +1,1499 @@ + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- +#include +#include +#include + +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- +void _msg_cache_cleanup_() +{ +} +//------------------------------------------------------------------------------ +BMessage *_reconstruct_msg_(uint32,uint32,uint32) +{ + return NULL; +} +//------------------------------------------------------------------------------ +void _set_message_target_(BMessage *msg, int32 target, bool preferred) +{ + if (preferred) + { + msg->fTarget = -1; + msg->fPreferred = true; + } + else + { + msg->fTarget = target; + msg->fPreferred = false; + } +} +//------------------------------------------------------------------------------ +void _set_message_reply_(BMessage *msg, BMessenger messenger) +{ + msg->fReplyTo.port = messenger.fPort; + msg->fReplyTo.target = messenger.fHandlerToken; + msg->fReplyTo.team = messenger.fTeam; + msg->fReplyTo.preferred = messenger.fPreferredTarget; + msg->fReplyRequired = true; +} +//------------------------------------------------------------------------------ +int32 _get_message_target_(BMessage *msg) +{ + if (msg->fPreferred) + return -1; + else + return msg->fTarget; +} +//------------------------------------------------------------------------------ +bool _use_preferred_target_(BMessage *msg) +{ + return msg->fPreferred; +} +//------------------------------------------------------------------------------ +BMessage::BMessage(uint32 command) +{ + init_data(); + + what = command; +} +//------------------------------------------------------------------------------ +BMessage::BMessage(const BMessage &message) +{ + *this = message; +} +//------------------------------------------------------------------------------ +BMessage::BMessage() +{ + init_data(); +} +//------------------------------------------------------------------------------ +BMessage::~BMessage () +{ +} +//------------------------------------------------------------------------------ +BMessage &BMessage::operator=(const BMessage &message) +{ + what = message.what; + + link = message.link; + fTarget = message.fTarget; + fOriginal = message.fOriginal; + fChangeCount = message.fChangeCount; + fCurSpecifier = message.fCurSpecifier; + fPtrOffset = message.fPtrOffset; + + fEntries = NULL; + + entry_hdr *src_entry; + + for ( src_entry = message.fEntries; src_entry != NULL; src_entry = src_entry->fNext ) + { + entry_hdr* new_entry = (entry_hdr*)new char[da_total_logical_size ( src_entry )]; + + if ( new_entry != NULL ) + { + memcpy ( new_entry, src_entry, da_total_logical_size ( src_entry ) ); + + new_entry->fNext = fEntries; + new_entry->fPhysicalBytes = src_entry->fLogicalBytes; + + fEntries = new_entry; + } + } + + fReplyTo.port = message.fReplyTo.port; + fReplyTo.target = message.fReplyTo.target; + fReplyTo.team = message.fReplyTo.team; + fReplyTo.preferred = message.fReplyTo.preferred; + + fPreferred = message.fPreferred; + fReplyRequired = message.fReplyRequired; + fReplyDone = message.fReplyDone; + fIsReply = message.fIsReply; + fWasDelivered = message.fWasDelivered; + fReadOnly = message.fReadOnly; + fHasSpecifiers = message.fHasSpecifiers; + + return *this; +} +//------------------------------------------------------------------------------ +status_t BMessage::GetInfo(const char *name, type_code *typeFound, + int32 *countFound) const +{ + for(entry_hdr *entry = fEntries; entry != NULL; entry = entry->fNext) + { + if (entry->fNameLength == strlen(name) && + strncmp(entry->fName, name, entry->fNameLength) == 0) + { + if (typeFound) + *typeFound = entry->fType; + + if (countFound) + *countFound = entry->fCount; + + return B_OK; + } + } + + return B_NAME_NOT_FOUND; +} +//------------------------------------------------------------------------------ +status_t BMessage::GetInfo(const char *name, type_code *typeFound, bool *fixedSize) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::GetInfo(type_code type, int32 index, char **nameFound, type_code *typeFound, + int32 *countFound) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +int32 BMessage::CountNames(type_code type) const +{ + return -1; +} +//------------------------------------------------------------------------------ +//bool BMessage::IsEmpty () const; +//------------------------------------------------------------------------------ +//bool BMessage::IsSystem () const; +//------------------------------------------------------------------------------ +bool BMessage::IsReply() const +{ + return fIsReply; +} +//------------------------------------------------------------------------------ +void BMessage::PrintToStream() const +{ + char name[256]; + + for (entry_hdr *entry = fEntries; entry != NULL; entry = entry->fNext) + { + memcpy(name, entry->fName, entry->fNameLength); + name[entry->fNameLength] = 0; + + printf("#entry %s, type = %c%c%c%c, count = %d\n", name, + (entry->fType & 0xFF000000) >> 24, (entry->fType & 0x00FF0000) >> 16, + (entry->fType & 0x0000FF00) >> 8, entry->fType & 0x000000FF, entry->fCount); + + ((BMessage*)this)->da_dump((dyn_array*)entry); + } +} +//------------------------------------------------------------------------------ +//status_t BMessage::Rename(const char *old_entry, const char *new_entry); +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +bool BMessage::WasDelivered () const +{ + return fWasDelivered; +} +//------------------------------------------------------------------------------ +//bool BMessage::IsSourceWaiting() const; +//------------------------------------------------------------------------------ +//bool BMessage::IsSourceRemote() const; +//------------------------------------------------------------------------------ +BMessenger BMessage::ReturnAddress() const +{ + return BMessenger(fReplyTo.team, fReplyTo.port, fReplyTo.target, + fReplyTo.preferred); +} +//------------------------------------------------------------------------------ +const BMessage *BMessage::Previous () const +{ + return fOriginal; +} +//------------------------------------------------------------------------------ +bool BMessage::WasDropped () const +{ + if (GetInfo("_drop_point_", NULL, (int32*)NULL) == B_OK) + return true; + else + return false; +} +//------------------------------------------------------------------------------ +BPoint BMessage::DropPoint(BPoint *offset) const +{ + BPoint point; + + FindPoint("_drop_point_", &point); + + if (offset) + FindPoint("_drop_offset_", offset); + + return point; +} +//------------------------------------------------------------------------------ +status_t BMessage::SendReply(uint32 command, BHandler *reply_to) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::SendReply(BMessage *the_reply, BHandler *reply_to, + bigtime_t timeout) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::SendReply(BMessage *the_reply, BMessenger reply_to, + bigtime_t timeout) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::SendReply(uint32 command, BMessage *reply_to_reply) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::SendReply(BMessage *the_reply, BMessage *reply_to_reply, + bigtime_t send_timeout, + bigtime_t reply_timeout) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +size_t BMessage::FlattenedSize() const +{ + size_t size = 7 * sizeof(int32); + + for (entry_hdr *entry = fEntries; entry != NULL; entry = entry->fNext) + size += da_total_logical_size(entry); + + return size; +} +//------------------------------------------------------------------------------ +status_t BMessage::Flatten(char *address, size_t numBytes) const +{ + if (numBytes != NULL && numBytes < FlattenedSize()) + return B_NO_MEMORY; + + int position = 7 * sizeof(int32); + + ((int32*)address)[1] = what; + ((int32*)address)[2] = fCurSpecifier; + ((int32*)address)[3] = fHasSpecifiers; + ((int32*)address)[4] = 0; + ((int32*)address)[5] = 0; + ((int32*)address)[6] = 0; + + for (entry_hdr *entry = fEntries; entry != NULL; entry = entry->fNext) + { + memcpy(address + position, entry, da_total_logical_size(entry)); + + position += da_total_logical_size(entry); + } + + ((size_t*)address)[0] = position; + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::Flatten(BDataIO *object, size_t *numBytes) const +{ + if (numBytes != NULL && *numBytes < FlattenedSize()) + return B_NO_MEMORY; + + int32 size = FlattenedSize(); + char *buffer = new char[size]; + + Flatten(buffer, size); + + object->Write(buffer, size); + + delete buffer; + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::Unflatten(const char *address) +{ + size_t size; + + MakeEmpty(); + + size = ((size_t*)address)[0]; + what = ((int32*)address)[1]; + fCurSpecifier = ((int32*)address)[2]; + fHasSpecifiers = ((int32*)address)[3]; + + size_t position = 7 * sizeof(int32); + + while (position < size) + { + entry_hdr* src_entry = (entry_hdr*)&address[position]; + entry_hdr* new_entry = (entry_hdr*)new char[da_total_logical_size ( src_entry )]; + + if (new_entry != NULL) + { + memcpy(new_entry, src_entry, da_total_logical_size(src_entry)); + + new_entry->fNext = fEntries; + new_entry->fPhysicalBytes = src_entry->fLogicalBytes; + position += da_total_logical_size(src_entry); + + fEntries = new_entry; + } + else + return B_NO_MEMORY; + } + + if (position != size) + { + MakeEmpty(); + return B_BAD_VALUE; + } + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::Unflatten(BDataIO *object) +{ + size_t size; + + object->Read(&size, sizeof(int32)); + + char *buffer = new char[size]; + + *(int32*)buffer = size; + + object->Read(buffer + sizeof(int32), size - sizeof(int32)); + + status_t status = Unflatten(buffer); + + delete[] buffer; + + return status; +} +//------------------------------------------------------------------------------ +status_t BMessage::AddSpecifier(const char *property) +{ + BMessage message(B_DIRECT_SPECIFIER); + message.AddString("property", property); + + fCurSpecifier ++; + fHasSpecifiers = true; + + return AddMessage("specifiers", &message); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddSpecifier(const char *property, int32 index) +{ + BMessage message(B_INDEX_SPECIFIER); + message.AddString("property", property); + message.AddInt32("index", index); + + fCurSpecifier++; + fHasSpecifiers = true; + + return AddMessage("specifiers", &message); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddSpecifier(const char *property, int32 index, int32 range) +{ + BMessage message(B_RANGE_SPECIFIER); + message.AddString("property", property); + message.AddInt32("index", index); + message.AddInt32("range", range); + + fCurSpecifier ++; + fHasSpecifiers = true; + + return AddMessage("specifiers", &message); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddSpecifier(const char *property, const char *name) +{ + BMessage message(B_NAME_SPECIFIER); + message.AddString("property", property); + message.AddString("name", name); + + fCurSpecifier ++; + fHasSpecifiers = true; + + return AddMessage("specifiers", &message); +} +//------------------------------------------------------------------------------ +//status_t BMessage::AddSpecifier(const BMessage *message); +//------------------------------------------------------------------------------ +status_t SetCurrentSpecifier(int32 index) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::GetCurrentSpecifier(int32 *index, BMessage *specifier, + int32 *what, const char **property) const +{ + if (fCurSpecifier == -1) + return B_BAD_SCRIPT_SYNTAX; + + if (index) + *index = fCurSpecifier; + + if (specifier) + { + FindMessage("specifiers", fCurSpecifier, specifier); + + if (what) + *what = specifier->what; + + if (property) + specifier->FindString("property", property); + } + + return B_OK; +} +//------------------------------------------------------------------------------ +bool BMessage::HasSpecifiers() const +{ + return fHasSpecifiers; +} +//------------------------------------------------------------------------------ +status_t BMessage::PopSpecifier() +{ + if (fCurSpecifier) + { + fCurSpecifier--; + return B_OK; + } + else + return B_BAD_VALUE; +} +//------------------------------------------------------------------------------ +status_t BMessage::AddRect(const char *name, BRect rect) +{ + return AddData(name, B_RECT_TYPE, &rect, sizeof(BRect), true); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddPoint(const char *name, BPoint point) +{ + return AddData(name, B_POINT_TYPE, &point, sizeof(BPoint), true); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddString(const char *name, const char *string) +{ + return AddData(name, B_STRING_TYPE, string, strlen(string) + 1, false); +} +//------------------------------------------------------------------------------ +//status_t BMessage::AddString(const char *name, const CString &string); +//------------------------------------------------------------------------------ +status_t BMessage::AddInt8(const char *name, int8 anInt8) +{ + return AddData(name, B_INT8_TYPE, &anInt8, sizeof(int8)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddInt16(const char *name, int16 anInt16) +{ + return AddData(name, B_INT16_TYPE, &anInt16, sizeof(int16)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddInt32(const char *name, int32 anInt32) +{ + return AddData(name, B_INT32_TYPE, &anInt32, sizeof(int32)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddInt64(const char *name, int64 anInt64) +{ + return AddData(name, B_INT64_TYPE, &anInt64, sizeof(int64)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddBool(const char *name, bool aBool) +{ + return AddData(name, B_BOOL_TYPE, &aBool, sizeof(bool)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddFloat ( const char *name, float aFloat) +{ + return AddData(name, B_FLOAT_TYPE, &aFloat, sizeof(float)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddDouble ( const char *name, double aDouble) +{ + return AddData(name, B_DOUBLE_TYPE, &aDouble, sizeof(double)); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddPointer(const char *name, const void *pointer) +{ + return AddData(name, B_POINTER_TYPE, &pointer, sizeof(void*), true); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddMessenger(const char *name, BMessenger messenger) +{ + return B_OK; +} +//------------------------------------------------------------------------------ +//status_t BMessage::AddRef(const char *name, const entry_ref *ref); +//------------------------------------------------------------------------------ +status_t BMessage::AddMessage(const char *name, const BMessage *message) +{ + int32 size = message->FlattenedSize(); + char *buffer = new char[size]; + + message->Flatten (buffer, size); + + return AddData(name, B_MESSAGE_TYPE, buffer, size, false); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddFlat(const char *name, BFlattenable *object, + int32 numItems) +{ + int32 size = object->FlattenedSize (); + char *buffer = new char[size]; + + object->Flatten(buffer, size); + + return AddData(name, object->TypeCode(), buffer, size, + object->IsFixedSize(), numItems); +} +//------------------------------------------------------------------------------ +status_t BMessage::AddData(const char *name, type_code type, const void *data, + size_t numBytes, bool fixedSize, int32 numItems) +{ + entry_hdr *entry = entry_find(name, type); + + if (entry == NULL) + { + if ( strlen(name) > 255) + return B_BAD_VALUE; + + entry = (entry_hdr*)da_create(sizeof(entry_hdr) - sizeof(dyn_array) + + strlen(name), numBytes, fixedSize, numItems); + + entry->fNext = fEntries; + entry->fType = type; + entry->fNameLength = strlen(name); + memcpy(entry->fName, name, entry->fNameLength); + + fEntries = entry; + } + + return da_add_data((dyn_array**)&entry, data, numBytes); +} +//------------------------------------------------------------------------------ +//status_t BMessage::RemoveData(const char *name, int32 index); +//status_t BMessage::RemoveName(const char *name); +//------------------------------------------------------------------------------ +status_t BMessage::MakeEmpty() +{ + entry_hdr *entry; + + while(entry = fEntries) + { + fEntries = entry->fNext; + delete entry; + } + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindRect(const char *name, BRect *rect) const +{ + entry_hdr *entry = entry_find(name, B_RECT_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *rect = *(BRect*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindRect(const char *name, int32 index, BRect *rect) const +{ + entry_hdr *entry = entry_find(name, B_RECT_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + BRect* data = (BRect*)da_first_chunk(entry); + *rect = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindPoint(const char *name, BPoint *point) const +{ + entry_hdr *entry = entry_find(name, B_POINT_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *point = *(BPoint*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindPoint(const char *name, int32 index, BPoint *point) const +{ + entry_hdr *entry = entry_find(name, B_POINT_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + BPoint* data = (BPoint*)da_first_chunk(entry); + *point = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindString(const char *name, int32 index, + const char **string) const +{ + return FindData(name, B_STRING_TYPE, index, (const void**)string, NULL); +} +//------------------------------------------------------------------------------ +status_t BMessage::FindString(const char *name, const char **string) const +{ + return FindData(name, B_STRING_TYPE, (const void**)string, NULL); +} +//------------------------------------------------------------------------------ +//status_t BMessage::FindString ( const char *name, int32 index, +//CString *string ) const; +//------------------------------------------------------------------------------ +//status_t BMessage::FindString ( const char *name, CString *string ) const; +//------------------------------------------------------------------------------ +status_t BMessage::FindInt8(const char *name, int8 *anInt8) const +{ + entry_hdr *entry = entry_find(name, B_INT8_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *anInt8 = *(int8*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindInt8(const char *name, int32 index, int8 *anInt8) const +{ + entry_hdr *entry = entry_find(name, B_INT8_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + int8* data = (int8*)da_first_chunk(entry); + *anInt8 = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindInt16(const char *name, int16 *anInt16) const +{ + entry_hdr *entry = entry_find(name, B_INT16_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *anInt16 = *(int16*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindInt16(const char *name, int32 index, int16 *anInt16) const +{ + entry_hdr *entry = entry_find(name, B_INT16_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + int16* data = (int16*)da_first_chunk(entry); + *anInt16 = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindInt32(const char *name, int32 *anInt32) const +{ + entry_hdr *entry = entry_find(name, B_INT32_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *anInt32 = *(int32*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindInt32(const char *name, int32 index, + int32 *anInt32) const +{ + entry_hdr *entry = entry_find(name, B_INT32_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + int32* data = (int32*)da_first_chunk(entry); + *anInt32 = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +//status_t BMessage::FindInt64 ( const char *name, int64 *anInt64) const; +//------------------------------------------------------------------------------ +//status_t BMessage::FindInt64 ( const char *name, int32 index, +// int64 *anInt64 ) const; +//------------------------------------------------------------------------------ +status_t BMessage::FindBool(const char *name, bool *aBool) const +{ + entry_hdr *entry = entry_find(name, B_BOOL_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *aBool = *(bool*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindBool(const char *name, int32 index, bool *aBool) const +{ + entry_hdr *entry = entry_find(name, B_BOOL_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + bool* data = (bool*)da_first_chunk(entry); + *aBool = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindFloat(const char *name, float *aFloat) const +{ + entry_hdr *entry = entry_find(name, B_FLOAT_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *aFloat = *(float*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindFloat(const char *name, int32 index, float *aFloat) const +{ + entry_hdr *entry = entry_find(name, B_FLOAT_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + float* data = (float*)da_first_chunk(entry); + *aFloat = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindDouble(const char *name, double *aDouble) const +{ + entry_hdr *entry = entry_find(name, B_DOUBLE_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + *aDouble = *(double*)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindDouble(const char *name, int32 index, + double *aDouble) const +{ + entry_hdr *entry = entry_find(name, B_DOUBLE_TYPE); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (index < entry->fCount) + { + double* data = (double*)da_first_chunk(entry); + *aDouble = data[index]; + + return B_OK; + } + + return B_BAD_INDEX; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindPointer(const char *name, void **pointer) const +{ + entry_hdr *entry = entry_find(name, B_POINTER_TYPE); + + if (entry == NULL) + { + *pointer = NULL; + return B_NAME_NOT_FOUND; + } + + *pointer = *(void**)da_first_chunk(entry); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindPointer(const char *name, int32 index, + void **pointer) const +{ + entry_hdr *entry = entry_find(name, B_POINTER_TYPE); + + if (entry == NULL) + { + *pointer = NULL; + return B_NAME_NOT_FOUND; + } + + if (index >= entry->fCount) + { + *pointer = NULL; + return B_BAD_INDEX; + } + + void** data = (void**)da_first_chunk(entry); + *pointer = data[index]; + + return B_OK; +} +//------------------------------------------------------------------------------ +//status_t BMessage::FindMessenger ( const char *name, CMessenger *messenger ) const; +//------------------------------------------------------------------------------ +//status_t BMessage::FindMessenger ( const char *name, int32 index, CMessenger *messenger ) const; +//------------------------------------------------------------------------------ +//status_t BMessage::FindRef ( const char *name, entry_ref *ref ) const; +//------------------------------------------------------------------------------ +//status_t BMessage::FindRef ( const char *name, int32 index, entry_ref *ref ) const; +//------------------------------------------------------------------------------ +status_t BMessage::FindMessage(const char *name, BMessage *message) const +{ + const char *data; + + if ( FindData(name, B_MESSAGE_TYPE, (const void**)&data, NULL) != B_OK) + return B_NAME_NOT_FOUND; + + return message->Unflatten(data); +} +//------------------------------------------------------------------------------ +status_t BMessage::FindMessage(const char *name, int32 index, + BMessage *message) const +{ + const char *data; + + if ( FindData(name, B_MESSAGE_TYPE, index, (const void**)&data, + NULL) != B_OK) + return B_NAME_NOT_FOUND; + + return message->Unflatten(data); +} +//------------------------------------------------------------------------------ +status_t BMessage::FindFlat(const char *name, BFlattenable *object) const +{ + status_t ret; + const void *data; + size_t numBytes; + + ret = FindData(name, object->TypeCode (), &data, &numBytes); + + if ( ret != B_OK ) + return ret; + + if ( object->Unflatten(object->TypeCode (), data, numBytes) != B_OK) + return B_BAD_VALUE; + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindFlat(const char *name, int32 index, + BFlattenable *object) const +{ + status_t ret; + const void *data; + size_t numBytes; + + ret = FindData(name, object->TypeCode(), index, &data, &numBytes); + + if (ret != B_OK) + return ret; + + if (object->Unflatten(object->TypeCode(), data, numBytes) != B_OK) + return B_BAD_VALUE; + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindData(const char *name, type_code type, const void **data, + size_t *numBytes) const +{ + entry_hdr *entry = entry_find(name, type); + + if (entry == NULL) + { + *data = NULL; + return B_NAME_NOT_FOUND; + } + + int32 size; + + *data = da_find_data(entry, 0, &size); + + if (numBytes) + *numBytes = size; + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BMessage::FindData(const char *name, type_code type, int32 index, + const void **data, size_t *numBytes) const +{ + entry_hdr *entry = entry_find(name, type); + + if (entry == NULL) + { + *data = NULL; + return B_NAME_NOT_FOUND; + } + + if (index >= entry->fCount) + { + *data = NULL; + return B_BAD_INDEX; + } + + int32 size; + + *data = da_find_data(entry, index, &size); + + if (numBytes) + *numBytes = size; + + return B_OK; +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceRect(const char *name, BRect rect); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceRect(const char *name, int32 index, BRect rect); +//------------------------------------------------------------------------------ +status_t BMessage::ReplacePoint(const char *name, BPoint point) +{ + return ReplaceData(name, B_POINT_TYPE, &point, sizeof(BPoint)); +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplacePoint(const char *name, int32 index, BPoint point); +//------------------------------------------------------------------------------ +status_t BMessage::ReplaceString(const char *name, const char *string) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceString(const char *name, int32 index, +// const char *string); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceString(const char *name, CString &string); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceString(const char *name, int32 index, CString &string); +//------------------------------------------------------------------------------ +status_t BMessage::ReplaceInt8(const char *name, int8 anInt8) +{ + return ReplaceData(name, B_INT8_TYPE, &anInt8, sizeof(int8)); +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceInt8(const char *name, int32 index, int8 anInt8); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceInt16(const char *name, int16 anInt16); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceInt16(const char *name, int32 index, int16 anInt16); +//------------------------------------------------------------------------------ +status_t BMessage::ReplaceInt32(const char *name, long anInt32) +{ + return ReplaceData(name, B_INT32_TYPE, &anInt32, sizeof(int32)); +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceInt32(const char *name, int32 index, int32 anInt32); +//------------------------------------------------------------------------------ +status_t BMessage::ReplaceInt64(const char *name, int64 anInt64) +{ + return ReplaceData(name, B_INT64_TYPE, &anInt64, sizeof(int64)); +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceInt64(const char *name, int32 index, int64 anInt64); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceBool(const char *name, bool aBool); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceBool(const char *name, int32 index, bool aBool); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceFloat(const char *name, float aFloat); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceFloat(const char *name, int32 index, float aFloat); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceDouble(const char *name, double aDouble); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceDouble(const char *name, int32 index, double aDouble); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplacePointer(const char *name, const void *pointer); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplacePointer(const char *name, int32 index, +// const void *pointer); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceMessenger(const char *name, BMessenger messenger); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceMessenger(const char *name, int32 index, +// BMessenger messenger); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceRef(const char *name, entry_ref *ref); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceRef(const char *name, int32 index, entry_ref *ref); +//------------------------------------------------------------------------------ +//status_t ReplaceMessage(const char *name, const BMessage *msg); +//------------------------------------------------------------------------------ +//status_t ReplaceMessage(const char *name, int32 index, const BMessage *msg); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceFlat(const char *name, BFlattenable *object); +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceFlat(const char *name, int32 index, +// BFlattenable *object); +//------------------------------------------------------------------------------ +status_t BMessage::ReplaceData(const char *name, type_code type, + const void *data, size_t numBytes) +{ + entry_hdr *entry = entry_find(name, type); + + if (entry == NULL) + return B_NAME_NOT_FOUND; + + if (entry->fType != type) + return B_BAD_TYPE; + + da_replace_data((dyn_array**)&entry, 0, data, numBytes); + + return B_OK; +} +//------------------------------------------------------------------------------ +//status_t BMessage::ReplaceData(const char *name, type_code type, int32 index, +// const void *data, size_t numBytes); +//------------------------------------------------------------------------------ +//void *BMessage::operator new(size_t numBytes); +//------------------------------------------------------------------------------ +//void BMessage::operator delete(void *memory, size_t numBytes); +//------------------------------------------------------------------------------ +/*bool HasRect(const char *, int32 n = 0) const; +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 HasInt16(const char *, int32 n = 0) const; +bool HasInt32(const char *, int32 n = 0) const; +bool HasInt64(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; +bool HasPointer(const char *, int32 n = 0) const; +bool HasMessenger(const char *, int32 n = 0) const; +bool HasRef(const char *, int32 n = 0) const; +bool HasMessage(const char *, int32 n = 0) const; +bool HasFlat(const char *, const BFlattenable *) const; +bool HasFlat(const char *,int32 ,const BFlattenable *) const; +bool HasData(const char *, type_code , int32 n = 0) const; +BRect FindRect(const char *, int32 n = 0) const; +BPoint FindPoint(const char *, int32 n = 0) const; +const char *FindString(const char *, int32 n = 0) const; +int8 FindInt8(const char *, int32 n = 0) const; +int16 FindInt16(const char *, int32 n = 0) const;*/ +//------------------------------------------------------------------------------ +int32 BMessage::FindInt32(const char *name, int32 index) const +{ + int32 anInt32 = 0; + + BMessage::FindInt32(name, index, &anInt32); + + return anInt32; +} +//------------------------------------------------------------------------------ +/*int64 FindInt64(const char *, int32 n = 0) const; +bool FindBool(const char *, int32 n = 0) const; +float FindFloat(const char *, int32 n = 0) const; +double FindDouble(const char *, int32 n = 0) const;*/ +//------------------------------------------------------------------------------ +BMessage::BMessage(BMessage *a_message) +{ + BMessage::BMessage(*a_message); +} +//------------------------------------------------------------------------------ +void BMessage::_ReservedMessage1() {} +void BMessage::_ReservedMessage2() {} +void BMessage::_ReservedMessage3() {} +//------------------------------------------------------------------------------ +void BMessage::init_data() +{ + what = 0; + + link = NULL; + fTarget = -1; + fOriginal = NULL; + fChangeCount = 0; + fCurSpecifier = -1; + fPtrOffset = 0; + + fEntries = NULL; + + fReplyTo.port = -1; + fReplyTo.target = -1; + fReplyTo.team = -1; + fReplyTo.preferred = false; + + fPreferred = false; + fReplyRequired = false; + fReplyDone = false; + fIsReply = false; + fWasDelivered = false; + fReadOnly = false; + fHasSpecifiers = false; +} +//------------------------------------------------------------------------------ +int32 BMessage::flatten_hdr(uchar *result, ssize_t size, uchar flags) const +{ + return -1; +} +//------------------------------------------------------------------------------ +status_t BMessage::real_flatten(char *result, ssize_t size, uchar flags) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::real_flatten(BDataIO *stream, ssize_t size, + uchar flags) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +char *BMessage::stack_flatten(char *stack_ptr, ssize_t stack_size, + bool incl_reply, ssize_t *size) const +{ + return NULL; +} +//------------------------------------------------------------------------------ +ssize_t BMessage::calc_size(uchar flags) const +{ + return -1; +} +//------------------------------------------------------------------------------ +ssize_t BMessage::calc_hdr_size(uchar flags) const +{ + return -1; +} +//------------------------------------------------------------------------------ +ssize_t BMessage::min_hdr_size() const +{ + return -1; +} +//------------------------------------------------------------------------------ +status_t BMessage::nfind_data(const char *name, type_code type, int32 index, + const void **data, ssize_t *data_size) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::copy_data(const char *name, type_code type, int32 index, + void *data, ssize_t data_size) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::_send_(port_id port, int32 token, bool preferred, + bigtime_t timeout, bool reply_required, + BMessenger &reply_to) const +{ + /*_set_message_target_(this, token, preferred); + _set_message_reply_(this, reply_to); + + int32 size; + char *buffer; + + write_port_etc(port, what, buffer, size, B_TIMEOUT, timeout);*/ + + return B_ERROR; +} +//------------------------------------------------------------------------------ +status_t BMessage::send_message(port_id port, team_id port_owner, int32 token, + bool preferred, BMessage *reply, + bigtime_t send_timeout, + bigtime_t reply_timeout) const +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +BMessage::entry_hdr * BMessage::entry_find(const char *name, uint32 type, + status_t *result) const +{ + for (entry_hdr *entry = fEntries; entry != NULL; entry = entry->fNext) + if (entry->fType ==type && entry->fNameLength == strlen(name) && + strncmp(entry->fName, name, entry->fNameLength) == 0) + { + if (result) + *result = B_OK; + + return entry; + } + + if (result) + *result = B_NAME_NOT_FOUND; + + return NULL; +} +//------------------------------------------------------------------------------ +void BMessage::entry_remove(entry_hdr *entry) +{ + if (entry == fEntries) + fEntries = entry->fNext; + else + { + for (entry_hdr *entry_ptr = fEntries; entry_ptr != NULL; entry_ptr = entry_ptr->fNext) + if (entry_ptr->fNext == entry) + entry_ptr->fNext = entry->fNext; + } +} +//------------------------------------------------------------------------------ +void *BMessage::da_create(int32 header_size, int32 chunk_size, bool fixed, + int32 nchunks) +{ + int size = da_calc_size(header_size, chunk_size, fixed, nchunks); + + dyn_array *da = (dyn_array*)new char[size]; + + da->fLogicalBytes = 0; + da->fPhysicalBytes = size - sizeof(dyn_array) - header_size; + + if ( fixed ) + da->fChunkSize = chunk_size; + else + da->fChunkSize = 0; + + da->fCount = 0; + da->fEntryHdrSize = header_size; + + return da; +} +//------------------------------------------------------------------------------ +status_t BMessage::da_add_data(dyn_array **da, const void *data, int32 size ) +{ + _ASSERT(_CrtCheckMemory()); + + int32 new_size = (*da)->fLogicalBytes + ((*da)->fChunkSize ? (*da)->fChunkSize : + da_pad_8(size + da_chunk_hdr_size())); + + if (new_size > (*da)->fPhysicalBytes) + da_grow(da, new_size - (*da)->fPhysicalBytes); + + void *ptr = da_find_data(*da, (*da)->fCount++, NULL); + + memcpy(ptr, data, size); + + if ((*da)->fChunkSize) + (*da)->fLogicalBytes += size; + else + { + da_chunk_ptr(ptr)->fDataSize = size; + (*da)->fLogicalBytes += da_chunk_size(da_chunk_ptr(ptr)); + } + + _ASSERT(_CrtCheckMemory()); + + return B_OK; +} +//------------------------------------------------------------------------------ +void *BMessage::da_find_data(dyn_array *da, int32 index, int32 *size) const +{ + if (da->fChunkSize) + { + if (size) + *size = da->fChunkSize; + + return (char*)da_start_of_data(da) + index * da->fChunkSize; + } + else + { + var_chunk *chunk = da_first_chunk(da); + + for (int i = 0; i < index; i++) + chunk = da_next_chunk(chunk); + + if (size) + *size = chunk->fDataSize; + + return chunk->fData; + } +} +//------------------------------------------------------------------------------ +status_t BMessage::da_delete_data(dyn_array **pda, int32 index) +{ + return 0; +} +//------------------------------------------------------------------------------ +status_t BMessage::da_replace_data(dyn_array **pda, int32 index, + const void *data, int32 dsize) +{ + void *ptr = da_find_data(*pda, index, NULL); + + memcpy(ptr, data, dsize); + + return B_OK; +} +//------------------------------------------------------------------------------ +int32 BMessage::da_calc_size(int32 hdr_size, int32 chunksize, bool is_fixed, + int32 nchunks) const +{ + int size = sizeof(dyn_array) + hdr_size; + + if (is_fixed) + size += chunksize * nchunks; + else + size += (chunksize + da_chunk_hdr_size()) * nchunks; + + return size; +} +//------------------------------------------------------------------------------ +void *BMessage::da_grow(dyn_array **pda, int32 increase) +{ + dyn_array *da = (dyn_array*)new char[da_total_size(*pda) + increase]; + dyn_array *old_da = *pda; + + memcpy(da, *pda, da_total_size(*pda)); + + *pda = da; + (*pda)->fPhysicalBytes += increase; + + entry_remove((entry_hdr*)old_da); + + delete old_da; + + ((entry_hdr*)*pda)->fNext = fEntries; + fEntries = (entry_hdr*)*pda; + + return *pda; +} +//------------------------------------------------------------------------------ +void BMessage::da_dump(dyn_array *da) +{ + entry_hdr *entry = (entry_hdr*)da; + + printf("\tLogicalBytes=%d\n\tPhysicalBytes=%d\n\tChunkSize=%d\n\tCount=%d\n\tEntryHdrSize=%d\n", + entry->fLogicalBytes, entry->fPhysicalBytes, entry->fChunkSize, entry->fCount, + entry->fEntryHdrSize); + printf("\tNext=%p\n\tType=%c%c%c%c\n\tNameLength=%d\n\tName=%s\n", + entry->fNext, (entry->fType & 0xFF000000) >> 24, (entry->fType & 0x00FF0000) >> 16, + (entry->fType & 0x0000FF00) >> 8, entry->fType & 0x000000FF, entry->fNameLength, + entry->fName); + + printf("\tData="); + + switch (entry->fType) + { + case B_BOOL_TYPE: + { + printf("%s", *(bool*)da_find_data(entry, 0, NULL) ? "true" : "false"); + + for (int i = 1; i < entry->fCount; i++) + printf(", %s", *(bool*)da_find_data ( entry, i, NULL ) ? "true" : "false"); + break; + } + case B_INT32_TYPE: + { + printf("%d", *(int32*)da_find_data(entry, 0, NULL)); + + for (int i = 1; i < entry->fCount; i++) + printf(", %d", *(int32*)da_find_data(entry, i, NULL)); + break; + } + case B_FLOAT_TYPE: + { + printf("%f", *(float*)da_find_data(entry, 0, NULL)); + + for (int i = 1; i < entry->fCount; i++) + printf(", %f", *(float*)da_find_data ( entry, i, NULL)); + break; + } + case B_STRING_TYPE: + { + printf("%s", da_find_data(entry, 0, NULL)); + + for (int i = 1; i < entry->fCount; i++) + printf(", %s", da_find_data(entry, i, NULL)); + break; + } + case B_POINT_TYPE: + { + float *data = (float*)da_find_data(entry, 0, NULL); + + printf("[%f,%f]", data[0], data[1]); + + for (int i = 1; i < entry->fCount; i++) + { + data = (float*)da_find_data ( entry, i, NULL); + printf(", [%f,%f]", data[0], data[1]); + } + break; + } + case B_RECT_TYPE: + { + float *data = (float*)da_find_data(entry, 0, NULL); + + printf("[%f,%f,%f,%f]", data[0], data[1], data[2], data[3]); + + for (int i = 1; i < entry->fCount; i++) + { + data = (float*)da_find_data ( entry, i, NULL); + printf(", [%f,%f,%f,%f]", data[0], data[1], data[2], data[3]); + } + break; + } + } + + printf("\n"); +} +//------------------------------------------------------------------------------ +void BMessage::da_swap_var_sized(dyn_array *da) +{ +} +//------------------------------------------------------------------------------ +void BMessage::da_swap_fixed_sized(dyn_array *da) +{ +} +//------------------------------------------------------------------------------