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_SENDER_H 11 #define _LINK_SENDER_H 12 13 14 #include <OS.h> 15 16 17 namespace BPrivate { 18 19 class LinkSender { 20 public: 21 LinkSender(port_id sendport); 22 virtual ~LinkSender(void); 23 24 void SetPort(port_id port); 25 port_id Port() { return fPort; } 26 27 status_t StartMessage(int32 code, size_t minSize = 0); 28 void CancelMessage(void); 29 status_t EndMessage(bool needsReply = false); 30 31 status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); 32 33 status_t Attach(const void *data, size_t size); 34 status_t AttachString(const char *string, int32 maxLength = -1); 35 template <class Type> status_t Attach(const Type& data) 36 { 37 return Attach(&data, sizeof(Type)); 38 } 39 40 protected: 41 size_t SpaceLeft() const { return fBufferSize - fCurrentEnd; } 42 size_t CurrentMessageSize() const { return fCurrentEnd - fCurrentStart; } 43 44 status_t AdjustBuffer(size_t newBufferSize, char **_oldBuffer = NULL); 45 status_t FlushCompleted(size_t newBufferSize); 46 47 port_id fPort; 48 49 char *fBuffer; 50 size_t fBufferSize; 51 52 uint32 fCurrentEnd; // current append position 53 uint32 fCurrentStart; // start of current message 54 55 status_t fCurrentStatus; 56 }; 57 58 } // namespace BPrivate 59 60 #endif /* _LINK_SENDER_H */ 61