1750b92faSAxel Dörfler/*
22ed942c1SAxel Dörfler * Copyright 2001-2006, Haiku.
3750b92faSAxel Dörfler * Distributed under the terms of the MIT License.
4750b92faSAxel Dörfler *
5750b92faSAxel Dörfler * Authors:
6750b92faSAxel Dörfler *		DarkWyrm <bpmagic@columbus.rr.com>
7750b92faSAxel Dörfler *		Pahtz <pahtz@yahoo.com.au>
841572514SAxel Dörfler *		Axel D��rfler, axeld@pinc-software.de
9750b92faSAxel Dörfler */
101156138bSAxel Dörfler#ifndef _LINK_RECEIVER_H
111156138bSAxel Dörfler#define _LINK_RECEIVER_H
1267e2a74dSDarkWyrm
1341572514SAxel Dörfler
1467e2a74dSDarkWyrm#include <OS.h>
1567e2a74dSDarkWyrm
16431dc47dSStephan Aßmus
17431dc47dSStephan Aßmusclass BGradient;
1841572514SAxel Dörflerclass BString;
19600fbd78SStephan Aßmusclass BRegion;
2041572514SAxel Dörfler
21750b92faSAxel Dörfler
22dd10337fSAxel Dörflernamespace BPrivate {
23750b92faSAxel Dörfler
24dd10337fSAxel Dörflerclass LinkReceiver {
25750b92faSAxel Dörfler	public:
26dd10337fSAxel Dörfler		LinkReceiver(port_id port);
27dd10337fSAxel Dörfler		virtual ~LinkReceiver(void);
28750b92faSAxel Dörfler
29750b92faSAxel Dörfler		void SetPort(port_id port);
30cee04e80SArtur Wyszynski		port_id	Port(void) const { return fReceivePort; }
31750b92faSAxel Dörfler
32600fbd78SStephan Aßmus		status_t GetNextMessage(int32& code, bigtime_t timeout = B_INFINITE_TIMEOUT);
331b974d07SAxel Dörfler		bool HasMessages() const;
34bd28b3c7SAxel Dörfler		bool NeedsReply() const;
3586fa5942SAxel Dörfler		int32 Code() const;
36bd28b3c7SAxel Dörfler
37600fbd78SStephan Aßmus		virtual status_t Read(void* data, ssize_t size);
382ed942c1SAxel Dörfler		status_t ReadString(char** _string, size_t* _length = NULL);
392ed942c1SAxel Dörfler		status_t ReadString(BString& string, size_t* _length = NULL);
40600fbd78SStephan Aßmus		status_t ReadString(char* buffer, size_t bufferSize);
41600fbd78SStephan Aßmus		status_t ReadRegion(BRegion* region);
42431dc47dSStephan Aßmus		status_t ReadGradient(BGradient** gradient);
432ed942c1SAxel Dörfler
44750b92faSAxel Dörfler		template <class Type> status_t Read(Type *data)
452ed942c1SAxel Dörfler			{ return Read(data, sizeof(Type)); }
46750b92faSAxel Dörfler
47750b92faSAxel Dörfler	protected:
48750b92faSAxel Dörfler		virtual status_t ReadFromPort(bigtime_t timeout);
49750b92faSAxel Dörfler		virtual status_t AdjustReplyBuffer(bigtime_t timeout);
50750b92faSAxel Dörfler		void ResetBuffer();
51750b92faSAxel Dörfler
52750b92faSAxel Dörfler		port_id fReceivePort;
53750b92faSAxel Dörfler
54600fbd78SStephan Aßmus		char*	fRecvBuffer;
55750b92faSAxel Dörfler		int32	fRecvPosition;	//current read position
56750b92faSAxel Dörfler		int32	fRecvStart;	//start of current message
57750b92faSAxel Dörfler		int32	fRecvBufferSize;
58750b92faSAxel Dörfler
59750b92faSAxel Dörfler		int32	fDataSize;	//size of data in recv buffer
60750b92faSAxel Dörfler		int32	fReplySize;	//size of current reply message
61750b92faSAxel Dörfler
62750b92faSAxel Dörfler		status_t fReadError;	//Read failed for current message
6367e2a74dSDarkWyrm};
6467e2a74dSDarkWyrm
65dd10337fSAxel Dörfler}	// namespace BPrivate
66750b92faSAxel Dörfler
671156138bSAxel Dörfler#endif	// _LINK_RECEIVER_H
68