diff --git a/src/kits/app/LinkReceiver.cpp b/src/kits/app/LinkReceiver.cpp index 27d5219a5b..4928500da7 100644 --- a/src/kits/app/LinkReceiver.cpp +++ b/src/kits/app/LinkReceiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008, Haiku. + * Copyright 2001-2011, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -9,7 +9,9 @@ * Artur Wyszynski */ -/** Class for low-overhead port-based messaging */ + +/*! Class for low-overhead port-based messaging */ + #include @@ -47,6 +49,7 @@ namespace BPrivate { + LinkReceiver::LinkReceiver(port_id port) : fReceivePort(port), fRecvBuffer(NULL), fRecvPosition(0), fRecvStart(0), @@ -233,7 +236,7 @@ LinkReceiver::ReadFromPort(bigtime_t timeout) } while (bytesRead == B_INTERRUPTED); } else { do { - bytesRead = read_port(fReceivePort, &code, fRecvBuffer, + bytesRead = read_port(fReceivePort, &code, fRecvBuffer, fRecvBufferSize); } while (bytesRead == B_INTERRUPTED); } @@ -297,7 +300,7 @@ LinkReceiver::Read(void *data, ssize_t passedSize) if (fReadError >= B_OK) { void* areaAddress = areaInfo.address; - + if (areaAddress && sourceArea >= B_OK) { memcpy(data, areaAddress, passedSize); delete_area(sourceArea); @@ -345,7 +348,7 @@ LinkReceiver::ReadString(char** _string, size_t* _length) if (_length) *_length = length; - + *_string = string; return B_OK; @@ -482,103 +485,106 @@ status_t LinkReceiver::ReadGradient(BGradient** _gradient) { GTRACE(("LinkReceiver::ReadGradient\n")); + BGradient::Type gradientType; int32 colorsCount; - status_t ret; - if ((ret = Read(&gradientType, sizeof(BGradient::Type))) != B_OK) - return ret; - if ((ret = Read(&colorsCount, sizeof(int32))) != B_OK) - return ret; + Read(&gradientType, sizeof(BGradient::Type)); + status_t status = Read(&colorsCount, sizeof(int32)); + if (status != B_OK) + return status; + BGradient* gradient = gradient_for_type(gradientType); if (!gradient) return B_NO_MEMORY; *_gradient = gradient; - + if (colorsCount > 0) { BGradient::ColorStop stop; for (int i = 0; i < colorsCount; i++) { - if ((ret = Read(&stop, sizeof(BGradient::ColorStop))) != B_OK) - return ret; + if ((status = Read(&stop, sizeof(BGradient::ColorStop))) != B_OK) + return status; if (!gradient->AddColorStop(stop, i)) return B_NO_MEMORY; } } - switch(gradientType) { - case BGradient::TYPE_LINEAR: { + switch (gradientType) { + case BGradient::TYPE_LINEAR: + { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_LINEAR\n")); BGradientLinear* linear = (BGradientLinear*)gradient; BPoint start; BPoint end; - if ((ret = Read(&start, sizeof(BPoint))) != B_OK) - return ret; - if ((ret = Read(&end, sizeof(BPoint))) != B_OK) - return ret; + Read(&start, sizeof(BPoint)); + if ((status = Read(&end, sizeof(BPoint))) != B_OK) + return status; linear->SetStart(start); linear->SetEnd(end); return B_OK; } - case BGradient::TYPE_RADIAL: { + case BGradient::TYPE_RADIAL: + { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL\n")); BGradientRadial* radial = (BGradientRadial*)gradient; BPoint center; float radius; - if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) - return ret; - if ((ret = Read(&radius, sizeof(float))) != B_OK) - return ret; + Read(¢er, sizeof(BPoint)); + if ((status = Read(&radius, sizeof(float))) != B_OK) + return status; radial->SetCenter(center); radial->SetRadius(radius); return B_OK; } - case BGradient::TYPE_RADIAL_FOCUS: { + case BGradient::TYPE_RADIAL_FOCUS: + { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL_FOCUS\n")); BGradientRadialFocus* radialFocus = (BGradientRadialFocus*)gradient; BPoint center; BPoint focal; float radius; - if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) - return ret; - if ((ret = Read(&focal, sizeof(BPoint))) != B_OK) - return ret; - if ((ret = Read(&radius, sizeof(float))) != B_OK) - return ret; + Read(¢er, sizeof(BPoint)); + Read(&focal, sizeof(BPoint)); + if ((status = Read(&radius, sizeof(float))) != B_OK) + return status; radialFocus->SetCenter(center); radialFocus->SetFocal(focal); radialFocus->SetRadius(radius); return B_OK; } - case BGradient::TYPE_DIAMOND: { + case BGradient::TYPE_DIAMOND: + { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_DIAMOND\n")); BGradientDiamond* diamond = (BGradientDiamond*)gradient; BPoint center; - if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) - return ret; + if ((status = Read(¢er, sizeof(BPoint))) != B_OK) + return status; diamond->SetCenter(center); return B_OK; } - case BGradient::TYPE_CONIC: { + case BGradient::TYPE_CONIC: + { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_CONIC\n")); BGradientConic* conic = (BGradientConic*)gradient; BPoint center; float angle; - if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) - return ret; - if ((ret = Read(&angle, sizeof(float))) != B_OK) - return ret; + Read(¢er, sizeof(BPoint)); + if ((status = Read(&angle, sizeof(float))) != B_OK) + return status; conic->SetCenter(center); conic->SetAngle(angle); return B_OK; } - case BGradient::TYPE_NONE: { + case BGradient::TYPE_NONE: + { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_NONE\n")); break; } } - + return B_ERROR; } + } // namespace BPrivate diff --git a/src/kits/app/ServerLink.cpp b/src/kits/app/ServerLink.cpp index f2f2fd9466..2c1b2af9f2 100644 --- a/src/kits/app/ServerLink.cpp +++ b/src/kits/app/ServerLink.cpp @@ -70,7 +70,7 @@ ServerLink::ReadRegion(BRegion* region) return fReceiver->Read(region->fData, region->fCount * sizeof(clipping_rect)); } - + return fReceiver->Read(®ion->fBounds, sizeof(clipping_rect)); } @@ -84,7 +84,7 @@ ServerLink::AttachRegion(const BRegion& region) return fSender->Attach(region.fData, region.fCount * sizeof(clipping_rect)); } - + return fSender->Attach(®ion.fBounds, sizeof(clipping_rect)); } @@ -95,15 +95,15 @@ ServerLink::ReadShape(BShape* shape) int32 opCount, ptCount; fReceiver->Read(&opCount, sizeof(int32)); fReceiver->Read(&ptCount, sizeof(int32)); - + uint32 opList[opCount]; if (opCount > 0) fReceiver->Read(opList, opCount * sizeof(uint32)); - + BPoint ptList[ptCount]; if (ptCount > 0) fReceiver->Read(ptList, ptCount * sizeof(BPoint)); - + shape->SetData(opCount, ptCount, opList, ptList); return B_OK; } @@ -115,9 +115,9 @@ 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)); if (opCount > 0) @@ -135,7 +135,7 @@ ServerLink::ReadGradient(BGradient** _gradient) return fReceiver->ReadGradient(_gradient); } - + status_t ServerLink::AttachGradient(const BGradient& gradient) { @@ -152,30 +152,31 @@ ServerLink::AttachGradient(const BGradient& gradient) sizeof(BGradient::ColorStop)); } } - - switch(gradientType) { - case BGradient::TYPE_LINEAR: { + + switch (gradientType) { + case BGradient::TYPE_LINEAR: + { GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n")); - const BGradientLinear* linear = (BGradientLinear*) &gradient; - BPoint start = linear->Start(); - BPoint end = linear->End(); - fSender->Attach(&start, sizeof(BPoint)); - fSender->Attach(&end, sizeof(BPoint)); + const BGradientLinear* linear = (BGradientLinear*)&gradient; + fSender->Attach(linear->Start()); + fSender->Attach(linear->End()); break; } - case BGradient::TYPE_RADIAL: { + case BGradient::TYPE_RADIAL: + { GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n")); - const BGradientRadial* radial = (BGradientRadial*) &gradient; + const BGradientRadial* radial = (BGradientRadial*)&gradient; BPoint center = radial->Center(); float radius = radial->Radius(); fSender->Attach(¢er, sizeof(BPoint)); fSender->Attach(&radius, sizeof(float)); break; } - case BGradient::TYPE_RADIAL_FOCUS: { + case BGradient::TYPE_RADIAL_FOCUS: + { GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n")); - const BGradientRadialFocus* radialFocus = - (BGradientRadialFocus*) &gradient; + const BGradientRadialFocus* radialFocus + = (BGradientRadialFocus*)&gradient; BPoint center = radialFocus->Center(); BPoint focal = radialFocus->Focal(); float radius = radialFocus->Radius(); @@ -184,23 +185,26 @@ ServerLink::AttachGradient(const BGradient& gradient) fSender->Attach(&radius, sizeof(float)); break; } - case BGradient::TYPE_DIAMOND: { + case BGradient::TYPE_DIAMOND: + { GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n")); - const BGradientDiamond* diamond = (BGradientDiamond*) &gradient; + const BGradientDiamond* diamond = (BGradientDiamond*)&gradient; BPoint center = diamond->Center(); fSender->Attach(¢er, sizeof(BPoint)); break; } - case BGradient::TYPE_CONIC: { + case BGradient::TYPE_CONIC: + { GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n")); - const BGradientConic* conic = (BGradientConic*) &gradient; + const BGradientConic* conic = (BGradientConic*)&gradient; BPoint center = conic->Center(); float angle = conic->Angle(); fSender->Attach(¢er, sizeof(BPoint)); fSender->Attach(&angle, sizeof(float)); break; } - case BGradient::TYPE_NONE: { + case BGradient::TYPE_NONE: + { GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n")); break; }