* 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.
*
* Authors:
@ -9,7 +9,9 @@
* Artur Wyszynski <harakash@gmail.com>
*/
/** Class for low-overhead port-based messaging */
/*! Class for low-overhead port-based messaging */
#include <LinkReceiver.h>
@ -47,6 +49,7 @@
namespace BPrivate {
LinkReceiver::LinkReceiver(port_id port)
:
fReceivePort(port), fRecvBuffer(NULL), fRecvPosition(0), fRecvStart(0),
@ -482,13 +485,14 @@ 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;
@ -498,81 +502,82 @@ LinkReceiver::ReadGradient(BGradient** _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: {
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(&center, sizeof(BPoint))) != B_OK)
return ret;
if ((ret = Read(&radius, sizeof(float))) != B_OK)
return ret;
Read(&center, 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(&center, 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(&center, 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(&center, sizeof(BPoint))) != B_OK)
return ret;
if ((status = Read(&center, 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(&center, sizeof(BPoint))) != B_OK)
return ret;
if ((ret = Read(&angle, sizeof(float))) != B_OK)
return ret;
Read(&center, 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;
}
@ -581,4 +586,5 @@ LinkReceiver::ReadGradient(BGradient** _gradient)
return B_ERROR;
}
} // namespace BPrivate

View File

@ -154,16 +154,16 @@ ServerLink::AttachGradient(const BGradient& gradient)
}
switch (gradientType) {
case BGradient::TYPE_LINEAR: {
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));
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;
BPoint center = radial->Center();
@ -172,10 +172,11 @@ ServerLink::AttachGradient(const BGradient& gradient)
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,14 +185,16 @@ 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;
BPoint center = diamond->Center();
fSender->Attach(&center, sizeof(BPoint));
break;
}
case BGradient::TYPE_CONIC: {
case BGradient::TYPE_CONIC:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n"));
const BGradientConic* conic = (BGradientConic*)&gradient;
BPoint center = conic->Center();
@ -200,7 +203,8 @@ ServerLink::AttachGradient(const BGradient& gradient)
fSender->Attach(&angle, sizeof(float));
break;
}
case BGradient::TYPE_NONE: {
case BGradient::TYPE_NONE:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
break;
}