From 1156138b2f9c9c85e0fe2538a1186d522d978d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 2 Nov 2005 12:55:20 +0000 Subject: [PATCH] Removed unused files like PortMessage.cpp/h and Session.cpp/h. Renamed LinkMsgReceiver.h and LinkMsgSender.h to LinkReceiver.h and LinkSender.h like the classes they contain. Split up PortLink.cpp/h into ServerLink.cpp/h and PortLink.cpp/h. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14635 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../app/{LinkMsgReader.h => LinkReceiver.h} | 9 +- .../app/{LinkMsgSender.h => LinkSender.h} | 9 +- headers/private/app/PortLink.h | 177 +---- headers/private/app/PortMessage.h | 82 --- headers/private/app/ServerLink.h | 186 +++++ headers/private/app/Session.h | 112 --- src/kits/app/Cursor.cpp | 46 +- src/kits/app/Jamfile | 1 + src/kits/app/LinkReceiver.cpp | 4 +- src/kits/app/LinkSender.cpp | 2 +- src/kits/app/PortLink.cpp | 90 +-- src/kits/app/PortMessage.cpp | 180 ----- src/kits/app/ServerLink.cpp | 97 +++ src/kits/app/Session.cpp | 680 ------------------ src/servers/app/LayerData.cpp | 4 +- src/servers/app/RAMLinkMsgReader.h | 2 +- 16 files changed, 315 insertions(+), 1366 deletions(-) rename headers/private/app/{LinkMsgReader.h => LinkReceiver.h} (93%) rename headers/private/app/{LinkMsgSender.h => LinkSender.h} (87%) delete mode 100644 headers/private/app/PortMessage.h create mode 100644 headers/private/app/ServerLink.h delete mode 100644 headers/private/app/Session.h delete mode 100644 src/kits/app/PortMessage.cpp create mode 100644 src/kits/app/ServerLink.cpp delete mode 100644 src/kits/app/Session.cpp diff --git a/headers/private/app/LinkMsgReader.h b/headers/private/app/LinkReceiver.h similarity index 93% rename from headers/private/app/LinkMsgReader.h rename to headers/private/app/LinkReceiver.h index 6ca28cbe01..602d3e8c99 100644 --- a/headers/private/app/LinkMsgReader.h +++ b/headers/private/app/LinkReceiver.h @@ -6,8 +6,8 @@ * DarkWyrm * Pahtz */ -#ifndef _LINKMSGREADER_H -#define _LINKMSGREADER_H +#ifndef _LINK_RECEIVER_H +#define _LINK_RECEIVER_H #include @@ -42,11 +42,8 @@ class LinkReceiver { port_id fReceivePort; char *fRecvBuffer; - int32 fRecvPosition; //current read position - int32 fRecvStart; //start of current message - int32 fRecvBufferSize; int32 fDataSize; //size of data in recv buffer @@ -57,4 +54,4 @@ class LinkReceiver { } // namespace BPrivate -#endif // _LINKMSGREADER_H +#endif // _LINK_RECEIVER_H diff --git a/headers/private/app/LinkMsgSender.h b/headers/private/app/LinkSender.h similarity index 87% rename from headers/private/app/LinkMsgSender.h rename to headers/private/app/LinkSender.h index 16ddedb825..182a4a5ad1 100644 --- a/headers/private/app/LinkMsgSender.h +++ b/headers/private/app/LinkSender.h @@ -7,8 +7,8 @@ * Pahtz * Axel Dörfler, axeld@pinc-software.de */ -#ifndef LINKMSGSENDER_H -#define LINKMSGSENDER_H +#ifndef _LINK_SENDER_H +#define _LINK_SENDER_H #include @@ -30,9 +30,6 @@ class LinkSender { status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); - // see BPrivate::BAppServerLink which inherits from BPortLink - //status_t FlushWithReply(int32 *code); - status_t Attach(const void *data, size_t size); status_t AttachString(const char *string, int32 length = -1); template status_t Attach(const Type& data) @@ -60,4 +57,4 @@ class LinkSender { } // namespace BPrivate -#endif /* LINKMSGSENDER_H */ +#endif /* _LINK_SENDER_H */ diff --git a/headers/private/app/PortLink.h b/headers/private/app/PortLink.h index 25800e328e..132a711db5 100644 --- a/headers/private/app/PortLink.h +++ b/headers/private/app/PortLink.h @@ -1,79 +1,19 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2005, Haiku. * Distributed under the terms of the MIT License. * * Authors: - * DarkWyrm - * Pahtz * Axel Dörfler, axeld@pinc-software.de */ -#ifndef _SERVER_LINK_H -#define _SERVER_LINK_H +#ifndef _PORT_LINK_H +#define _PORT_LINK_H -#include -#include -#include +#include -/* - * Error checking rules: (for if you don't want to check every return code) - * - Calling EndMessage() is optional, implied by Flush() or StartMessage(). - * - If you are sending just one message you only need to test Flush() == B_OK - * - If you are buffering multiple messages without calling Flush() you must - * check EndMessage() == B_OK, or the last Attach() for each message. - * Check Flush() at the end. - * - If you are reading, check the last Read() or ReadString() you perform. - */ - namespace BPrivate { -class ServerLink { - public: - ServerLink(); - virtual ~ServerLink(); - - // send methods - - void SetSenderPort(port_id port); - port_id SenderPort(); - - status_t StartMessage(int32 code, size_t minSize = 0); - void CancelMessage(); - status_t EndMessage(); - - status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); - status_t Attach(const void *data, ssize_t size); - status_t AttachString(const char *string, int32 length = -1); - status_t AttachRegion(const BRegion ®ion); - status_t AttachShape(BShape &shape); - template status_t Attach(const Type& data); - - // receive methods - - void SetReceiverPort(port_id port); - port_id ReceiverPort(); - - status_t GetNextMessage(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); - bool NeedsReply() const; - status_t Read(void *data, ssize_t size); - status_t ReadString(char *buffer, size_t bufferSize); - status_t ReadString(char **string); - status_t ReadRegion(BRegion *region); - status_t ReadShape(BShape *shape); - template status_t Read(Type *data); - - // convenience methods - - status_t FlushWithReply(int32 &code); - LinkSender &Sender() { return *fSender; } - LinkReceiver &Receiver() { return *fReceiver; } - - protected: - LinkSender *fSender; - LinkReceiver *fReceiver; -}; - class PortLink : public ServerLink { public: PortLink(port_id sender = -1, port_id receiver = -1); @@ -82,113 +22,6 @@ class PortLink : public ServerLink { void SetTo(port_id sender, port_id receiver); }; - -// sender inline functions - -inline void -ServerLink::SetSenderPort(port_id port) -{ - fSender->SetPort(port); -} - -inline port_id -ServerLink::SenderPort() -{ - return fSender->Port(); -} - -inline status_t -ServerLink::StartMessage(int32 code, size_t minSize) -{ - return fSender->StartMessage(code, minSize); -} - -inline status_t -ServerLink::EndMessage() -{ - return fSender->EndMessage(); -} - -inline void -ServerLink::CancelMessage() -{ - fSender->CancelMessage(); -} - -inline status_t -ServerLink::Flush(bigtime_t timeout, bool needsReply) -{ - return fSender->Flush(timeout, needsReply); -} - -inline status_t -ServerLink::Attach(const void *data, ssize_t size) -{ - return fSender->Attach(data, size); -} - -inline status_t -ServerLink::AttachString(const char *string, int32 length) -{ - return fSender->AttachString(string, length); -} - -template status_t -ServerLink::Attach(const Type &data) -{ - return Attach(&data, sizeof(Type)); -} - -// #pragma mark - receiver inline functions - -inline void -ServerLink::SetReceiverPort(port_id port) -{ - fReceiver->SetPort(port); -} - -inline port_id -ServerLink::ReceiverPort() -{ - return fReceiver->Port(); -} - -inline status_t -ServerLink::GetNextMessage(int32 &code, bigtime_t timeout) -{ - return fReceiver->GetNextMessage(code, timeout); -} - -inline bool -ServerLink::NeedsReply() const -{ - return fReceiver->NeedsReply(); -} - -inline status_t -ServerLink::Read(void *data, ssize_t size) -{ - return fReceiver->Read(data, size); -} - -inline status_t -ServerLink::ReadString(char *buffer, size_t bufferSize) -{ - return fReceiver->ReadString(buffer, bufferSize); -} - -inline status_t -ServerLink::ReadString(char **string) -{ - return fReceiver->ReadString(string); -} - -template status_t -ServerLink::Read(Type *data) -{ - return Read(data, sizeof(Type)); -} - } // namespace BPrivate -#endif /* _SERVER_LINK_H */ +#endif /* _PORT_LINK_H */ diff --git a/headers/private/app/PortMessage.h b/headers/private/app/PortMessage.h deleted file mode 100644 index 81a5c0c8e9..0000000000 --- a/headers/private/app/PortMessage.h +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: PortMessage.h -// Author: DarkWyrm -// Description: Package class for port messaging-based data -// -//------------------------------------------------------------------------------ -#ifndef PORTMESSAGE_H_ -#define PORTMESSAGE_H_ - -#include -#include - -class PortMessage -{ -public: - PortMessage(const int32 &code, const void *buffer, const ssize_t &buffersize, - const bool ©); - PortMessage(void); - ~PortMessage(void); - - status_t ReadFromPort(const port_id &port, const bigtime_t &timeout=B_INFINITE_TIMEOUT); - status_t WriteToPort(const port_id &port); - - void SetCode(const int32 &code); - void SetProtocol(int32 protocol) { _protocol=protocol; } - void SetBuffer(const void *buffer, const ssize_t &size, const bool ©=false); - - int32 Code(void) { return _code; } - void *Buffer(void) { return _buffer; } - ssize_t BufferSize(void) { return _buffersize; } - int32 Protocol(void) const { return _protocol; } - - status_t Read(void *data, ssize_t size); - status_t ReadString(char **string); - template status_t Read(Type *data) - { - int32 size = sizeof(Type); - - if(!data) - return B_BAD_VALUE; - - if( !_buffer || - (_buffersize < size) || - (_index+size > _buffer+_buffersize) ) - return B_NO_MEMORY; - - *data=*((Type*)_index); - _index+=size; - - return B_OK; - } - - void Rewind(void); -private: - int32 _code; - uint8 *_buffer; - ssize_t _buffersize; - uint8 *_index; - int32 _protocol; -}; - -#endif diff --git a/headers/private/app/ServerLink.h b/headers/private/app/ServerLink.h new file mode 100644 index 0000000000..5648989bae --- /dev/null +++ b/headers/private/app/ServerLink.h @@ -0,0 +1,186 @@ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + * Pahtz + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef _SERVER_LINK_H +#define _SERVER_LINK_H + + +#include +#include +#include + + +/* + * Error checking rules: (for if you don't want to check every return code) + * - Calling EndMessage() is optional, implied by Flush() or StartMessage(). + * - If you are sending just one message you only need to test Flush() == B_OK + * - If you are buffering multiple messages without calling Flush() you must + * check EndMessage() == B_OK, or the last Attach() for each message. + * Check Flush() at the end. + * - If you are reading, check the last Read() or ReadString() you perform. + */ + +namespace BPrivate { + +class ServerLink { + public: + ServerLink(); + virtual ~ServerLink(); + + // send methods + + void SetSenderPort(port_id port); + port_id SenderPort(); + + status_t StartMessage(int32 code, size_t minSize = 0); + void CancelMessage(); + status_t EndMessage(); + + status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); + status_t Attach(const void *data, ssize_t size); + status_t AttachString(const char *string, int32 length = -1); + status_t AttachRegion(const BRegion ®ion); + status_t AttachShape(BShape &shape); + template status_t Attach(const Type& data); + + // receive methods + + void SetReceiverPort(port_id port); + port_id ReceiverPort(); + + status_t GetNextMessage(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); + bool NeedsReply() const; + status_t Read(void *data, ssize_t size); + status_t ReadString(char *buffer, size_t bufferSize); + status_t ReadString(char **string); + status_t ReadRegion(BRegion *region); + status_t ReadShape(BShape *shape); + template status_t Read(Type *data); + + // convenience methods + + status_t FlushWithReply(int32 &code); + LinkSender &Sender() { return *fSender; } + LinkReceiver &Receiver() { return *fReceiver; } + + protected: + LinkSender *fSender; + LinkReceiver *fReceiver; +}; + + +// sender inline functions + +inline void +ServerLink::SetSenderPort(port_id port) +{ + fSender->SetPort(port); +} + +inline port_id +ServerLink::SenderPort() +{ + return fSender->Port(); +} + +inline status_t +ServerLink::StartMessage(int32 code, size_t minSize) +{ + return fSender->StartMessage(code, minSize); +} + +inline status_t +ServerLink::EndMessage() +{ + return fSender->EndMessage(); +} + +inline void +ServerLink::CancelMessage() +{ + fSender->CancelMessage(); +} + +inline status_t +ServerLink::Flush(bigtime_t timeout, bool needsReply) +{ + return fSender->Flush(timeout, needsReply); +} + +inline status_t +ServerLink::Attach(const void *data, ssize_t size) +{ + return fSender->Attach(data, size); +} + +inline status_t +ServerLink::AttachString(const char *string, int32 length) +{ + return fSender->AttachString(string, length); +} + +template status_t +ServerLink::Attach(const Type &data) +{ + return Attach(&data, sizeof(Type)); +} + +// #pragma mark - receiver inline functions + +inline void +ServerLink::SetReceiverPort(port_id port) +{ + fReceiver->SetPort(port); +} + +inline port_id +ServerLink::ReceiverPort() +{ + return fReceiver->Port(); +} + +inline status_t +ServerLink::GetNextMessage(int32 &code, bigtime_t timeout) +{ + return fReceiver->GetNextMessage(code, timeout); +} + +inline bool +ServerLink::NeedsReply() const +{ + return fReceiver->NeedsReply(); +} + +inline status_t +ServerLink::Read(void *data, ssize_t size) +{ + return fReceiver->Read(data, size); +} + +inline status_t +ServerLink::ReadString(char *buffer, size_t bufferSize) +{ + return fReceiver->ReadString(buffer, bufferSize); +} + +inline status_t +ServerLink::ReadString(char **string) +{ + return fReceiver->ReadString(string); +} + +template status_t +ServerLink::Read(Type *data) +{ + return Read(data, sizeof(Type)); +} + +} // namespace BPrivate + +#endif /* _SERVER_LINK_H */ diff --git a/headers/private/app/Session.h b/headers/private/app/Session.h deleted file mode 100644 index 1eb7d057e9..0000000000 --- a/headers/private/app/Session.h +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: Session.h -// Author: Adi Oanca -// Description: Stream-based messaging class -// -//------------------------------------------------------------------------------ -#ifndef _SESSION_H -#define _SESSION_H - -#include -#include -#include -#include -#include -#include - -#define SESSION_BUFFER_SIZE 1024 - -class BSession -{ -public: - BSession(port_id receivePort, port_id sendPort); - BSession(int32, char *); - BSession( const BSession &ses ); - virtual ~BSession(void); - void SetSendPort( port_id port ); - void SetRecvPort( port_id port ); - port_id GetSendPort(void) const { return fSendPort; } - port_id GetRecvPort(void) const { return fReceivePort; } - - char *ReadString(); - void ReadBool( bool *b ); - void ReadInt8( int8 *i ); - void ReadUInt8( uint8 *i ); - void ReadInt16( int16 *i ); - void ReadUInt16( uint16 *i ); - void ReadInt32( int32 *i ); - void ReadUInt32( uint32 *i ); - void ReadInt64( int64 *i ); - void ReadUInt64( uint64 *i ); - void ReadFloat( float *f ); - void ReadFloatFromInt32( float *f ); - void ReadDouble( double *d ); - void ReadDoubleFromInt64( double *d ); - void ReadPoint( BPoint *point ); - void ReadPointFromInts( BPoint *point ); - void ReadRectCR( clipping_rect *rect ); - void ReadRect( BRect *rect ); - void ReadRectFromInts( BRect *rect ); - void ReadData( void* data, int32 size ); - - void WriteString( const char* string ); - void WriteBool( const bool& b ); - void WriteInt8( const int8& i ); - void WriteUInt8( const uint8& i ); - void WriteInt16( const int16& i ); - void WriteUInt16( const uint16& i ); - void WriteInt32( const int32& i ); - void WriteUInt32( const uint32& i ); - void WriteInt64( const int64& i ); - void WriteUInt64( const uint64& i ); - void WriteFloat(const float& f ); - void WriteFloatAsInt32( const float& f ); - void WriteDouble( const double& d ); - void WriteDoubleAsInt64( const double& d ); - void WritePoint(const BPoint& point); - void WritePointAsInt32s(const BPoint& point); - void WriteRect(const clipping_rect& rect); - void WriteRect(const BRect& rect); - void WriteRectAsInt32s(const BRect& rect); - void WriteData(const void* data, int32 size); - - void Sync(); - - // Deprecated. Do not use. - void CopyToSendBuffer(void* buffer, int32 count); - -private: - port_id fSendPort; - port_id fReceivePort; - - char *fSendBuffer; - int32 fSendPosition; - int32 fRecvCode; - - char *fReceiveBuffer; - int32 fReceiveSize; - int32 fReceivePosition; -}; - - -#endif diff --git a/src/kits/app/Cursor.cpp b/src/kits/app/Cursor.cpp index a84ac9f623..2e69118c1a 100644 --- a/src/kits/app/Cursor.cpp +++ b/src/kits/app/Cursor.cpp @@ -1,43 +1,23 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku -// -// 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: Cursor.cpp -// Author: Frans van Nispen (xlr8@tref.nl) -// Gabe Yoder (gyoder@stny.rr.com) -// Description: BCursor describes a view-wide or application-wide cursor. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen (xlr8@tref.nl) + * Gabe Yoder (gyoder@stny.rr.com) + */ + +/** BCursor describes a view-wide or application-wide cursor. */ + /** @note: As BeOS only supports 16x16 monochrome cursors, and I would like to see a nice shadowes one, we will need to extend this one. */ -// Standard Includes ----------------------------------------------------------- - -// System Includes ------------------------------------------------------------- #include -#include -#include -#include -// Project Includes ------------------------------------------------------------ +#include +#include #include diff --git a/src/kits/app/Jamfile b/src/kits/app/Jamfile index 2b95625ec0..700dde151c 100644 --- a/src/kits/app/Jamfile +++ b/src/kits/app/Jamfile @@ -59,6 +59,7 @@ MergeObject app_kit.o : Roster.cpp RosterPrivate.cpp Server.cpp + ServerLink.cpp ServerMemIO.cpp TokenSpace.cpp TypeConstants.cpp diff --git a/src/kits/app/LinkReceiver.cpp b/src/kits/app/LinkReceiver.cpp index 2364e12dce..c4d6f18913 100644 --- a/src/kits/app/LinkReceiver.cpp +++ b/src/kits/app/LinkReceiver.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include "link_message.h" @@ -23,7 +23,7 @@ #ifdef DEBUG_BPORTLINK # include # define STRACE(x) printf x -// those are defined in LinkMsgSender.cpp +// those are defined in LinkSender.cpp extern const char *strcode(int32 code); extern const char *bstrcode(int32 code); #else diff --git a/src/kits/app/LinkSender.cpp b/src/kits/app/LinkSender.cpp index ee5bbb26f0..2ba3176755 100644 --- a/src/kits/app/LinkSender.cpp +++ b/src/kits/app/LinkSender.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "link_message.h" diff --git a/src/kits/app/PortLink.cpp b/src/kits/app/PortLink.cpp index 4cfbabfb8f..059f3cfc65 100644 --- a/src/kits/app/PortLink.cpp +++ b/src/kits/app/PortLink.cpp @@ -1,105 +1,17 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2005, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: - * Pahtz * Axel Dörfler, axeld@pinc-software.de */ -/** Class for low-overhead port-based messaging */ -#include -#include -#include -#include -#include - -#include -#include #include -#include namespace BPrivate { -ServerLink::ServerLink() -{ -} - - -ServerLink::~ServerLink() -{ -} - - -status_t -ServerLink::ReadRegion(BRegion *region) -{ - fReceiver->Read(®ion->count, sizeof(long)); - fReceiver->Read(®ion->bound, sizeof(clipping_rect)); - region->set_size(region->count + 1); - return fReceiver->Read(region->data, region->count * sizeof(clipping_rect)); -} - - -status_t -ServerLink::AttachRegion(const BRegion ®ion) -{ - fSender->Attach(®ion.count, sizeof(long)); - fSender->Attach(®ion.bound, sizeof(clipping_rect)); - return fSender->Attach(region.data, region.count * sizeof(clipping_rect)); -} - - -status_t -ServerLink::ReadShape(BShape *shape) -{ - int32 opCount, ptCount; - fReceiver->Read(&opCount, sizeof(int32)); - fReceiver->Read(&ptCount, sizeof(int32)); - - uint32 opList[opCount]; - fReceiver->Read(opList, opCount * sizeof(uint32)); - - BPoint ptList[ptCount]; - fReceiver->Read(ptList, ptCount * sizeof(BPoint)); - - shape->SetData(opCount, ptCount, opList, ptList); - return B_OK; -} - - -status_t -ServerLink::AttachShape(BShape &shape) -{ - int32 opCount, ptCount; - uint32 *opList; - BPoint *ptList; - - shape.GetData(&opCount, &ptCount, &opList, &ptList); - - fSender->Attach(&opCount, sizeof(int32)); - fSender->Attach(&ptCount, sizeof(int32)); - fSender->Attach(opList, opCount * sizeof(uint32)); - return fSender->Attach(ptList, ptCount * sizeof(BPoint)); -} - - -status_t -ServerLink::FlushWithReply(int32 &code) -{ - status_t status = Flush(B_INFINITE_TIMEOUT, true); - if (status < B_OK) - return status; - - return GetNextMessage(code); -} - - -// #pragma mark - - - PortLink::PortLink(port_id send, port_id receive) { fSender = new LinkSender(send); diff --git a/src/kits/app/PortMessage.cpp b/src/kits/app/PortMessage.cpp deleted file mode 100644 index cdfbd8545f..0000000000 --- a/src/kits/app/PortMessage.cpp +++ /dev/null @@ -1,180 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: PortMessage.cpp -// Author: DarkWyrm -// Description: Package class for port messaging-based data -// -//------------------------------------------------------------------------------ -#include -#include -#include "PortMessage.h" -#include - -// TODO: Eliminate the reallocation of the message buffer - allocate it on construction -// and free it on destruction. - -PortMessage::PortMessage(const int32 &code, const void *buffer, const ssize_t &buffersize, - const bool ©) -{ - _code=code; - _protocol=AS_SERVER_PORTLINK; - SetBuffer(buffer,buffersize,copy); -} - -PortMessage::PortMessage(void) -{ - _code=0; - _protocol=AS_SERVER_PORTLINK; - _buffer=NULL; - _buffersize=0; - _index=NULL; -} - -PortMessage::~PortMessage(void) -{ - if(_buffersize>0 && _buffer!=NULL) - delete _buffer; -} - -status_t PortMessage::ReadFromPort(const port_id &port, const bigtime_t &timeout) -{ - if(_buffersize>0 && _buffer!=NULL) - delete _buffer; - _buffer=NULL; - _index=NULL; - _buffersize=0; - - if(timeout==B_INFINITE_TIMEOUT) - { - _buffersize=port_buffer_size(port); - if(_buffersize==B_BAD_PORT_ID) - return (status_t)_buffersize; - } - else - { - _buffersize=port_buffer_size_etc(port,B_TIMEOUT, timeout); - if(_buffersize==B_TIMED_OUT || _buffersize==B_BAD_PORT_ID || - _buffersize==B_WOULD_BLOCK) - return (status_t)_buffersize; - } - - if(_buffersize>0) - _buffer=new uint8[_buffersize]; - read_port(port, &_protocol, _buffer, _buffersize); - if(_buffer) - _code=*((int32*)_buffer); - - _index=_buffer+8; - - return B_OK; -} - -status_t PortMessage::WriteToPort(const port_id &port) -{ - // Check port validity - port_info pi; - if(get_port_info(port,&pi)!=B_OK) - return B_BAD_VALUE; - - int32 *cast=(int32*)_buffer; - *cast=_code; - - write_port(port, AS_SERVER_PORTLINK, _buffer, _buffersize); - - if(_buffer && _buffersize>0) - { - delete _buffer; - _buffersize=0; - _buffer=NULL; - _index=NULL; - } - return B_OK; -} - -void PortMessage::SetCode(const int32 &code) -{ - _code=code; -} - -void PortMessage::SetBuffer(const void *buffer, const ssize_t &size, const bool ©) -{ - if(_buffersize>0 && _buffer!=NULL) - delete _buffer; - _buffer=NULL; - _buffersize=4; - - if(!buffer || size<5) - return; - - if(copy) - { - _buffersize=size; - _buffer=new uint8[_buffersize]; - memcpy(_buffer,buffer,_buffersize); - } - else - { - _buffersize=size; - _buffer=(uint8 *)buffer; - } - _index=_buffer+8; -} - -status_t PortMessage::Read(void *data, ssize_t size) -{ - if(!data || size<1) - return B_BAD_VALUE; - - if( !_buffer || _buffersize(_buffer+_buffersize)) ) - return B_NO_MEMORY; - - memcpy(data,_index,size); - _index+=size; - - return B_OK; -} - -void PortMessage::Rewind(void) -{ - _index=_buffer+8; -} - -status_t PortMessage::ReadString(char **string) -{ - int16 len=0; - - if(Read(&len)!= B_OK) - return B_ERROR; - - if (len) - { - *string=new char[len]; - if(Read(*string, len)!= B_OK) - { - delete *string; - *string=NULL; - } - } - - return B_OK; -} diff --git a/src/kits/app/ServerLink.cpp b/src/kits/app/ServerLink.cpp new file mode 100644 index 0000000000..ee843b10d8 --- /dev/null +++ b/src/kits/app/ServerLink.cpp @@ -0,0 +1,97 @@ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Pahtz + * Axel Dörfler, axeld@pinc-software.de + */ + +/** Class for low-overhead port-based messaging */ + +#include +#include +#include +#include +#include + +#include +#include + + +namespace BPrivate { + +ServerLink::ServerLink() +{ +} + + +ServerLink::~ServerLink() +{ +} + + +status_t +ServerLink::ReadRegion(BRegion *region) +{ + fReceiver->Read(®ion->count, sizeof(long)); + fReceiver->Read(®ion->bound, sizeof(clipping_rect)); + region->set_size(region->count + 1); + return fReceiver->Read(region->data, region->count * sizeof(clipping_rect)); +} + + +status_t +ServerLink::AttachRegion(const BRegion ®ion) +{ + fSender->Attach(®ion.count, sizeof(long)); + fSender->Attach(®ion.bound, sizeof(clipping_rect)); + return fSender->Attach(region.data, region.count * sizeof(clipping_rect)); +} + + +status_t +ServerLink::ReadShape(BShape *shape) +{ + int32 opCount, ptCount; + fReceiver->Read(&opCount, sizeof(int32)); + fReceiver->Read(&ptCount, sizeof(int32)); + + uint32 opList[opCount]; + fReceiver->Read(opList, opCount * sizeof(uint32)); + + BPoint ptList[ptCount]; + fReceiver->Read(ptList, ptCount * sizeof(BPoint)); + + shape->SetData(opCount, ptCount, opList, ptList); + return B_OK; +} + + +status_t +ServerLink::AttachShape(BShape &shape) +{ + int32 opCount, ptCount; + uint32 *opList; + BPoint *ptList; + + shape.GetData(&opCount, &ptCount, &opList, &ptList); + + fSender->Attach(&opCount, sizeof(int32)); + fSender->Attach(&ptCount, sizeof(int32)); + fSender->Attach(opList, opCount * sizeof(uint32)); + return fSender->Attach(ptList, ptCount * sizeof(BPoint)); +} + + +status_t +ServerLink::FlushWithReply(int32 &code) +{ + status_t status = Flush(B_INFINITE_TIMEOUT, true); + if (status < B_OK) + return status; + + return GetNextMessage(code); +} + +} // namespace BPrivate diff --git a/src/kits/app/Session.cpp b/src/kits/app/Session.cpp deleted file mode 100644 index 8a66a24fba..0000000000 --- a/src/kits/app/Session.cpp +++ /dev/null @@ -1,680 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: Session.cpp -// Author: Adi Oanca -// Description: Stream-based messaging class -// -//------------------------------------------------------------------------------ -#include -#include - -/* -#ifdef DEBUG_BSESSION -# include -# define STRACE(x) printf x -#else -# define STRACE(x) ; -#endif -*/ - -/*! - \brief Standard constructor - \param receivePort ID of the port the BSession is to receive messages from - \param sendPort ID of the port the BSession is to send messages to -*/ -BSession::BSession(port_id receivePort, port_id sendPort) -{ - fSendPort = sendPort; - fReceivePort = receivePort; - - fSendBuffer = NULL; - fSendPosition = 0; - - fReceiveBuffer = NULL; - fReceiveSize = SESSION_BUFFER_SIZE; - fReceivePosition = SESSION_BUFFER_SIZE; - - fSendBuffer = new char[SESSION_BUFFER_SIZE]; - fReceiveBuffer = new char[SESSION_BUFFER_SIZE]; -} - -/*! - \brief Copy constructor - \param ses Session to copy - - The instantiated BSession utilizes the same ports but contains no data -*/ -BSession::BSession( const BSession &ses) -{ - fSendPort = ses.fSendPort; - fReceivePort = ses.fReceivePort; - - fSendBuffer = NULL; - fSendPosition = 0; - - fReceiveBuffer = NULL; - fReceiveSize = SESSION_BUFFER_SIZE; - fReceivePosition = SESSION_BUFFER_SIZE; - - fSendBuffer = new char[SESSION_BUFFER_SIZE]; - fReceiveBuffer = new char[SESSION_BUFFER_SIZE]; -} - -//! Deletes the allocated messaging buffers. Ports used are not deleted. -BSession::~BSession(void) -{ - delete [] fSendBuffer; - delete [] fReceiveBuffer; -} - -/*! - \brief Sets the sender port to the passed ID - \param port ID of the new sender port - - If the port ID is not valid, the Session will not send messages until a valid - port ID is passed to it. -*/ -void BSession::SetSendPort( port_id port ) -{ - port_info pi; - - if( get_port_info(port,&pi) != B_OK ) - fSendPort=0; - else - fSendPort=port; -} - -/*! - \brief Sets the receiver port to the passed ID - \param port ID of the new receiver port - - If the port ID is not valid, the Session will not receive messages until a valid - port ID is passed to it. -*/ -void BSession::SetRecvPort( port_id port ) -{ - port_info pi; - - if( get_port_info(port,&pi) != B_OK ) - fReceivePort=0; - else - fReceivePort=port; -} - -/*! - \brief Returns a copy of the string in the message buffer - \return A new string from the message buffer - - Caller is responsible for deleting the pointer -*/ -char *BSession::ReadString(void) -{ - int16 len = 0; - char *str = NULL; - - ReadData(&len, sizeof(int16)); - - if(len > 0) - { - str = new char[len]; - ReadData(str, len); - } - return str; -} - -/*! - \brief Reads a boolean value from the message buffer - \param b boolean variable to receive the value -*/ -void BSession::ReadBool( bool* b ) -{ - ReadData( b, sizeof(bool) ); -} - -/*! - \brief Reads an 8-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadInt8( int8* i ) -{ - ReadData( i, sizeof(int8) ); -} - -/*! - \brief Reads an unsigned 8-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadUInt8( uint8* i ) -{ - ReadData( i, sizeof(uint8) ); -} - -/*! - \brief Reads an 16-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadInt16( int16* i ) -{ - ReadData( i, sizeof(int16) ); -} - -/*! - \brief Reads an unsigned 16-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadUInt16( uint16* i ) -{ - ReadData( i, sizeof(uint16) ); -} - -/*! - \brief Reads an 32-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadInt32( int32* i ) -{ - ReadData( i, sizeof(int32) ); -} - -/*! - \brief Reads an unsigned 32-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadUInt32( uint32* i ) -{ - ReadData( i, sizeof(uint32) ); -} - -/*! - \brief Reads an 64-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadInt64( int64* i ) -{ - ReadData( i, sizeof(int64) ); -} - -/*! - \brief Reads an unisgned 64-bit integer value from the message buffer - \param i integer variable to receive the value -*/ -void BSession::ReadUInt64( uint64* i ) -{ - ReadData( i, sizeof(uint64) ); -} - -/*! - \brief Reads a floating point value from the message buffer - \param f floating point variable to receive the value -*/ -void BSession::ReadFloat(float *f) -{ - ReadData(f, sizeof(float)); -} - -/*! - \brief Reads a 32-bit integer value into a floating point variable - \param f floating point variable to receive the value -*/ -void BSession::ReadFloatFromInt32(float *f) -{ - int32 i; - ReadData( &i, sizeof(int32)); - *f = (float)i; -} - -/*! - \brief Reads a double precision value into a double precision variable - \param d double precision variable to receive the value -*/ -void BSession::ReadDouble(double *d) -{ - ReadData(d, sizeof(double)); -} - -/*! - \brief Reads a 64-bit integer value into a double precision variable - \param d double precision variable to receive the value -*/ -void BSession::ReadDoubleFromInt64(double *d) -{ - int64 i; - ReadData( &i, sizeof(int64)); - *d = (double)i; -} - -/*! - \brief Reads a BPoint value from the message buffer - \param point BPoint variable to receive the value -*/ -void BSession::ReadPoint(BPoint *point) -{ - ReadData( point, sizeof(BPoint)); -} - -/*! - \brief Reads a BPoint value from two 32-bit integers in the message buffer - \param point BPoint variable to receive the values -*/ -void BSession::ReadPointFromInts(BPoint *point) -{ - int32 ipoint[2]; - ReadData( &ipoint, 2 * sizeof(int32)); - point->x = (float)ipoint[0]; - point->y = (float)ipoint[1]; -} - -/*! - \brief Reads a clipping_rect from the message buffer - \param rect clipping_rect variable to receive the value -*/ -void BSession::ReadRectCR(clipping_rect *rect) -{ - ReadData( rect, sizeof(clipping_rect)); -} - -/*! - \brief Reads a BRect value from the message buffer - \param rect BRect variable to receive the value -*/ -void BSession::ReadRect(BRect *rect) -{ - ReadData( rect, sizeof(BRect)); -} - -/*! - \brief Reads a BRect from four 32-bit integers in the message buffer - \param rect BRect variable to receive the values -*/ -void BSession::ReadRectFromInts(BRect *rect) -{ - int32 irect[4]; - ReadData( irect, 4 * sizeof(int32)); - rect->left = (float)irect[0]; - rect->top = (float)irect[1]; - rect->right = (float)irect[2]; - rect->bottom = (float)irect[3]; -} - -/*! - \brief Generic data-reading function - \param data buffer to receive data - \param size number of bytes to read from the message buffer - - This function fails if the receiver port ID is invalid or if the data pointer - is NULL. This function will cause a crash if the buffer size is less than size. -*/ -void BSession::ReadData( void *data, int32 size) -{ - if(!data) - return; - - // 0 = no receive port - Don't try to receive any data - if ( fReceivePort == 0 ) - return; - - while (size > 0) - { - while (fReceiveSize == fReceivePosition) - { - ssize_t portSize; - portSize = port_buffer_size(fReceivePort); - - if (portSize == B_BAD_PORT_ID) - return; - else - fReceiveSize= (portSize > SESSION_BUFFER_SIZE)? SESSION_BUFFER_SIZE: portSize; - - ssize_t rv; - do - { - rv = read_port(fReceivePort, &fRecvCode, fReceiveBuffer, SESSION_BUFFER_SIZE); - - #ifdef DEBUG_BSESSION - if (fRecvCode != AS_SERVER_SESSION && fRecvCodw != AS_SERVER_PORTLINK) - { - printf("BSession received a message not using BSession/PortLink protocol"); - printf("offset: %ld", fRecvCode - SERVER_TRUE); - } - printf("did read something...\n"); - #endif - - } while( fRecvCode != AS_SERVER_SESSION && fRecvCode != AS_SERVER_PORTLINK ); - - fReceivePosition = 0; - - if( rv == B_BAD_PORT_ID ) - { - fReceivePort=0; - return; - } - } - - int32 copySize = fReceiveSize - fReceivePosition; - - if (size < copySize) - copySize = size; - - memcpy(data, fReceiveBuffer + fReceivePosition, copySize); - - // workaround for: data += copySize - uint8 *d = (uint8*)data; - d += copySize; - data = d; - - size -= copySize; - fReceivePosition += copySize; - } -} - -/*! - \brief Adds a string to the message buffer. - \param string string to copy - - Internally speaking, the length of the string is written as a 16-bit integer immediately - prior to the actual string. - - This function will fail if the pointer is NULL. -*/ -void BSession::WriteString(const char *string) -{ - int16 len = (int16)strlen(string) + 1; - - WriteData(&len, sizeof(int16)); - WriteData(string, len); -} - -/*! - \brief Adds a boolean value to the message buffer. - \param b boolean value to add to the buffer -*/ -void BSession::WriteBool(const bool& b) -{ - WriteData(&b, sizeof(bool)); -} - -/*! - \brief Adds an 8-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteInt8(const int8& i) -{ - WriteData(&i, sizeof(int8)); -} - -/*! - \brief Adds an unsigned 8-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteUInt8(const uint8& i) -{ - WriteData(&i, sizeof(uint8)); -} - -/*! - \brief Adds a 16-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteInt16(const int16& i) -{ - WriteData(&i, sizeof(int16)); -} - -/*! - \brief Adds an unsigned 16-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteUInt16(const uint16& i) -{ - WriteData(&i, sizeof(uint16)); -} - -/*! - \brief Adds a 32-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteInt32(const int32& i) -{ - WriteData(&i, sizeof(int32)); -} - -/*! - \brief Adds an unsigned 32-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteUInt32(const uint32& i) -{ - WriteData(&i, sizeof(uint32)); -} - -/*! - \brief Adds a 64-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteInt64(const int64& i) -{ - WriteData(&i, sizeof(int64)); -} - -/*! - \brief Adds an unsigned 64-bit integer value to the message buffer. - \param i integer value to add to the buffer -*/ -void BSession::WriteUInt64(const uint64& i) -{ - WriteData(&i, sizeof(uint64)); -} - -/*! - \brief Adds a floating point value to the message buffer. - \param f floating point value to add to the buffer -*/ -void BSession::WriteFloat(const float& f) -{ - WriteData(&f, sizeof(float)); -} - -/*! - \brief Adds a floating point value to the message buffer as a 32-bit integer - \param f floating point value to add to the buffer -*/ -void BSession::WriteFloatAsInt32(const float& f) -{ - int32 i; - i = (int32)f; - WriteData(&i, sizeof(int32)); -} - -/*! - \brief Adds a double precision value to the message buffer. - \param d double precision value to add to the buffer -*/ -void BSession::WriteDouble(const double& d) -{ - WriteData(&d, sizeof(double)); -} - -/*! - \brief Adds a double precision value to the message buffer as a 64-bit integer - \param d double precision value to add to the buffer -*/ -void BSession::WriteDoubleAsInt64(const double& d) -{ - int64 i; - i = (int64)d; - WriteData(&i, sizeof(int64)); -} - -/*! - \brief Adds a BPoint to the message buffer. - \param point BPoint to add to the buffer -*/ -void BSession::WritePoint(const BPoint& point) -{ - WriteData(&point, sizeof(BPoint)); -} - -/*! - \brief Adds a BPoint to the message buffer as two 32-bit integers - \param point BPoint to add to the buffer -*/ -void BSession::WritePointAsInt32s(const BPoint& point) -{ - int32 ipoint[2]; - ipoint[0] = (int32)point.x; - ipoint[1] = (int32)point.y; - WriteData(ipoint, 2 * sizeof(int32)); -} - -/*! - \brief Adds a clipping_rect to the message buffer. - \param rect clipping_rect to add to the buffer -*/ -void BSession::WriteRect(const clipping_rect& rect) -{ - WriteData(&rect, sizeof(clipping_rect)); -} - -/*! - \brief Adds a BRect to the message buffer as four 32-bit integers - \param rect BRect to add to the buffer -*/ -void BSession::WriteRectAsInt32s(const BRect& rect) -{ - int32 irect[4]; - irect[0] = (int32)floor(rect.left); - irect[1] = (int32)floor(rect.top); - irect[2] = (int32)floor(rect.right); - irect[3] = (int32)floor(rect.bottom); - WriteData(&irect, 4 * sizeof(int32)); -} - -/*! - \brief Adds a BRect to the message buffer. - \param rect BRect to add to the buffer -*/ -void BSession::WriteRect(const BRect& rect) -{ - WriteData(&rect, sizeof(BRect)); -} - -/*! - \brief Generic data-writing function - \param data buffer to write to the message buffer - \param size number of bytes to write to the message buffer - - This function fails if the receiver port ID is invalid or if the data pointer - is NULL. This function will cause a crash if the buffer size is less than size. -*/ -void BSession::WriteData(const void *data, int32 size) -{ - if(!data) - return; - - // 0 = no send port - Don't send any data - if ( fSendPort == 0 ) - return; - - if (size <= 0) - return; - - if (SESSION_BUFFER_SIZE - fSendPosition > size) - { - memcpy(fSendBuffer + fSendPosition, data, size); - fSendPosition += size; - return; - } - - status_t rv; - do - { - int32 copySize = SESSION_BUFFER_SIZE - fSendPosition; - - if (size < copySize) - copySize = size; - - memcpy(fSendBuffer + fSendPosition, data, copySize); - - // workaround for: data += copySize - uint8 *d = (uint8*)data; - d += copySize; - data = d; - - size -= copySize; - fSendPosition += copySize; - - if (fSendPosition != SESSION_BUFFER_SIZE) - return; - - rv = write_port(fSendPort, AS_SERVER_SESSION, fSendBuffer, fSendPosition); - - fSendPosition = 0; - - if (rv == B_BAD_PORT_ID) - return; - - } while (size > 0); -} - -//! Flushes the message cache -void BSession::Sync(void) -{ - if (fSendPosition <= 0) - return; - - status_t rv; - rv = write_port(fSendPort, AS_SERVER_SESSION, fSendBuffer, fSendPosition); - - fSendPosition = 0; -} - -/*! - \brief Directly copies the passed buffer to the message buffer - \param buffer The buffer to copy - \count count currently unused - - Use of this function is discouraged wherever possible -*/ -void BSession::CopyToSendBuffer(void* buffer, int32 count) -{ - // Note: 'count' is there because of future modifications to PortLink class - int32 code; - int32 size; - - uint8 *buf = (uint8*)buffer; - - code = *((int32*)buf); - size = *((int32*)(buf+sizeof(int32))); - //size = count; - - *((int32*)fSendBuffer) = code; - - fSendPosition = sizeof(int32); // = 4 - - int32 compensated_buffer_size=SESSION_BUFFER_SIZE-sizeof(int32); - - memcpy( fSendBuffer + sizeof(int32), - buf + 2*sizeof(int32), - size > compensated_buffer_size? compensated_buffer_size : size); - - fSendPosition += size > compensated_buffer_size? compensated_buffer_size : size; -} diff --git a/src/servers/app/LayerData.cpp b/src/servers/app/LayerData.cpp index 0a3d1c0887..53bf071518 100644 --- a/src/servers/app/LayerData.cpp +++ b/src/servers/app/LayerData.cpp @@ -15,8 +15,8 @@ #include -#include "LinkMsgReader.h" -#include "LinkMsgSender.h" +#include "LinkReceiver.h" +#include "LinkSender.h" #include "LayerData.h" diff --git a/src/servers/app/RAMLinkMsgReader.h b/src/servers/app/RAMLinkMsgReader.h index fe93722b3f..9243d01b43 100644 --- a/src/servers/app/RAMLinkMsgReader.h +++ b/src/servers/app/RAMLinkMsgReader.h @@ -26,7 +26,7 @@ #ifndef RAM_LINK_MSG_READER_H #define RAM_LINK_MSG_READER_H -#include +#include /* This class is somewhat an inheritance hack to avoid some *serious* code