task_looper() again. * removed BMessenger::fPreferred - whenever you had to specify "usePreferred" separately, you don't have to do that anymore - use B_PREFERRED_TOKEN instead. * fixed BTokenSpace::GetToken() semantics: it will no longer touch the "object" argument in case of failure. * Introduced a BWindow::_DistributeMessage() that will be part of the event dispatcher counterpart to the app_server (the other will be _DetermineTarget()). * Made it easier to use Michael's Message4 implementation: just add the following line to your UserBuildConfig: AppendToConfigVar DEFINES : HAIKU_TOP src : USING_MESSAGE4 : global ; * Introduced ServerWindow::HandlerMessenger() and FocusMessenger() - the first will target the client handler, while the other will target the preferred handler of the client looper (usually the view having focus). * Fixed dano message unflattening in the Message4 code. * Changed BMessage::PrintToStream() to no longer use macros in the Message4 implementation. * I hope that's all - it's a huge change, but it's all connected. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15046 a95241bf-73f2-0310-859d-f6bbb57e9c96
136 lines
2.4 KiB
C++
136 lines
2.4 KiB
C++
/*
|
|
* Copyright 2001-2005, Haiku.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* Erik Jaesler ([email protected])
|
|
*/
|
|
|
|
#ifdef USING_MESSAGE4
|
|
# include "MessageUtils4.cpp"
|
|
#else
|
|
|
|
/** Extra messaging utility functions */
|
|
|
|
#include <string.h>
|
|
#include <ByteOrder.h>
|
|
|
|
#include <MessageUtils.h>
|
|
|
|
|
|
uint32
|
|
_checksum_(const uchar* buf, int32 size)
|
|
{
|
|
uint32 sum = 0;
|
|
uint32 temp = 0;
|
|
|
|
while (size > 3) {
|
|
#if defined(__INTEL__)
|
|
sum += B_SWAP_INT32(*(int*)buf);
|
|
#else
|
|
sum += *(int*)buf;
|
|
#endif
|
|
|
|
buf += 4;
|
|
size -= 4;
|
|
}
|
|
|
|
while (size > 0) {
|
|
temp = (temp << 8) + *buf++;
|
|
size -= 1;
|
|
}
|
|
|
|
return sum + temp;
|
|
}
|
|
|
|
|
|
namespace BPrivate { // Only putting these here because Be did
|
|
|
|
status_t
|
|
entry_ref_flatten(char* buffer, size_t* size, const entry_ref* ref)
|
|
{
|
|
memcpy((void*)buffer, (const void*)&ref->device, sizeof (ref->device));
|
|
buffer += sizeof (ref->device);
|
|
memcpy((void*)buffer, (const void*)&ref->directory, sizeof (ref->directory));
|
|
buffer += sizeof (ref->directory);
|
|
|
|
size_t len = 0;
|
|
if (ref->name) {
|
|
len = strlen(ref->name) + 1; // extra for NULL terminator
|
|
memcpy((void*)buffer, (const void*)ref->name, len);
|
|
}
|
|
|
|
*size = sizeof (ref->device) + sizeof (ref->directory) + len;
|
|
return B_OK;
|
|
}
|
|
|
|
|
|
status_t
|
|
entry_ref_unflatten(entry_ref* ref, const char* buffer, size_t size)
|
|
{
|
|
if (size < (sizeof (ref->device) + sizeof (ref->directory))) {
|
|
*ref = entry_ref();
|
|
return B_BAD_VALUE;
|
|
}
|
|
|
|
memcpy((void*)&ref->device, (const void*)buffer, sizeof (ref->device));
|
|
buffer += sizeof (ref->device);
|
|
memcpy((void*)&ref->directory, (const void*)buffer,
|
|
sizeof (ref->directory));
|
|
buffer += sizeof (ref->directory);
|
|
|
|
if (ref->device != -1
|
|
&& size > (sizeof (ref->device) + sizeof (ref->directory))) {
|
|
ref->set_name(buffer);
|
|
if (ref->name == NULL) {
|
|
*ref = entry_ref();
|
|
return B_NO_MEMORY;
|
|
}
|
|
} else
|
|
ref->set_name(NULL);
|
|
|
|
return B_OK;
|
|
}
|
|
|
|
|
|
status_t
|
|
entry_ref_swap(char* buffer, size_t size)
|
|
{
|
|
if (size < (sizeof (dev_t) + sizeof (ino_t)))
|
|
return B_BAD_DATA;
|
|
|
|
dev_t* dev = (dev_t*)buffer;
|
|
*dev = B_SWAP_INT32(*dev);
|
|
buffer += sizeof (dev_t);
|
|
|
|
ino_t* ino = (ino_t*)buffer;
|
|
*ino = B_SWAP_INT64(*ino);
|
|
|
|
return B_OK;
|
|
}
|
|
|
|
|
|
size_t
|
|
calc_padding(size_t size, size_t boundary)
|
|
{
|
|
size_t pad = size % boundary;
|
|
if (pad)
|
|
pad = boundary - pad;
|
|
|
|
return pad;
|
|
}
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
int32
|
|
TChecksumHelper::CheckSum()
|
|
{
|
|
return _checksum_(fBuffer, fBufPtr - fBuffer);
|
|
}
|
|
|
|
#endif // USING_MESSAGE4
|