2005-06-08 02:36:03 +04:00
|
|
|
/*
|
2006-02-27 16:09:37 +03:00
|
|
|
* Copyright 2001-2006, Haiku.
|
2005-06-08 02:36:03 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
* Pahtz <pahtz@yahoo.com.au>
|
2005-11-07 19:14:05 +03:00
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
2005-06-08 02:36:03 +04:00
|
|
|
*/
|
2005-11-02 15:55:20 +03:00
|
|
|
#ifndef _LINK_RECEIVER_H
|
|
|
|
#define _LINK_RECEIVER_H
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-11-07 19:14:05 +03:00
|
|
|
|
2004-10-14 05:18:38 +04:00
|
|
|
#include <OS.h>
|
|
|
|
|
2005-11-07 19:14:05 +03:00
|
|
|
class BString;
|
2006-04-01 20:56:10 +04:00
|
|
|
class BRegion;
|
2005-11-07 19:14:05 +03:00
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
|
2005-06-15 01:28:56 +04:00
|
|
|
namespace BPrivate {
|
2005-06-08 02:36:03 +04:00
|
|
|
|
2005-06-15 01:28:56 +04:00
|
|
|
class LinkReceiver {
|
2005-06-08 02:36:03 +04:00
|
|
|
public:
|
2005-06-15 01:28:56 +04:00
|
|
|
LinkReceiver(port_id port);
|
|
|
|
virtual ~LinkReceiver(void);
|
2005-06-08 02:36:03 +04:00
|
|
|
|
|
|
|
void SetPort(port_id port);
|
|
|
|
port_id Port(void) { return fReceivePort; }
|
|
|
|
|
2006-04-01 20:56:10 +04:00
|
|
|
status_t GetNextMessage(int32& code, bigtime_t timeout = B_INFINITE_TIMEOUT);
|
2005-12-12 16:45:09 +03:00
|
|
|
bool HasMessages() const;
|
2005-06-08 08:01:59 +04:00
|
|
|
bool NeedsReply() const;
|
2005-07-01 10:50:09 +04:00
|
|
|
int32 Code() const;
|
2005-06-08 08:01:59 +04:00
|
|
|
|
2006-04-01 20:56:10 +04:00
|
|
|
virtual status_t Read(void* data, ssize_t size);
|
2006-02-27 16:09:37 +03:00
|
|
|
status_t ReadString(char** _string, size_t* _length = NULL);
|
|
|
|
status_t ReadString(BString& string, size_t* _length = NULL);
|
2006-04-01 20:56:10 +04:00
|
|
|
status_t ReadString(char* buffer, size_t bufferSize);
|
|
|
|
status_t ReadRegion(BRegion* region);
|
2006-02-27 16:09:37 +03:00
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
template <class Type> status_t Read(Type *data)
|
2006-02-27 16:09:37 +03:00
|
|
|
{ return Read(data, sizeof(Type)); }
|
2005-06-08 02:36:03 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual status_t ReadFromPort(bigtime_t timeout);
|
|
|
|
virtual status_t AdjustReplyBuffer(bigtime_t timeout);
|
|
|
|
void ResetBuffer();
|
|
|
|
|
|
|
|
port_id fReceivePort;
|
|
|
|
|
2006-04-01 20:56:10 +04:00
|
|
|
char* fRecvBuffer;
|
2005-06-08 02:36:03 +04:00
|
|
|
int32 fRecvPosition; //current read position
|
|
|
|
int32 fRecvStart; //start of current message
|
|
|
|
int32 fRecvBufferSize;
|
|
|
|
|
|
|
|
int32 fDataSize; //size of data in recv buffer
|
|
|
|
int32 fReplySize; //size of current reply message
|
|
|
|
|
|
|
|
status_t fReadError; //Read failed for current message
|
2004-10-14 05:18:38 +04:00
|
|
|
};
|
|
|
|
|
2005-06-15 01:28:56 +04:00
|
|
|
} // namespace BPrivate
|
2005-06-08 02:36:03 +04:00
|
|
|
|
2005-11-02 15:55:20 +03:00
|
|
|
#endif // _LINK_RECEIVER_H
|