xref: /haiku/headers/private/app/LinkSender.h (revision 97901ec593ec4dd50ac115c1c35a6d72f6e489a5)
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() const { return fPort; }
26 
27 		team_id TargetTeam() const;
28 		void SetTargetTeam(team_id team);
29 
30 		status_t StartMessage(int32 code, size_t minSize = 0);
31 		void CancelMessage(void);
32 		status_t EndMessage(bool needsReply = false);
33 
34 		status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false);
35 
36 		status_t Attach(const void *data, size_t size);
37 		status_t AttachString(const char *string, int32 maxLength = -1);
38 		template <class Type> status_t Attach(const Type& data)
39 		{
40 			return Attach(&data, sizeof(Type));
41 		}
42 
43 	protected:
44 		size_t SpaceLeft() const { return fBufferSize - fCurrentEnd; }
45 		size_t CurrentMessageSize() const { return fCurrentEnd - fCurrentStart; }
46 
47 		status_t AdjustBuffer(size_t newBufferSize, char **_oldBuffer = NULL);
48 		status_t FlushCompleted(size_t newBufferSize);
49 
50 		port_id	fPort;
51 		team_id fTargetTeam;
52 
53 		char	*fBuffer;
54 		size_t	fBufferSize;
55 
56 		uint32	fCurrentEnd;		// current append position
57 		uint32	fCurrentStart;		// start of current message
58 
59 		status_t fCurrentStatus;
60 };
61 
62 
63 inline team_id
64 LinkSender::TargetTeam() const
65 {
66 	return fTargetTeam;
67 }
68 
69 
70 inline void
71 LinkSender::SetTargetTeam(team_id team)
72 {
73 	fTargetTeam = team;
74 }
75 
76 }	// namespace BPrivate
77 
78 #endif	/* _LINK_SENDER_H */
79