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); Port()25cee04e80SArtur Wyszynski port_id Port() const { return fPort; } 261156138bSAxel Dörfler 27*b13b0b0fSIthamar R. Adema team_id TargetTeam() const; 28*b13b0b0fSIthamar R. Adema void SetTargetTeam(team_id team); 29*b13b0b0fSIthamar R. Adema 301156138bSAxel Dörfler status_t StartMessage(int32 code, size_t minSize = 0); 311156138bSAxel Dörfler void CancelMessage(void); 321156138bSAxel Dörfler status_t EndMessage(bool needsReply = false); 331156138bSAxel Dörfler 341156138bSAxel Dörfler status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); 351156138bSAxel Dörfler 361156138bSAxel Dörfler status_t Attach(const void *data, size_t size); 37f46e077cSAxel Dörfler status_t AttachString(const char *string, int32 maxLength = -1); Attach(const Type & data)381156138bSAxel Dörfler template <class Type> status_t Attach(const Type& data) 391156138bSAxel Dörfler { 401156138bSAxel Dörfler return Attach(&data, sizeof(Type)); 411156138bSAxel Dörfler } 421156138bSAxel Dörfler 431156138bSAxel Dörfler protected: SpaceLeft()441156138bSAxel Dörfler size_t SpaceLeft() const { return fBufferSize - fCurrentEnd; } CurrentMessageSize()451156138bSAxel Dörfler size_t CurrentMessageSize() const { return fCurrentEnd - fCurrentStart; } 461156138bSAxel Dörfler 471156138bSAxel Dörfler status_t AdjustBuffer(size_t newBufferSize, char **_oldBuffer = NULL); 481156138bSAxel Dörfler status_t FlushCompleted(size_t newBufferSize); 491156138bSAxel Dörfler 501156138bSAxel Dörfler port_id fPort; 514f85bc9fSRene Gollent team_id fTargetTeam; 521156138bSAxel Dörfler 531156138bSAxel Dörfler char *fBuffer; 541156138bSAxel Dörfler size_t fBufferSize; 551156138bSAxel Dörfler 561156138bSAxel Dörfler uint32 fCurrentEnd; // current append position 571156138bSAxel Dörfler uint32 fCurrentStart; // start of current message 581156138bSAxel Dörfler 591156138bSAxel Dörfler status_t fCurrentStatus; 601156138bSAxel Dörfler }; 611156138bSAxel Dörfler 62*b13b0b0fSIthamar R. Adema 63*b13b0b0fSIthamar R. Adema inline team_id TargetTeam()64*b13b0b0fSIthamar R. AdemaLinkSender::TargetTeam() const 65*b13b0b0fSIthamar R. Adema { 66*b13b0b0fSIthamar R. Adema return fTargetTeam; 67*b13b0b0fSIthamar R. Adema } 68*b13b0b0fSIthamar R. Adema 69*b13b0b0fSIthamar R. Adema 70*b13b0b0fSIthamar R. Adema inline void SetTargetTeam(team_id team)71*b13b0b0fSIthamar R. AdemaLinkSender::SetTargetTeam(team_id team) 72*b13b0b0fSIthamar R. Adema { 73*b13b0b0fSIthamar R. Adema fTargetTeam = team; 74*b13b0b0fSIthamar R. Adema } 75*b13b0b0fSIthamar R. Adema 761156138bSAxel Dörfler } // namespace BPrivate 771156138bSAxel Dörfler 781156138bSAxel Dörfler #endif /* _LINK_SENDER_H */ 79