1750b92faSAxel Dörfler/*
2750b92faSAxel Dörfler * Copyright 2001-2005, Haiku.
3750b92faSAxel Dörfler * Distributed under the terms of the MIT License.
4750b92faSAxel Dörfler *
5750b92faSAxel Dörfler * Authors:
6750b92faSAxel Dörfler *		DarkWyrm <bpmagic@columbus.rr.com>
7750b92faSAxel Dörfler *		Pahtz <pahtz@yahoo.com.au>
8750b92faSAxel Dörfler *		Axel D��rfler, axeld@pinc-software.de
9750b92faSAxel Dörfler */
101156138bSAxel Dörfler#ifndef _LINK_SENDER_H
111156138bSAxel Dörfler#define _LINK_SENDER_H
1267e2a74dSDarkWyrm
1367e2a74dSDarkWyrm
14750b92faSAxel Dörfler#include <OS.h>
1567e2a74dSDarkWyrm
1667e2a74dSDarkWyrm
17dd10337fSAxel Dörflernamespace BPrivate {
1867e2a74dSDarkWyrm
19dd10337fSAxel Dörflerclass LinkSender {
20750b92faSAxel Dörfler	public:
21dd10337fSAxel Dörfler		LinkSender(port_id sendport);
22dd10337fSAxel Dörfler		virtual ~LinkSender(void);
2367e2a74dSDarkWyrm
24750b92faSAxel Dörfler		void SetPort(port_id port);
25cee04e80SArtur Wyszynski		port_id	Port() const { return fPort; }
2667e2a74dSDarkWyrm
27b13b0b0fSIthamar R. Adema		team_id TargetTeam() const;
28b13b0b0fSIthamar R. Adema		void SetTargetTeam(team_id team);
29b13b0b0fSIthamar R. Adema
30750b92faSAxel Dörfler		status_t StartMessage(int32 code, size_t minSize = 0);
31750b92faSAxel Dörfler		void CancelMessage(void);
32750b92faSAxel Dörfler		status_t EndMessage(bool needsReply = false);
3367e2a74dSDarkWyrm
34750b92faSAxel Dörfler		status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false);
3567e2a74dSDarkWyrm
36750b92faSAxel Dörfler		status_t Attach(const void *data, size_t size);
37f46e077cSAxel Dörfler		status_t AttachString(const char *string, int32 maxLength = -1);
38750b92faSAxel Dörfler		template <class Type> status_t Attach(const Type& data)
39750b92faSAxel Dörfler		{
40750b92faSAxel Dörfler			return Attach(&data, sizeof(Type));
41750b92faSAxel Dörfler		}
42750b92faSAxel Dörfler
43750b92faSAxel Dörfler	protected:
44750b92faSAxel Dörfler		size_t SpaceLeft() const { return fBufferSize - fCurrentEnd; }
45750b92faSAxel Dörfler		size_t CurrentMessageSize() const { return fCurrentEnd - fCurrentStart; }
46750b92faSAxel Dörfler
47750b92faSAxel Dörfler		status_t AdjustBuffer(size_t newBufferSize, char **_oldBuffer = NULL);
48750b92faSAxel Dörfler		status_t FlushCompleted(size_t newBufferSize);
49750b92faSAxel Dörfler
50750b92faSAxel Dörfler		port_id	fPort;
514f85bc9fSRene Gollent		team_id fTargetTeam;
52750b92faSAxel Dörfler
53750b92faSAxel Dörfler		char	*fBuffer;
54750b92faSAxel Dörfler		size_t	fBufferSize;
55750b92faSAxel Dörfler
56750b92faSAxel Dörfler		uint32	fCurrentEnd;		// current append position
57750b92faSAxel Dörfler		uint32	fCurrentStart;		// start of current message
58750b92faSAxel Dörfler
59750b92faSAxel Dörfler		status_t fCurrentStatus;
6067e2a74dSDarkWyrm};
6167e2a74dSDarkWyrm
62b13b0b0fSIthamar R. Adema
63b13b0b0fSIthamar R. Ademainline team_id
64b13b0b0fSIthamar R. AdemaLinkSender::TargetTeam() const
65b13b0b0fSIthamar R. Adema{
66b13b0b0fSIthamar R. Adema	return fTargetTeam;
67b13b0b0fSIthamar R. Adema}
68b13b0b0fSIthamar R. Adema
69b13b0b0fSIthamar R. Adema
70b13b0b0fSIthamar R. Ademainline void
71b13b0b0fSIthamar R. AdemaLinkSender::SetTargetTeam(team_id team)
72b13b0b0fSIthamar R. Adema{
73b13b0b0fSIthamar R. Adema	fTargetTeam = team;
74b13b0b0fSIthamar R. Adema}
75b13b0b0fSIthamar R. Adema
76dd10337fSAxel Dörfler}	// namespace BPrivate
7767e2a74dSDarkWyrm
781156138bSAxel Dörfler#endif	/* _LINK_SENDER_H */
79