xref: /haiku/src/kits/app/PortLink.cpp (revision 39241fe22890fb958b6ba32d6ab9526da98be187)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, Haiku, Inc.
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		PortLink.cpp
23 //	Author:			Pahtz <pahtz@yahoo.com.au>
24 //	Description:	Class for low-overhead port-based messaging
25 //
26 //------------------------------------------------------------------------------
27 #include <stdlib.h>
28 #include <string.h>
29 #include <new>
30 
31 #include <ServerProtocol.h>
32 #include <PortLink.h>
33 
34 BPortLink::BPortLink(port_id send, port_id receive) :
35 	fReader(new LinkMsgReader(receive)), fSender(new LinkMsgSender(send))
36 {
37 }
38 
39 BPortLink::~BPortLink()
40 {
41 	delete fReader;
42 	delete fSender;
43 }
44 
45 status_t BPortLink::StartMessage(int32 code)
46 {
47 	return fSender->StartMessage(code);
48 }
49 
50 status_t BPortLink::EndMessage()
51 {
52 	return fSender->EndMessage();
53 }
54 
55 void BPortLink::CancelMessage()
56 {
57 	fSender->CancelMessage();
58 }
59 
60 status_t BPortLink::Attach(const void *data, ssize_t size)
61 {
62 	return fSender->Attach(data,size);
63 }
64 
65 void BPortLink::SetSendPort( port_id port )
66 {
67 	fSender->SetPort(port);
68 }
69 
70 port_id BPortLink::GetSendPort()
71 {
72 	return fSender->GetPort();
73 }
74 
75 void BPortLink::SetReplyPort( port_id port )
76 {
77 	fReader->SetPort(port);
78 }
79 
80 port_id BPortLink::GetReplyPort()
81 {
82 	return fReader->GetPort();
83 }
84 
85 status_t BPortLink::Flush(bigtime_t timeout)
86 {
87 	return fSender->Flush(timeout);
88 }
89 
90 status_t BPortLink::GetNextReply(int32 *code, bigtime_t timeout)
91 {
92 	return fReader->GetNextMessage(code,timeout);
93 }
94 
95 status_t BPortLink::Read(void *data, ssize_t size)
96 {
97 	return fReader->Read(data,size);
98 }
99 
100 status_t BPortLink::ReadString(char **string)
101 {
102 	return fReader->ReadString(string);
103 }
104 
105 status_t BPortLink::AttachString(const char *string)
106 {
107 	return fSender->AttachString(string);
108 }
109