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