xref: /haiku/headers/private/app/LinkReceiver.h (revision cbe35e2031cb2bfb757422f35006bb9bd382bed1)
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 NeedsReply() const;
31 		int32 Code() const;
32 
33 		virtual status_t Read(void *data, ssize_t size);
34 		status_t ReadString(char **string);
35 		status_t ReadString(BString& string);
36 		status_t ReadString(char *buffer, size_t bufferSize);
37 		template <class Type> status_t Read(Type *data)
38 		{
39 			return Read(data, sizeof(Type));
40 		}
41 
42 	protected:
43 		virtual status_t ReadFromPort(bigtime_t timeout);
44 		virtual status_t AdjustReplyBuffer(bigtime_t timeout);
45 		void ResetBuffer();
46 
47 		port_id fReceivePort;
48 
49 		char	*fRecvBuffer;
50 		int32	fRecvPosition;	//current read position
51 		int32	fRecvStart;	//start of current message
52 		int32	fRecvBufferSize;
53 
54 		int32	fDataSize;	//size of data in recv buffer
55 		int32	fReplySize;	//size of current reply message
56 
57 		status_t fReadError;	//Read failed for current message
58 };
59 
60 }	// namespace BPrivate
61 
62 #endif	// _LINK_RECEIVER_H
63