Another cleanup patch by Vasilis Kaoutsis - thanks!
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19998 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,78 +1,63 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* DarkWyrm, [email protected]
|
||||||
// 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: AreaLink.h
|
|
||||||
// Author: DarkWyrm <[email protected]>
|
|
||||||
// Description: Helper class for managing chunks of small data in an area
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#ifndef AREALINK_H
|
#ifndef AREALINK_H
|
||||||
#define AREALINK_H
|
#define AREALINK_H
|
||||||
|
|
||||||
#include <List.h>
|
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
|
#include <List.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
#define MAX_ATTACHMENT_SIZE 65535 // in bytes
|
#define MAX_ATTACHMENT_SIZE 65535 // in bytes
|
||||||
#define SIZE_SIZE 2 // size of the size records in an AreaLink area
|
#define SIZE_SIZE 2 // size of the size records in an AreaLink area
|
||||||
|
|
||||||
class AreaLinkHeader;
|
class AreaLinkHeader;
|
||||||
|
|
||||||
class AreaLink
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AreaLink(area_id area, bool is_arealink_area=false);
|
|
||||||
AreaLink(void);
|
|
||||||
~AreaLink(void);
|
|
||||||
|
|
||||||
void SetTarget(area_id area, bool is_arealink_area=false);
|
class AreaLink {
|
||||||
area_id GetTarget(void) { return target; }
|
public:
|
||||||
|
AreaLink(area_id area, bool is_arealink_area = false);
|
||||||
|
AreaLink();
|
||||||
|
~AreaLink();
|
||||||
|
|
||||||
void Attach(const void *data, size_t size);
|
void SetTarget(area_id area, bool is_arealink_area = false);
|
||||||
inline void Attach(const int32 &data);
|
area_id GetTarget() const { return fTarget; }
|
||||||
inline void Attach(const int16 &data);
|
|
||||||
inline void Attach(const int8 &data);
|
|
||||||
inline void Attach(const float &data);
|
|
||||||
inline void Attach(const bool &data);
|
|
||||||
inline void Attach(const rgb_color &data);
|
|
||||||
inline void Attach(const BRect &data);
|
|
||||||
inline void Attach(const BPoint &data);
|
|
||||||
|
|
||||||
void MakeEmpty(void);
|
void Attach(const void *data, size_t size);
|
||||||
void *ItemAt(int32 index) { return attachlist->ItemAt(index); }
|
inline void Attach(const int32 &data);
|
||||||
int32 CountAttachments(void) { return attachlist->CountItems(); }
|
inline void Attach(const int16 &data);
|
||||||
void *BaseAddress(void) { return (void *)baseaddress; }
|
inline void Attach(const int8 &data);
|
||||||
|
inline void Attach(const float &data);
|
||||||
|
inline void Attach(const bool &data);
|
||||||
|
inline void Attach(const rgb_color &data);
|
||||||
|
inline void Attach(const BRect &data);
|
||||||
|
inline void Attach(const BPoint &data);
|
||||||
|
|
||||||
|
void MakeEmpty();
|
||||||
|
void *ItemAt(const int32 index) const { return fAttachList->ItemAt(index); }
|
||||||
|
int32 CountAttachments() const { return fAttachList->CountItems(); }
|
||||||
|
void *BaseAddress() const { return (void *)fBaseAddress; }
|
||||||
|
|
||||||
void Lock(void);
|
void Lock();
|
||||||
void Unlock(void);
|
void Unlock();
|
||||||
bool IsLocked(void);
|
bool IsLocked();
|
||||||
protected:
|
|
||||||
void _ReadAttachments(void);
|
private:
|
||||||
|
void _ReadAttachments();
|
||||||
BList *attachlist;
|
|
||||||
area_id target;
|
private:
|
||||||
bool area_ok;
|
BList *fAttachList;
|
||||||
bool have_lock;
|
area_id fTarget;
|
||||||
int8 *baseaddress;
|
bool fAreaIsOk;
|
||||||
AreaLinkHeader *header;
|
bool fHaveLock;
|
||||||
|
int8 *fBaseAddress;
|
||||||
|
AreaLinkHeader *fHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // AREALINK_H
|
||||||
|
|||||||
+142
-126
@@ -1,213 +1,229 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* DarkWyrm, [email protected]
|
||||||
// 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: AreaLink.cpp
|
|
||||||
// Author: DarkWyrm <[email protected]>
|
|
||||||
// Description: Helper class for managing chunks of small data in an area
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <Rect.h>
|
|
||||||
#include "AreaLink.h"
|
#include "AreaLink.h"
|
||||||
|
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//#define AL_DEBUG
|
//#define AL_DEBUG
|
||||||
|
|
||||||
#ifdef AL_DEBUG
|
#ifdef AL_DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class AreaLinkHeader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AreaLinkHeader(void) { MakeEmpty(); lock=B_NAME_NOT_FOUND; }
|
|
||||||
|
|
||||||
void SetAttachmentCount(uint32 size) { attachmentcount=size; }
|
class AreaLinkHeader {
|
||||||
uint32 GetAttachmentCount(void) { return attachmentcount; }
|
public:
|
||||||
|
AreaLinkHeader() { MakeEmpty(); fLock = B_NAME_NOT_FOUND; }
|
||||||
|
|
||||||
void SetAttachmentSize(uint32 size) { attachmentsize=size; }
|
void SetAttachmentCount(uint32 size) { fAttachmentCount = size; }
|
||||||
uint32 GetAttachmentSize(void) { return attachmentsize; }
|
uint32 GetAttachmentCount() { return fAttachmentCount; }
|
||||||
|
|
||||||
|
void SetAttachmentSize(uint32 size) { fAttachmentSize = size; }
|
||||||
|
uint32 GetAttachmentSize() { return fAttachmentSize; }
|
||||||
|
|
||||||
|
void AddAttachment(uint32 size) { fAttachmentSize += size; fAttachmentCount++; }
|
||||||
|
|
||||||
void AddAttachment(uint32 size) { attachmentsize+=size; attachmentcount++; }
|
void SetLockSem(sem_id sem) { fLock = sem; }
|
||||||
|
sem_id GetLockSem() { return fLock; }
|
||||||
void SetLockSem(sem_id sem) { lock=sem; }
|
|
||||||
sem_id GetLockSem(void) { return lock; }
|
|
||||||
|
|
||||||
void MakeEmpty(void) { attachmentcount=0; attachmentsize=0; }
|
void MakeEmpty() { fAttachmentCount = 0; fAttachmentSize = 0; }
|
||||||
area_info GetInfo(void) { return info; }
|
area_info GetInfo() { return fInfo; }
|
||||||
void SetInfo(const area_info &newinfo) { info=newinfo; }
|
void SetInfo(const area_info &newInfo) { fInfo = newInfo; }
|
||||||
private:
|
|
||||||
uint32 attachmentcount;
|
private:
|
||||||
uint32 attachmentsize;
|
uint32 fAttachmentCount;
|
||||||
sem_id lock;
|
uint32 fAttachmentSize;
|
||||||
area_info info;
|
sem_id fLock;
|
||||||
|
area_info fInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
AreaLink::AreaLink(area_id area, bool is_arealink_area)
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
AreaLink::AreaLink(area_id area, bool isAreaLinkArea)
|
||||||
|
:fAttachList(new BList(0)),
|
||||||
|
fHaveLock(false)
|
||||||
{
|
{
|
||||||
attachlist=new BList(0);
|
SetTarget(area, isAreaLinkArea);
|
||||||
have_lock=false;
|
|
||||||
SetTarget(area,is_arealink_area);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaLink::AreaLink(void)
|
|
||||||
{
|
AreaLink::AreaLink()
|
||||||
attachlist=new BList(0);
|
:fAttachList(new BList(0)),
|
||||||
area_ok=false;
|
fTarget(B_NAME_NOT_FOUND),
|
||||||
have_lock=false;
|
fAreaIsOk(false),
|
||||||
target=B_NAME_NOT_FOUND;
|
fHaveLock(false)
|
||||||
|
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaLink::~AreaLink(void)
|
|
||||||
|
AreaLink::~AreaLink()
|
||||||
{
|
{
|
||||||
delete attachlist;
|
delete fAttachList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::SetTarget(area_id area,bool is_arealink_area)
|
|
||||||
|
void
|
||||||
|
AreaLink::SetTarget(area_id area, bool isAreaLinkArea)
|
||||||
{
|
{
|
||||||
area_info targetinfo;
|
area_info targetInfo;
|
||||||
|
|
||||||
if(get_area_info(area,&targetinfo)==B_OK)
|
if (get_area_info(area, &targetInfo) == B_OK) {
|
||||||
{
|
fTarget = area;
|
||||||
target=area;
|
fAreaIsOk = true;
|
||||||
area_ok=true;
|
fHeader = (AreaLinkHeader *)targetInfo.address;
|
||||||
header=(AreaLinkHeader *)targetinfo.address;
|
|
||||||
|
|
||||||
if(is_arealink_area)
|
if (isAreaLinkArea)
|
||||||
_ReadAttachments();
|
_ReadAttachments();
|
||||||
else
|
else {
|
||||||
{
|
fHeader->MakeEmpty();
|
||||||
header->MakeEmpty();
|
fHeader->SetInfo(targetInfo);
|
||||||
header->SetInfo(targetinfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
baseaddress=(int8*)targetinfo.address;
|
fBaseAddress = (int8*)targetInfo.address;
|
||||||
baseaddress+=sizeof(AreaLinkHeader);
|
fBaseAddress += sizeof(AreaLinkHeader);
|
||||||
}
|
} else {
|
||||||
else
|
fTarget = B_NAME_NOT_FOUND;
|
||||||
{
|
fAreaIsOk = false;
|
||||||
target=B_NAME_NOT_FOUND;
|
|
||||||
area_ok=false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const void *data, size_t size)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const void *data, size_t size)
|
||||||
{
|
{
|
||||||
if(!data || size==0)
|
if (!data || size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Lock();
|
Lock();
|
||||||
|
|
||||||
// Will the attachment fit?
|
// Will the attachment fit?
|
||||||
if(header->GetAttachmentSize()+size>header->GetInfo().size)
|
if (fHeader->GetAttachmentSize() + size > fHeader->GetInfo().size) {
|
||||||
{
|
|
||||||
// Being it won't fit, resize the area to fit the thing
|
// Being it won't fit, resize the area to fit the thing
|
||||||
int32 pagenum=int32(header->GetInfo().size/B_PAGE_SIZE);
|
int32 pageNum = int32(fHeader->GetInfo().size / B_PAGE_SIZE);
|
||||||
resize_area(target,pagenum+1);
|
resize_area(fTarget, pageNum + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our attachment will fit, so copy the data into the current location
|
// Our attachment will fit, so copy the data into the current location
|
||||||
// and increment the appropriate header values
|
// and increment the appropriate fHeader values
|
||||||
int8 *currentpointer=(int8*)BaseAddress();
|
int8 *currentpointer = (int8*)BaseAddress();
|
||||||
currentpointer+=header->GetAttachmentSize();
|
currentpointer += fHeader->GetAttachmentSize();
|
||||||
memcpy(currentpointer,data,size);
|
memcpy(currentpointer, data, size);
|
||||||
|
|
||||||
attachlist->AddItem(currentpointer);
|
fAttachList->AddItem(currentpointer);
|
||||||
header->AddAttachment(size);
|
fHeader->AddAttachment(size);
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const int32 &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const int32 &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(int32));
|
Attach(&data, sizeof(int32));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const int16 &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const int16 &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(int16));
|
Attach(&data, sizeof(int16));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const int8 &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const int8 &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(int8));
|
Attach(&data, sizeof(int8));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const float &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const float &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(float));
|
Attach(&data, sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const bool &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const bool &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(bool));
|
Attach(&data, sizeof(bool));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const rgb_color &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const rgb_color &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(rgb_color));
|
Attach(&data, sizeof(rgb_color));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const BRect &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const BRect &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(BRect));
|
Attach(&data, sizeof(BRect));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Attach(const BPoint &data)
|
|
||||||
|
void
|
||||||
|
AreaLink::Attach(const BPoint &data)
|
||||||
{
|
{
|
||||||
Attach(&data,sizeof(BPoint));
|
Attach(&data, sizeof(BPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::MakeEmpty(void)
|
|
||||||
|
void
|
||||||
|
AreaLink::MakeEmpty()
|
||||||
{
|
{
|
||||||
attachlist->MakeEmpty();
|
fAttachList->MakeEmpty();
|
||||||
header->MakeEmpty();
|
fHeader->MakeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::_ReadAttachments(void)
|
|
||||||
|
void
|
||||||
|
AreaLink::_ReadAttachments()
|
||||||
{
|
{
|
||||||
int8 *index=baseaddress;
|
int8 *index = fBaseAddress;
|
||||||
uint16 size;
|
uint16 size;
|
||||||
|
|
||||||
for(uint32 i=0; i<header->GetAttachmentCount();i++)
|
for (uint32 i = 0; i < fHeader->GetAttachmentCount(); i++) {
|
||||||
{
|
size = *((int16*)index);
|
||||||
size=*((int16*)index);
|
fBaseAddress += SIZE_SIZE;
|
||||||
baseaddress+=SIZE_SIZE;
|
fAttachList->AddItem(fBaseAddress);
|
||||||
attachlist->AddItem(baseaddress);
|
fBaseAddress += size;
|
||||||
baseaddress+=size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Lock(void)
|
|
||||||
|
void
|
||||||
|
AreaLink::Lock()
|
||||||
{
|
{
|
||||||
if(!have_lock)
|
if (!fHaveLock)
|
||||||
acquire_sem(header->GetLockSem());
|
acquire_sem(fHeader->GetLockSem());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AreaLink::Unlock(void)
|
|
||||||
|
void
|
||||||
|
AreaLink::Unlock()
|
||||||
{
|
{
|
||||||
if(have_lock)
|
if (fHaveLock)
|
||||||
release_sem(header->GetLockSem());
|
release_sem(fHeader->GetLockSem());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AreaLink::IsLocked(void)
|
|
||||||
|
bool
|
||||||
|
AreaLink::IsLocked()
|
||||||
{
|
{
|
||||||
return have_lock;
|
return fHaveLock;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user