xref: /haiku/src/kits/app/ServerLink.cpp (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /*
2  * Copyright 2001-2005, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Pahtz <pahtz@yahoo.com.au>
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 
10 /** Class for low-overhead port-based messaging */
11 
12 #include <stdlib.h>
13 #include <string.h>
14 #include <new>
15 #include <Region.h>
16 #include <Shape.h>
17 
18 #include <ServerLink.h>
19 #include <ServerProtocol.h>
20 
21 
22 namespace BPrivate {
23 
24 ServerLink::ServerLink()
25 {
26 }
27 
28 
29 ServerLink::~ServerLink()
30 {
31 }
32 
33 
34 status_t
35 ServerLink::ReadRegion(BRegion *region)
36 {
37 	fReceiver->Read(&region->count, sizeof(long));
38 	fReceiver->Read(&region->bound, sizeof(clipping_rect));
39 	region->set_size(region->count + 1);
40 	return fReceiver->Read(region->data, region->count * sizeof(clipping_rect));
41 }
42 
43 
44 status_t
45 ServerLink::AttachRegion(const BRegion &region)
46 {
47 	fSender->Attach(&region.count, sizeof(long));
48 	fSender->Attach(&region.bound, sizeof(clipping_rect));
49 	return fSender->Attach(region.data, region.count * sizeof(clipping_rect));
50 }
51 
52 
53 status_t
54 ServerLink::ReadShape(BShape *shape)
55 {
56 	int32 opCount, ptCount;
57 	fReceiver->Read(&opCount, sizeof(int32));
58 	fReceiver->Read(&ptCount, sizeof(int32));
59 
60 	uint32 opList[opCount];
61 	if (opCount > 0)
62 		fReceiver->Read(opList, opCount * sizeof(uint32));
63 
64 	BPoint ptList[ptCount];
65 	if (ptCount > 0)
66 		fReceiver->Read(ptList, ptCount * sizeof(BPoint));
67 
68 	shape->SetData(opCount, ptCount, opList, ptList);
69 	return B_OK;
70 }
71 
72 
73 status_t
74 ServerLink::AttachShape(BShape &shape)
75 {
76 	int32 opCount, ptCount;
77 	uint32 *opList;
78 	BPoint *ptList;
79 
80 	shape.GetData(&opCount, &ptCount, &opList, &ptList);
81 
82 	fSender->Attach(&opCount, sizeof(int32));
83 	fSender->Attach(&ptCount, sizeof(int32));
84 	if (opCount > 0)
85 		fSender->Attach(opList, opCount * sizeof(uint32));
86 	if (ptCount > 0)
87 		fSender->Attach(ptList, ptCount * sizeof(BPoint));
88 	return B_OK;
89 }
90 
91 
92 status_t
93 ServerLink::FlushWithReply(int32 &code)
94 {
95 	status_t status = Flush(B_INFINITE_TIMEOUT, true);
96 	if (status < B_OK)
97 		return status;
98 
99 	return GetNextMessage(code);
100 }
101 
102 }	// namespace BPrivate
103