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(®ion->count, sizeof(long)); 38 fReceiver->Read(®ion->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 ®ion) 46 { 47 fSender->Attach(®ion.count, sizeof(long)); 48 fSender->Attach(®ion.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 fReceiver->Read(opList, opCount * sizeof(uint32)); 62 63 BPoint ptList[ptCount]; 64 fReceiver->Read(ptList, ptCount * sizeof(BPoint)); 65 66 shape->SetData(opCount, ptCount, opList, ptList); 67 return B_OK; 68 } 69 70 71 status_t 72 ServerLink::AttachShape(BShape &shape) 73 { 74 int32 opCount, ptCount; 75 uint32 *opList; 76 BPoint *ptList; 77 78 shape.GetData(&opCount, &ptCount, &opList, &ptList); 79 80 fSender->Attach(&opCount, sizeof(int32)); 81 fSender->Attach(&ptCount, sizeof(int32)); 82 fSender->Attach(opList, opCount * sizeof(uint32)); 83 return fSender->Attach(ptList, ptCount * sizeof(BPoint)); 84 } 85 86 87 status_t 88 ServerLink::FlushWithReply(int32 &code) 89 { 90 status_t status = Flush(B_INFINITE_TIMEOUT, true); 91 if (status < B_OK) 92 return status; 93 94 return GetNextMessage(code); 95 } 96 97 } // namespace BPrivate 98