11156138bSAxel Dörfler /* 21156138bSAxel Dörfler * Copyright 2001-2005, Haiku. 31156138bSAxel Dörfler * Distributed under the terms of the MIT License. 41156138bSAxel Dörfler * 51156138bSAxel Dörfler * Authors: 61156138bSAxel Dörfler * DarkWyrm <bpmagic@columbus.rr.com> 71156138bSAxel Dörfler * Pahtz <pahtz@yahoo.com.au> 81156138bSAxel Dörfler * Axel Dörfler, axeld@pinc-software.de 91156138bSAxel Dörfler */ 101156138bSAxel Dörfler #ifndef _LINK_SENDER_H 111156138bSAxel Dörfler #define _LINK_SENDER_H 121156138bSAxel Dörfler 131156138bSAxel Dörfler 141156138bSAxel Dörfler #include <OS.h> 151156138bSAxel Dörfler 161156138bSAxel Dörfler 171156138bSAxel Dörfler namespace BPrivate { 181156138bSAxel Dörfler 191156138bSAxel Dörfler class LinkSender { 201156138bSAxel Dörfler public: 211156138bSAxel Dörfler LinkSender(port_id sendport); 221156138bSAxel Dörfler virtual ~LinkSender(void); 231156138bSAxel Dörfler 241156138bSAxel Dörfler void SetPort(port_id port); 251156138bSAxel Dörfler port_id Port() { return fPort; } 261156138bSAxel Dörfler 271156138bSAxel Dörfler status_t StartMessage(int32 code, size_t minSize = 0); 281156138bSAxel Dörfler void CancelMessage(void); 291156138bSAxel Dörfler status_t EndMessage(bool needsReply = false); 301156138bSAxel Dörfler 311156138bSAxel Dörfler status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); 321156138bSAxel Dörfler 331156138bSAxel Dörfler status_t Attach(const void *data, size_t size); 34*f46e077cSAxel Dörfler status_t AttachString(const char *string, int32 maxLength = -1); 351156138bSAxel Dörfler template <class Type> status_t Attach(const Type& data) 361156138bSAxel Dörfler { 371156138bSAxel Dörfler return Attach(&data, sizeof(Type)); 381156138bSAxel Dörfler } 391156138bSAxel Dörfler 401156138bSAxel Dörfler protected: 411156138bSAxel Dörfler size_t SpaceLeft() const { return fBufferSize - fCurrentEnd; } 421156138bSAxel Dörfler size_t CurrentMessageSize() const { return fCurrentEnd - fCurrentStart; } 431156138bSAxel Dörfler 441156138bSAxel Dörfler status_t AdjustBuffer(size_t newBufferSize, char **_oldBuffer = NULL); 451156138bSAxel Dörfler status_t FlushCompleted(size_t newBufferSize); 461156138bSAxel Dörfler 471156138bSAxel Dörfler port_id fPort; 481156138bSAxel Dörfler 491156138bSAxel Dörfler char *fBuffer; 501156138bSAxel Dörfler size_t fBufferSize; 511156138bSAxel Dörfler 521156138bSAxel Dörfler uint32 fCurrentEnd; // current append position 531156138bSAxel Dörfler uint32 fCurrentStart; // start of current message 541156138bSAxel Dörfler 551156138bSAxel Dörfler status_t fCurrentStatus; 561156138bSAxel Dörfler }; 571156138bSAxel Dörfler 581156138bSAxel Dörfler } // namespace BPrivate 591156138bSAxel Dörfler 601156138bSAxel Dörfler #endif /* _LINK_SENDER_H */ 61