/* * Copyright 2001-2005, Haiku. * Distributed under the terms of the MIT License. * * Authors: * Pahtz * Axel Dörfler, axeld@pinc-software.de */ /** Class for low-overhead port-based messaging */ #include #include #include #include #include #include #include #include #include namespace BPrivate { ServerLink::ServerLink() { } ServerLink::~ServerLink() { } status_t ServerLink::ReadRegion(BRegion *region) { fReceiver->Read(®ion->count, sizeof(long)); fReceiver->Read(®ion->bound, sizeof(clipping_rect)); region->set_size(region->count + 1); return fReceiver->Read(region->data, region->count * sizeof(clipping_rect)); } status_t ServerLink::AttachRegion(const BRegion ®ion) { fSender->Attach(®ion.count, sizeof(long)); fSender->Attach(®ion.bound, sizeof(clipping_rect)); return fSender->Attach(region.data, region.count * sizeof(clipping_rect)); } status_t ServerLink::ReadShape(BShape *shape) { int32 opCount, ptCount; fReceiver->Read(&opCount, sizeof(int32)); fReceiver->Read(&ptCount, sizeof(int32)); uint32 opList[opCount]; fReceiver->Read(opList, opCount * sizeof(uint32)); BPoint ptList[ptCount]; fReceiver->Read(ptList, ptCount * sizeof(BPoint)); shape->SetData(opCount, ptCount, opList, ptList); return B_OK; } status_t ServerLink::AttachShape(BShape &shape) { int32 opCount, ptCount; uint32 *opList; BPoint *ptList; shape.GetData(&opCount, &ptCount, &opList, &ptList); fSender->Attach(&opCount, sizeof(int32)); fSender->Attach(&ptCount, sizeof(int32)); fSender->Attach(opList, opCount * sizeof(uint32)); return fSender->Attach(ptList, ptCount * sizeof(BPoint)); } status_t ServerLink::FlushWithReply(int32 &code) { status_t status = Flush(B_INFINITE_TIMEOUT, true); if (status < B_OK) return status; return GetNextMessage(code); } // #pragma mark - PortLink::PortLink(port_id send, port_id receive) { fSender = new LinkSender(send); fReceiver = new LinkReceiver(receive); } PortLink::~PortLink() { delete fReceiver; delete fSender; } void PortLink::SetTo(port_id sender, port_id receiver) { fSender->SetPort(sender); fReceiver->SetPort(receiver); } } // namespace BPrivate