1 /* 2 * Copyright 2005-2007, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Michael Lotz <mmlr@mlotz.ch> 7 */ 8 #ifndef _MESSAGE_PRIVATE_H_ 9 #define _MESSAGE_PRIVATE_H_ 10 11 #include <Message.h> 12 #include <TokenSpace.h> 13 14 15 #define MESSAGE_BODY_HASH_TABLE_SIZE 10 16 #define MAX_DATA_PREALLOCATION B_PAGE_SIZE * 10 17 #define MAX_FIELD_PREALLOCATION 50 18 #define MAX_ITEM_PREALLOCATION B_PAGE_SIZE 19 20 21 static const int32 kPortMessageCode = 'pjpp'; 22 23 24 enum { 25 MESSAGE_FLAG_VALID = 0x0001, 26 MESSAGE_FLAG_REPLY_REQUIRED = 0x0002, 27 MESSAGE_FLAG_REPLY_DONE = 0x0004, 28 MESSAGE_FLAG_IS_REPLY = 0x0008, 29 MESSAGE_FLAG_WAS_DELIVERED = 0x0010, 30 MESSAGE_FLAG_HAS_SPECIFIERS = 0x0020, 31 MESSAGE_FLAG_WAS_DROPPED = 0x0080, 32 MESSAGE_FLAG_PASS_BY_AREA = 0x0100 33 }; 34 35 36 enum { 37 FIELD_FLAG_VALID = 0x0001, 38 FIELD_FLAG_FIXED_SIZE = 0x0002, 39 }; 40 41 42 struct BMessage::field_header { 43 uint32 flags; 44 type_code type; 45 int32 name_length; 46 int32 count; 47 ssize_t data_size; 48 ssize_t allocated; 49 int32 offset; 50 int32 next_field; 51 }; 52 53 54 struct BMessage::message_header { 55 uint32 format; 56 uint32 what; 57 uint32 flags; 58 59 ssize_t fields_size; 60 ssize_t data_size; 61 ssize_t fields_available; 62 ssize_t data_available; 63 64 uint32 fields_checksum; 65 uint32 data_checksum; 66 67 int32 target; 68 int32 current_specifier; 69 area_id shared_area; 70 71 // reply info 72 port_id reply_port; 73 int32 reply_target; 74 team_id reply_team; 75 76 // body info 77 int32 field_count; 78 int32 hash_table_size; 79 int32 hash_table[MESSAGE_BODY_HASH_TABLE_SIZE]; 80 81 /* The hash table does contain indexes into the field list and 82 not direct offsets to the fields. This has the advantage 83 of not needing to update offsets in two locations. 84 The hash table must be reevaluated when we remove a field 85 though. 86 */ 87 }; 88 89 90 class BMessage::Private { 91 public: 92 Private(BMessage *msg) 93 : fMessage(msg) 94 { 95 } 96 97 Private(BMessage &msg) 98 : fMessage(&msg) 99 { 100 } 101 102 void 103 SetTarget(int32 token) 104 { 105 fMessage->fHeader->target = token; 106 } 107 108 int32 109 GetTarget() 110 { 111 return fMessage->fHeader->target; 112 } 113 114 bool 115 UsePreferredTarget() 116 { 117 return fMessage->fHeader->target == B_PREFERRED_TOKEN; 118 } 119 120 void 121 SetWasDropped(bool wasDropped) 122 { 123 if (wasDropped) 124 fMessage->fHeader->flags |= MESSAGE_FLAG_WAS_DROPPED; 125 else 126 fMessage->fHeader->flags &= ~MESSAGE_FLAG_WAS_DROPPED; 127 } 128 129 status_t 130 Clear() 131 { 132 return fMessage->_Clear(); 133 } 134 135 status_t 136 InitHeader() 137 { 138 return fMessage->_InitHeader(); 139 } 140 141 BMessage::message_header* 142 GetMessageHeader() 143 { 144 return fMessage->fHeader; 145 } 146 147 BMessage::field_header* 148 GetMessageFields() 149 { 150 return fMessage->fFields; 151 } 152 153 uint8* 154 GetMessageData() 155 { 156 return fMessage->fData; 157 } 158 159 ssize_t 160 NativeFlattenedSize() const 161 { 162 return fMessage->_NativeFlattenedSize(); 163 } 164 165 status_t 166 NativeFlatten(char *buffer, ssize_t size) const 167 { 168 return fMessage->_NativeFlatten(buffer, size); 169 } 170 171 status_t 172 NativeFlatten(BDataIO *stream, ssize_t *size) const 173 { 174 return fMessage->_NativeFlatten(stream, size); 175 } 176 177 // static methods 178 179 static void 180 StaticCacheCleanup() 181 { 182 BMessage::_StaticCacheCleanup(); 183 } 184 185 private: 186 BMessage* fMessage; 187 }; 188 189 #endif // _MESSAGE_PRIVATE_H_ 190