* 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),
@ -482,13 +485,14 @@ 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;
@ -498,81 +502,82 @@ LinkReceiver::ReadGradient(BGradient** _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;
} }
@ -581,4 +586,5 @@ LinkReceiver::ReadGradient(BGradient** _gradient)
return B_ERROR; return B_ERROR;
} }
} // namespace BPrivate } // namespace BPrivate

View File

@ -153,29 +153,30 @@ ServerLink::AttachGradient(const BGradient& gradient)
} }
} }
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;
} }