1 /* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Pahtz <pahtz@yahoo.com.au> 8 * Axel Dörfler, axeld@pinc-software.de 9 */ 10 #ifndef _LINK_RECEIVER_H 11 #define _LINK_RECEIVER_H 12 13 14 #include <OS.h> 15 16 class BString; 17 class BRegion; 18 19 20 namespace BPrivate { 21 22 class LinkReceiver { 23 public: 24 LinkReceiver(port_id port); 25 virtual ~LinkReceiver(void); 26 27 void SetPort(port_id port); 28 port_id Port(void) { return fReceivePort; } 29 30 status_t GetNextMessage(int32& code, bigtime_t timeout = B_INFINITE_TIMEOUT); 31 bool HasMessages() const; 32 bool NeedsReply() const; 33 int32 Code() const; 34 35 virtual status_t Read(void* data, ssize_t size); 36 status_t ReadString(char** _string, size_t* _length = NULL); 37 status_t ReadString(BString& string, size_t* _length = NULL); 38 status_t ReadString(char* buffer, size_t bufferSize); 39 status_t ReadRegion(BRegion* region); 40 41 template <class Type> status_t Read(Type *data) 42 { return Read(data, sizeof(Type)); } 43 44 protected: 45 virtual status_t ReadFromPort(bigtime_t timeout); 46 virtual status_t AdjustReplyBuffer(bigtime_t timeout); 47 void ResetBuffer(); 48 49 port_id fReceivePort; 50 51 char* fRecvBuffer; 52 int32 fRecvPosition; //current read position 53 int32 fRecvStart; //start of current message 54 int32 fRecvBufferSize; 55 56 int32 fDataSize; //size of data in recv buffer 57 int32 fReplySize; //size of current reply message 58 59 status_t fReadError; //Read failed for current message 60 }; 61 62 } // namespace BPrivate 63 64 #endif // _LINK_RECEIVER_H 65