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->fCount, sizeof(long)); 38 fReceiver->Read(®ion->fBounds, sizeof(clipping_rect)); 39 if (!region->_SetSize(region->fCount)) 40 return B_NO_MEMORY; 41 return fReceiver->Read(region->fData, 42 region->fCount * sizeof(clipping_rect)); 43 } 44 45 46 status_t 47 ServerLink::AttachRegion(const BRegion ®ion) 48 { 49 fSender->Attach(®ion.fCount, sizeof(long)); 50 fSender->Attach(®ion.fBounds, sizeof(clipping_rect)); 51 return fSender->Attach(region.fData, 52 region.fCount * sizeof(clipping_rect)); 53 } 54 55 56 status_t 57 ServerLink::ReadShape(BShape *shape) 58 { 59 int32 opCount, ptCount; 60 fReceiver->Read(&opCount, sizeof(int32)); 61 fReceiver->Read(&ptCount, sizeof(int32)); 62 63 uint32 opList[opCount]; 64 if (opCount > 0) 65 fReceiver->Read(opList, opCount * sizeof(uint32)); 66 67 BPoint ptList[ptCount]; 68 if (ptCount > 0) 69 fReceiver->Read(ptList, ptCount * sizeof(BPoint)); 70 71 shape->SetData(opCount, ptCount, opList, ptList); 72 return B_OK; 73 } 74 75 76 status_t 77 ServerLink::AttachShape(BShape &shape) 78 { 79 int32 opCount, ptCount; 80 uint32 *opList; 81 BPoint *ptList; 82 83 shape.GetData(&opCount, &ptCount, &opList, &ptList); 84 85 fSender->Attach(&opCount, sizeof(int32)); 86 fSender->Attach(&ptCount, sizeof(int32)); 87 if (opCount > 0) 88 fSender->Attach(opList, opCount * sizeof(uint32)); 89 if (ptCount > 0) 90 fSender->Attach(ptList, ptCount * sizeof(BPoint)); 91 return B_OK; 92 } 93 94 95 status_t 96 ServerLink::FlushWithReply(int32 &code) 97 { 98 status_t status = Flush(B_INFINITE_TIMEOUT, true); 99 if (status < B_OK) 100 return status; 101 102 return GetNextMessage(code); 103 } 104 105 } // namespace BPrivate 106