* Coding style cleanup.

* The Read() method remembers the last error, so you don't have to check each
  read when you do several in a row.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42789 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2011-09-30 00:02:22 +00:00
parent f74afb8218
commit a35bbf9fb3
2 changed files with 77 additions and 67 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku. * Copyright 2001-2011, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,7 +9,9 @@
* Artur Wyszynski <harakash@gmail.com> * Artur Wyszynski <harakash@gmail.com>
*/ */
/** Class for low-overhead port-based messaging */
/*! Class for low-overhead port-based messaging */
#include <LinkReceiver.h> #include <LinkReceiver.h>
@ -47,6 +49,7 @@
namespace BPrivate { namespace BPrivate {
LinkReceiver::LinkReceiver(port_id port) LinkReceiver::LinkReceiver(port_id port)
: :
fReceivePort(port), fRecvBuffer(NULL), fRecvPosition(0), fRecvStart(0), fReceivePort(port), fRecvBuffer(NULL), fRecvPosition(0), fRecvStart(0),
@ -233,7 +236,7 @@ LinkReceiver::ReadFromPort(bigtime_t timeout)
} while (bytesRead == B_INTERRUPTED); } while (bytesRead == B_INTERRUPTED);
} else { } else {
do { do {
bytesRead = read_port(fReceivePort, &code, fRecvBuffer, bytesRead = read_port(fReceivePort, &code, fRecvBuffer,
fRecvBufferSize); fRecvBufferSize);
} while (bytesRead == B_INTERRUPTED); } while (bytesRead == B_INTERRUPTED);
} }
@ -297,7 +300,7 @@ LinkReceiver::Read(void *data, ssize_t passedSize)
if (fReadError >= B_OK) { if (fReadError >= B_OK) {
void* areaAddress = areaInfo.address; void* areaAddress = areaInfo.address;
if (areaAddress && sourceArea >= B_OK) { if (areaAddress && sourceArea >= B_OK) {
memcpy(data, areaAddress, passedSize); memcpy(data, areaAddress, passedSize);
delete_area(sourceArea); delete_area(sourceArea);
@ -345,7 +348,7 @@ LinkReceiver::ReadString(char** _string, size_t* _length)
if (_length) if (_length)
*_length = length; *_length = length;
*_string = string; *_string = string;
return B_OK; return B_OK;
@ -482,103 +485,106 @@ status_t
LinkReceiver::ReadGradient(BGradient** _gradient) LinkReceiver::ReadGradient(BGradient** _gradient)
{ {
GTRACE(("LinkReceiver::ReadGradient\n")); GTRACE(("LinkReceiver::ReadGradient\n"));
BGradient::Type gradientType; BGradient::Type gradientType;
int32 colorsCount; int32 colorsCount;
status_t ret; Read(&gradientType, sizeof(BGradient::Type));
if ((ret = Read(&gradientType, sizeof(BGradient::Type))) != B_OK) status_t status = Read(&colorsCount, sizeof(int32));
return ret; if (status != B_OK)
if ((ret = Read(&colorsCount, sizeof(int32))) != B_OK) return status;
return ret;
BGradient* gradient = gradient_for_type(gradientType); BGradient* gradient = gradient_for_type(gradientType);
if (!gradient) if (!gradient)
return B_NO_MEMORY; return B_NO_MEMORY;
*_gradient = gradient; *_gradient = gradient;
if (colorsCount > 0) { if (colorsCount > 0) {
BGradient::ColorStop stop; BGradient::ColorStop stop;
for (int i = 0; i < colorsCount; i++) { for (int i = 0; i < colorsCount; i++) {
if ((ret = Read(&stop, sizeof(BGradient::ColorStop))) != B_OK) if ((status = Read(&stop, sizeof(BGradient::ColorStop))) != B_OK)
return ret; return status;
if (!gradient->AddColorStop(stop, i)) if (!gradient->AddColorStop(stop, i))
return B_NO_MEMORY; return B_NO_MEMORY;
} }
} }
switch(gradientType) { switch (gradientType) {
case BGradient::TYPE_LINEAR: { case BGradient::TYPE_LINEAR:
{
GTRACE(("LinkReceiver::ReadGradient> type == TYPE_LINEAR\n")); GTRACE(("LinkReceiver::ReadGradient> type == TYPE_LINEAR\n"));
BGradientLinear* linear = (BGradientLinear*)gradient; BGradientLinear* linear = (BGradientLinear*)gradient;
BPoint start; BPoint start;
BPoint end; BPoint end;
if ((ret = Read(&start, sizeof(BPoint))) != B_OK) Read(&start, sizeof(BPoint));
return ret; if ((status = Read(&end, sizeof(BPoint))) != B_OK)
if ((ret = Read(&end, sizeof(BPoint))) != B_OK) return status;
return ret;
linear->SetStart(start); linear->SetStart(start);
linear->SetEnd(end); linear->SetEnd(end);
return B_OK; return B_OK;
} }
case BGradient::TYPE_RADIAL: { case BGradient::TYPE_RADIAL:
{
GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL\n")); GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL\n"));
BGradientRadial* radial = (BGradientRadial*)gradient; BGradientRadial* radial = (BGradientRadial*)gradient;
BPoint center; BPoint center;
float radius; float radius;
if ((ret = Read(&center, sizeof(BPoint))) != B_OK) Read(&center, sizeof(BPoint));
return ret; if ((status = Read(&radius, sizeof(float))) != B_OK)
if ((ret = Read(&radius, sizeof(float))) != B_OK) return status;
return ret;
radial->SetCenter(center); radial->SetCenter(center);
radial->SetRadius(radius); radial->SetRadius(radius);
return B_OK; return B_OK;
} }
case BGradient::TYPE_RADIAL_FOCUS: { case BGradient::TYPE_RADIAL_FOCUS:
{
GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL_FOCUS\n")); GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL_FOCUS\n"));
BGradientRadialFocus* radialFocus = BGradientRadialFocus* radialFocus =
(BGradientRadialFocus*)gradient; (BGradientRadialFocus*)gradient;
BPoint center; BPoint center;
BPoint focal; BPoint focal;
float radius; float radius;
if ((ret = Read(&center, sizeof(BPoint))) != B_OK) Read(&center, sizeof(BPoint));
return ret; Read(&focal, sizeof(BPoint));
if ((ret = Read(&focal, sizeof(BPoint))) != B_OK) if ((status = Read(&radius, sizeof(float))) != B_OK)
return ret; return status;
if ((ret = Read(&radius, sizeof(float))) != B_OK)
return ret;
radialFocus->SetCenter(center); radialFocus->SetCenter(center);
radialFocus->SetFocal(focal); radialFocus->SetFocal(focal);
radialFocus->SetRadius(radius); radialFocus->SetRadius(radius);
return B_OK; return B_OK;
} }
case BGradient::TYPE_DIAMOND: { case BGradient::TYPE_DIAMOND:
{
GTRACE(("LinkReceiver::ReadGradient> type == TYPE_DIAMOND\n")); GTRACE(("LinkReceiver::ReadGradient> type == TYPE_DIAMOND\n"));
BGradientDiamond* diamond = (BGradientDiamond*)gradient; BGradientDiamond* diamond = (BGradientDiamond*)gradient;
BPoint center; BPoint center;
if ((ret = Read(&center, sizeof(BPoint))) != B_OK) if ((status = Read(&center, sizeof(BPoint))) != B_OK)
return ret; return status;
diamond->SetCenter(center); diamond->SetCenter(center);
return B_OK; return B_OK;
} }
case BGradient::TYPE_CONIC: { case BGradient::TYPE_CONIC:
{
GTRACE(("LinkReceiver::ReadGradient> type == TYPE_CONIC\n")); GTRACE(("LinkReceiver::ReadGradient> type == TYPE_CONIC\n"));
BGradientConic* conic = (BGradientConic*)gradient; BGradientConic* conic = (BGradientConic*)gradient;
BPoint center; BPoint center;
float angle; float angle;
if ((ret = Read(&center, sizeof(BPoint))) != B_OK) Read(&center, sizeof(BPoint));
return ret; if ((status = Read(&angle, sizeof(float))) != B_OK)
if ((ret = Read(&angle, sizeof(float))) != B_OK) return status;
return ret;
conic->SetCenter(center); conic->SetCenter(center);
conic->SetAngle(angle); conic->SetAngle(angle);
return B_OK; return B_OK;
} }
case BGradient::TYPE_NONE: { case BGradient::TYPE_NONE:
{
GTRACE(("LinkReceiver::ReadGradient> type == TYPE_NONE\n")); GTRACE(("LinkReceiver::ReadGradient> type == TYPE_NONE\n"));
break; break;
} }
} }
return B_ERROR; return B_ERROR;
} }
} // namespace BPrivate } // namespace BPrivate

View File

@ -70,7 +70,7 @@ ServerLink::ReadRegion(BRegion* region)
return fReceiver->Read(region->fData, return fReceiver->Read(region->fData,
region->fCount * sizeof(clipping_rect)); region->fCount * sizeof(clipping_rect));
} }
return fReceiver->Read(&region->fBounds, sizeof(clipping_rect)); return fReceiver->Read(&region->fBounds, sizeof(clipping_rect));
} }
@ -84,7 +84,7 @@ ServerLink::AttachRegion(const BRegion& region)
return fSender->Attach(region.fData, return fSender->Attach(region.fData,
region.fCount * sizeof(clipping_rect)); region.fCount * sizeof(clipping_rect));
} }
return fSender->Attach(&region.fBounds, sizeof(clipping_rect)); return fSender->Attach(&region.fBounds, sizeof(clipping_rect));
} }
@ -95,15 +95,15 @@ ServerLink::ReadShape(BShape* shape)
int32 opCount, ptCount; int32 opCount, ptCount;
fReceiver->Read(&opCount, sizeof(int32)); fReceiver->Read(&opCount, sizeof(int32));
fReceiver->Read(&ptCount, sizeof(int32)); fReceiver->Read(&ptCount, sizeof(int32));
uint32 opList[opCount]; uint32 opList[opCount];
if (opCount > 0) if (opCount > 0)
fReceiver->Read(opList, opCount * sizeof(uint32)); fReceiver->Read(opList, opCount * sizeof(uint32));
BPoint ptList[ptCount]; BPoint ptList[ptCount];
if (ptCount > 0) if (ptCount > 0)
fReceiver->Read(ptList, ptCount * sizeof(BPoint)); fReceiver->Read(ptList, ptCount * sizeof(BPoint));
shape->SetData(opCount, ptCount, opList, ptList); shape->SetData(opCount, ptCount, opList, ptList);
return B_OK; return B_OK;
} }
@ -115,9 +115,9 @@ ServerLink::AttachShape(BShape& shape)
int32 opCount, ptCount; int32 opCount, ptCount;
uint32* opList; uint32* opList;
BPoint* ptList; BPoint* ptList;
shape.GetData(&opCount, &ptCount, &opList, &ptList); shape.GetData(&opCount, &ptCount, &opList, &ptList);
fSender->Attach(&opCount, sizeof(int32)); fSender->Attach(&opCount, sizeof(int32));
fSender->Attach(&ptCount, sizeof(int32)); fSender->Attach(&ptCount, sizeof(int32));
if (opCount > 0) if (opCount > 0)
@ -135,7 +135,7 @@ ServerLink::ReadGradient(BGradient** _gradient)
return fReceiver->ReadGradient(_gradient); return fReceiver->ReadGradient(_gradient);
} }
status_t status_t
ServerLink::AttachGradient(const BGradient& gradient) ServerLink::AttachGradient(const BGradient& gradient)
{ {
@ -152,30 +152,31 @@ ServerLink::AttachGradient(const BGradient& gradient)
sizeof(BGradient::ColorStop)); sizeof(BGradient::ColorStop));
} }
} }
switch(gradientType) { switch (gradientType) {
case BGradient::TYPE_LINEAR: { case BGradient::TYPE_LINEAR:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n")); GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n"));
const BGradientLinear* linear = (BGradientLinear*) &gradient; const BGradientLinear* linear = (BGradientLinear*)&gradient;
BPoint start = linear->Start(); fSender->Attach(linear->Start());
BPoint end = linear->End(); fSender->Attach(linear->End());
fSender->Attach(&start, sizeof(BPoint));
fSender->Attach(&end, sizeof(BPoint));
break; break;
} }
case BGradient::TYPE_RADIAL: { case BGradient::TYPE_RADIAL:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n")); GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n"));
const BGradientRadial* radial = (BGradientRadial*) &gradient; const BGradientRadial* radial = (BGradientRadial*)&gradient;
BPoint center = radial->Center(); BPoint center = radial->Center();
float radius = radial->Radius(); float radius = radial->Radius();
fSender->Attach(&center, sizeof(BPoint)); fSender->Attach(&center, sizeof(BPoint));
fSender->Attach(&radius, sizeof(float)); fSender->Attach(&radius, sizeof(float));
break; break;
} }
case BGradient::TYPE_RADIAL_FOCUS: { case BGradient::TYPE_RADIAL_FOCUS:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n")); GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n"));
const BGradientRadialFocus* radialFocus = const BGradientRadialFocus* radialFocus
(BGradientRadialFocus*) &gradient; = (BGradientRadialFocus*)&gradient;
BPoint center = radialFocus->Center(); BPoint center = radialFocus->Center();
BPoint focal = radialFocus->Focal(); BPoint focal = radialFocus->Focal();
float radius = radialFocus->Radius(); float radius = radialFocus->Radius();
@ -184,23 +185,26 @@ ServerLink::AttachGradient(const BGradient& gradient)
fSender->Attach(&radius, sizeof(float)); fSender->Attach(&radius, sizeof(float));
break; break;
} }
case BGradient::TYPE_DIAMOND: { case BGradient::TYPE_DIAMOND:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n")); GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n"));
const BGradientDiamond* diamond = (BGradientDiamond*) &gradient; const BGradientDiamond* diamond = (BGradientDiamond*)&gradient;
BPoint center = diamond->Center(); BPoint center = diamond->Center();
fSender->Attach(&center, sizeof(BPoint)); fSender->Attach(&center, sizeof(BPoint));
break; break;
} }
case BGradient::TYPE_CONIC: { case BGradient::TYPE_CONIC:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n")); GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n"));
const BGradientConic* conic = (BGradientConic*) &gradient; const BGradientConic* conic = (BGradientConic*)&gradient;
BPoint center = conic->Center(); BPoint center = conic->Center();
float angle = conic->Angle(); float angle = conic->Angle();
fSender->Attach(&center, sizeof(BPoint)); fSender->Attach(&center, sizeof(BPoint));
fSender->Attach(&angle, sizeof(float)); fSender->Attach(&angle, sizeof(float));
break; break;
} }
case BGradient::TYPE_NONE: { case BGradient::TYPE_NONE:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n")); GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
break; break;
} }