1 /* 2 * Copyright 2001-2005, 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 18 19 namespace BPrivate { 20 21 class LinkReceiver { 22 public: 23 LinkReceiver(port_id port); 24 virtual ~LinkReceiver(void); 25 26 void SetPort(port_id port); 27 port_id Port(void) { return fReceivePort; } 28 29 status_t GetNextMessage(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); 30 bool HasMessages() const; 31 bool NeedsReply() const; 32 int32 Code() const; 33 34 virtual status_t Read(void *data, ssize_t size); 35 status_t ReadString(char **string); 36 status_t ReadString(BString& string); 37 status_t ReadString(char *buffer, size_t bufferSize); 38 template <class Type> status_t Read(Type *data) 39 { 40 return Read(data, sizeof(Type)); 41 } 42 43 protected: 44 virtual status_t ReadFromPort(bigtime_t timeout); 45 virtual status_t AdjustReplyBuffer(bigtime_t timeout); 46 void ResetBuffer(); 47 48 port_id fReceivePort; 49 50 char *fRecvBuffer; 51 int32 fRecvPosition; //current read position 52 int32 fRecvStart; //start of current message 53 int32 fRecvBufferSize; 54 55 int32 fDataSize; //size of data in recv buffer 56 int32 fReplySize; //size of current reply message 57 58 status_t fReadError; //Read failed for current message 59 }; 60 61 } // namespace BPrivate 62 63 #endif // _LINK_RECEIVER_H 64