Files
haiku-beta6/src/kits/app/PortLink.cpp
T

156 lines
4.0 KiB
C++
Raw Normal View History

//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: PortLink.cpp
// Author: Pahtz <[email protected]>
// Description: Class for low-overhead port-based messaging
//
//------------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <new>
2005-01-22 09:48:10 +00:00
#include <Region.h>
#include <Shape.h>
2003-10-03 22:23:17 +00:00
#include <ServerProtocol.h>
#include <PortLink.h>
BPortLink::BPortLink(port_id send, port_id receive) :
fReader(new LinkMsgReader(receive)), fSender(new LinkMsgSender(send))
{
}
BPortLink::~BPortLink()
{
delete fReader;
delete fSender;
}
status_t BPortLink::StartMessage(int32 code)
{
return fSender->StartMessage(code);
}
2003-10-03 22:23:17 +00:00
status_t BPortLink::EndMessage()
2002-07-09 12:24:59 +00:00
{
return fSender->EndMessage();
2002-07-09 12:24:59 +00:00
}
2003-10-03 22:23:17 +00:00
void BPortLink::CancelMessage()
2003-10-03 23:28:46 +00:00
{
fSender->CancelMessage();
2003-10-03 23:28:46 +00:00
}
status_t BPortLink::Attach(const void *data, ssize_t size)
2003-10-03 22:23:17 +00:00
{
return fSender->Attach(data,size);
2002-07-09 12:24:59 +00:00
}
2003-10-03 22:23:17 +00:00
void BPortLink::SetSendPort( port_id port )
2003-10-03 22:23:17 +00:00
{
fSender->SetPort(port);
2002-07-09 12:24:59 +00:00
}
2003-10-03 22:23:17 +00:00
port_id BPortLink::GetSendPort()
2003-10-03 22:23:17 +00:00
{
return fSender->GetPort();
2002-07-09 12:24:59 +00:00
}
2003-10-03 22:23:17 +00:00
void BPortLink::SetReplyPort( port_id port )
2003-10-03 22:23:17 +00:00
{
fReader->SetPort(port);
}
port_id BPortLink::GetReplyPort()
{
return fReader->GetPort();
}
status_t BPortLink::Flush(bigtime_t timeout)
{
return fSender->Flush(timeout);
2002-07-09 12:24:59 +00:00
}
status_t BPortLink::GetNextReply(int32 *code, bigtime_t timeout)
2003-06-23 13:18:39 +00:00
{
return fReader->GetNextMessage(code,timeout);
}
status_t BPortLink::Read(void *data, ssize_t size)
{
return fReader->Read(data,size);
}
status_t BPortLink::ReadString(char **string)
{
return fReader->ReadString(string);
}
2003-10-03 22:23:17 +00:00
status_t BPortLink::AttachString(const char *string)
{
return fSender->AttachString(string);
}
2005-01-22 09:48:10 +00:00
status_t BPortLink::ReadRegion(BRegion *region)
{
fReader->Read(&region->count, sizeof(long));
fReader->Read(&region->bound, sizeof(clipping_rect));
region->set_size(region->count + 1);
return fReader->Read(region->data, region->count * sizeof(clipping_rect));
}
status_t BPortLink::AttachRegion(const BRegion &region)
{
fSender->Attach(&region.count, sizeof(long));
fSender->Attach(&region.bound, sizeof(clipping_rect));
return fSender->Attach(region.data, region.count * sizeof(clipping_rect));
}
status_t BPortLink::ReadShape(BShape *shape)
{
int32 opCount, ptCount;
fReader->Read(&opCount, sizeof(int32));
fReader->Read(&ptCount, sizeof(int32));
uint32 opList[opCount];
fReader->Read(opList, opCount * sizeof(uint32));
BPoint ptList[ptCount];
fReader->Read(ptList, ptCount * sizeof(BPoint));
shape->SetData(opCount, ptCount, opList, ptList);
return B_OK;
}
status_t BPortLink::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));
}