diff --git a/headers/private/app/LinkMsgReader.h b/headers/private/app/LinkMsgReader.h new file mode 100644 index 0000000000..21621155a3 --- /dev/null +++ b/headers/private/app/LinkMsgReader.h @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, 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: LinkMsgReader.h +// Author: DarkWyrm +// Pahtz +// Description: Class for receiving low-overhead port-based messages +// +//------------------------------------------------------------------------------ +#ifndef _LINKMSGREADER_H +#define _LINKMSGREADER_H + +#include + +class LinkMsgReader +{ +public: + LinkMsgReader(port_id port); + virtual ~LinkMsgReader(void); + + virtual void SetPort(port_id port); + virtual port_id GetPort(void); + + virtual status_t GetNextMessage(int32 *code, bigtime_t timeout = B_INFINITE_TIMEOUT); + virtual status_t Read(void *data, ssize_t size); + virtual status_t ReadString(char **string); + template status_t Read(Type *data) + { + return Read(data, sizeof(Type)); + } + +protected: + virtual status_t ReadFromPort(bigtime_t timeout); + virtual status_t AdjustReplyBuffer(bigtime_t timeout); + void ResetBuffer(); + + 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 + int32 fReplySize; //size of current reply message + + status_t fReadError; //Read failed for current message +}; + +#endif diff --git a/headers/private/app/LinkMsgSender.h b/headers/private/app/LinkMsgSender.h new file mode 100644 index 0000000000..ce6cdca83b --- /dev/null +++ b/headers/private/app/LinkMsgSender.h @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// 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: LinkMsgSender.h +// Author: DarkWyrm +// Pahtz +// Description: Class for sending low-overhead port-based messaging +// +//------------------------------------------------------------------------------ +#ifndef LINKMSGSENDER_H +#define LINKMSGSENDER_H + +#include + +class LinkMsgSender +{ +public: + LinkMsgSender(port_id sendport); + virtual ~LinkMsgSender(void); + + status_t StartMessage(int32 code); + void CancelMessage(void); + status_t EndMessage(void); + + status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT); + + // see BPrivate::BAppServerLink which inherits from BPortLink + //status_t FlushWithReply(int32 *code); + + void SetPort(port_id port); + port_id GetPort(); + + status_t Attach(const void *data, ssize_t size); + status_t AttachString(const char *string); + template status_t Attach(const Type& data) + { + return Attach(&data, sizeof(Type)); + } + +protected: + status_t FlushCompleted(ssize_t newbuffersize); + status_t AdjustReplyBuffer(bigtime_t timeout); + void ResetReplyBuffer(); + + port_id fSendPort; + + char *fSendBuffer; + + int32 fSendPosition; //current append position + + int32 fSendStart; //start of current message + + int32 fSendBufferSize; + + int32 fSendCount; //number of completed messages in buffer + + int32 fDataSize; //size of data in recv buffer + int32 fReplySize; //size of current reply message + + status_t fWriteError; //Attach failed for current message +}; + + +#endif diff --git a/headers/private/app/PortLink.h b/headers/private/app/PortLink.h index 8f2c7436fa..29da78f5cc 100644 --- a/headers/private/app/PortLink.h +++ b/headers/private/app/PortLink.h @@ -29,6 +29,8 @@ #define _PORTLINK_H #include +#include +#include /* Error checking rules: (for if you don't want to check every return code) @@ -57,11 +59,9 @@ public: status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT); - // see BPrivate::BAppServerLink which inherits from BPortLink - //status_t FlushWithReply(int32 *code); - void SetSendPort(port_id port); port_id GetSendPort(); + void SetReplyPort(port_id port); port_id GetReplyPort(); @@ -75,39 +75,14 @@ public: status_t GetNextReply(int32 *code, bigtime_t timeout = B_INFINITE_TIMEOUT); status_t Read(void *data, ssize_t size); status_t ReadString(char **string); - template status_t Read(Type *data) + template status_t Read(T *data) { - return Read(data, sizeof(Type)); + return fReader->Read(data,sizeof(T)); } protected: - status_t FlushCompleted(ssize_t newbuffersize); - status_t ReadFromPort(bigtime_t timeout); - status_t AdjustReplyBuffer(bigtime_t timeout); - void ResetReplyBuffer(); - - port_id fSendPort; - port_id fReceivePort; - - char *fSendBuffer; - char *fRecvBuffer; - - int32 fSendPosition; //current append position - int32 fRecvPosition; //current read position - - int32 fSendStart; //start of current message - int32 fRecvStart; //start of current message - - int32 fSendBufferSize; - int32 fRecvBufferSize; - - int32 fSendCount; //number of completed messages in buffer - - int32 fDataSize; //size of data in recv buffer - int32 fReplySize; //size of current reply message - - status_t fWriteError; //Attach failed for current message - status_t fReadError; //Read failed for current message + LinkMsgReader *fReader; + LinkMsgSender *fSender; }; #endif diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index 36b91a7840..757b391588 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -32,6 +32,7 @@ AS_DELETE_BITMAP, AS_ACQUIRE_SERVERMEM, AS_RELEASE_SERVERMEM, +AS_AREA_MESSAGE, // Cursor definitions AS_SET_CURSOR_DATA,