From 557411309fa6033e6229d482d9167cec2a2e8296 Mon Sep 17 00:00:00 2001 From: Adi Oanca Date: Mon, 24 Oct 2005 17:46:37 +0000 Subject: [PATCH] preparing RootLayer thread to receive BMessages instead of PortLink ones git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14495 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/RootLayer.cpp | 64 +++++++++++++++++++++++++++++++++++ src/servers/app/RootLayer.h | 4 +++ 2 files changed, 68 insertions(+) diff --git a/src/servers/app/RootLayer.cpp b/src/servers/app/RootLayer.cpp index 42940f89cd..72127483fe 100644 --- a/src/servers/app/RootLayer.cpp +++ b/src/servers/app/RootLayer.cpp @@ -1771,3 +1771,67 @@ RootLayer::AddDebugInfo(const char* string) } } #endif // ON_SCREEN_DEBUGGING_INFO + + +// taken from BLooper +void * +RootLayer::ReadRawFromPort(int32 *msgCode, bigtime_t timeout) +{ + int8 *msgBuffer = NULL; + ssize_t bufferSize; + + do { + bufferSize = port_buffer_size_etc(fListenPort, B_RELATIVE_TIMEOUT, timeout); + } while (bufferSize == B_INTERRUPTED); + + if (bufferSize < B_OK) + return NULL; + + if (bufferSize > 0) + msgBuffer = new int8[bufferSize]; + + // we don't want to wait again here, since that can only mean + // that someone else has read our message and our bufferSize + // is now probably wrong + bufferSize = read_port_etc(fListenPort, msgCode, msgBuffer, bufferSize, + B_RELATIVE_TIMEOUT, 0); + if (bufferSize < B_OK) { + delete[] msgBuffer; + return NULL; + } + + return msgBuffer; +} + + +BMessage * +RootLayer::ReadMessageFromPort(bigtime_t tout) +{ + int32 msgcode; + BMessage* bmsg; + + void* msgbuffer = ReadRawFromPort(&msgcode, tout); + if (!msgbuffer) + return NULL; + + bmsg = ConvertToMessage(msgbuffer, msgcode); + + delete[] (int8*)msgbuffer; + + return bmsg; +} +//------------------------------------------------------------------------------ +BMessage* +RootLayer::ConvertToMessage(void* raw, int32 code) +{ + BMessage* bmsg = new BMessage(code); + + if (raw != NULL) { + if (bmsg->Unflatten((const char*)raw) != B_OK) { + delete bmsg; + bmsg = NULL; + } + } + + return bmsg; +} \ No newline at end of file diff --git a/src/servers/app/RootLayer.h b/src/servers/app/RootLayer.h index a4aed87a08..093ed47161 100644 --- a/src/servers/app/RootLayer.h +++ b/src/servers/app/RootLayer.h @@ -169,6 +169,10 @@ friend class WinBorder; // temporarily, I need invalidate_layer() inline HWInterface* GetHWInterface() const { return fDesktop->GetHWInterface(); } + void* ReadRawFromPort(int32 *msgCode, bigtime_t timeout); + BMessage* ReadMessageFromPort(bigtime_t tout); + BMessage* ConvertToMessage(void* raw, int32 code); + Desktop* fDesktop; BMessage* fDragMessage; Layer* fLastLayerUnderMouse;