2005-06-08 02:36:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2005, Haiku.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
* Pahtz <pahtz@yahoo.com.au>
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
2005-11-02 15:55:20 +03:00
|
|
|
#ifndef _LINK_SENDER_H
|
|
|
|
#define _LINK_SENDER_H
|
2004-10-14 05:18:38 +04:00
|
|
|
|
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
#include <OS.h>
|
2004-10-14 05:18:38 +04:00
|
|
|
|
|
|
|
|
2005-06-15 01:28:56 +04:00
|
|
|
namespace BPrivate {
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-06-15 01:28:56 +04:00
|
|
|
class LinkSender {
|
2005-06-08 02:36:03 +04:00
|
|
|
public:
|
2005-06-15 01:28:56 +04:00
|
|
|
LinkSender(port_id sendport);
|
|
|
|
virtual ~LinkSender(void);
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
void SetPort(port_id port);
|
|
|
|
port_id Port() { return fPort; }
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
status_t StartMessage(int32 code, size_t minSize = 0);
|
|
|
|
void CancelMessage(void);
|
|
|
|
status_t EndMessage(bool needsReply = false);
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false);
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-06-08 02:36:03 +04:00
|
|
|
status_t Attach(const void *data, size_t size);
|
2005-11-09 21:28:13 +03:00
|
|
|
status_t AttachString(const char *string, int32 maxLength = -1);
|
2005-06-08 02:36:03 +04:00
|
|
|
template <class Type> status_t Attach(const Type& data)
|
|
|
|
{
|
|
|
|
return Attach(&data, sizeof(Type));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t SpaceLeft() const { return fBufferSize - fCurrentEnd; }
|
|
|
|
size_t CurrentMessageSize() const { return fCurrentEnd - fCurrentStart; }
|
|
|
|
|
|
|
|
status_t AdjustBuffer(size_t newBufferSize, char **_oldBuffer = NULL);
|
|
|
|
status_t FlushCompleted(size_t newBufferSize);
|
|
|
|
|
|
|
|
port_id fPort;
|
|
|
|
|
|
|
|
char *fBuffer;
|
|
|
|
size_t fBufferSize;
|
|
|
|
|
|
|
|
uint32 fCurrentEnd; // current append position
|
|
|
|
uint32 fCurrentStart; // start of current message
|
|
|
|
|
|
|
|
status_t fCurrentStatus;
|
2004-10-14 05:18:38 +04:00
|
|
|
};
|
|
|
|
|
2005-06-15 01:28:56 +04:00
|
|
|
} // namespace BPrivate
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2005-11-02 15:55:20 +03:00
|
|
|
#endif /* _LINK_SENDER_H */
|