* Rewrote headers as necessary; only Errors.h and Debug.h still originate from a Be header now;
feel free to change that ;-) * Cleaned up existing headers. * Coding style guide update to BBufferIO (renamed m_* members to f*). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19972 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,97 +1,51 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// 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: Archivable.h
|
||||
// Author: Erik Jaesler ([email protected])
|
||||
// Description: BArchivable mix-in class defines the archiving
|
||||
// protocol. Also some global archiving functions.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ARCHIVABLE_H
|
||||
#define _ARCHIVABLE_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <BeBuild.h>
|
||||
#include <image.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class BMessage;
|
||||
|
||||
// BArchivable class -----------------------------------------------------------
|
||||
|
||||
class BArchivable {
|
||||
public:
|
||||
BArchivable();
|
||||
virtual ~BArchivable();
|
||||
public:
|
||||
BArchivable(BMessage* from);
|
||||
BArchivable();
|
||||
virtual ~BArchivable();
|
||||
|
||||
BArchivable(BMessage* from);
|
||||
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||
static BArchivable *Instantiate(BMessage* from);
|
||||
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
|
||||
// Private or reserved ---------------------------------------------------------
|
||||
virtual status_t Perform(perform_code d, void* arg);
|
||||
// Private or reserved
|
||||
virtual status_t Perform(perform_code d, void* arg);
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual void _ReservedArchivable1();
|
||||
virtual void _ReservedArchivable2();
|
||||
virtual void _ReservedArchivable3();
|
||||
|
||||
virtual void _ReservedArchivable1();
|
||||
virtual void _ReservedArchivable2();
|
||||
virtual void _ReservedArchivable3();
|
||||
|
||||
uint32 _reserved[2];
|
||||
uint32 _reserved[2];
|
||||
};
|
||||
|
||||
|
||||
// Global Functions ------------------------------------------------------------
|
||||
// global functions
|
||||
|
||||
typedef BArchivable* (*instantiation_func) (BMessage *);
|
||||
typedef BArchivable* (*instantiation_func)(BMessage*);
|
||||
|
||||
_IMPEXP_BE BArchivable* instantiate_object(BMessage *from, image_id *id);
|
||||
_IMPEXP_BE BArchivable* instantiate_object(BMessage *from);
|
||||
_IMPEXP_BE bool validate_instantiation(BMessage* from,
|
||||
const char* class_name);
|
||||
|
||||
_IMPEXP_BE instantiation_func find_instantiation_func(const char* class_name,
|
||||
const char* sig);
|
||||
_IMPEXP_BE instantiation_func find_instantiation_func(const char* class_name);
|
||||
_IMPEXP_BE instantiation_func find_instantiation_func(BMessage* archive_data);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
BArchivable* instantiate_object(BMessage *from, image_id *id);
|
||||
BArchivable* instantiate_object(BMessage *from);
|
||||
bool validate_instantiation(BMessage* from, const char* className);
|
||||
|
||||
instantiation_func find_instantiation_func(const char* className,
|
||||
const char* signature);
|
||||
instantiation_func find_instantiation_func(const char* className);
|
||||
instantiation_func find_instantiation_func(BMessage* archive);
|
||||
|
||||
#endif // _ARCHIVABLE_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,79 +1,68 @@
|
||||
//
|
||||
// $Id: Autolock.h 3246 2003-05-14 17:21:46Z haydentech $
|
||||
//
|
||||
// This is the BAutolock interface for OpenBeOS. It has been created to
|
||||
// be source and binary compatible with the BeOS version of BAutolock.
|
||||
// To that end, all members are inline just as with the BeOS version.
|
||||
//
|
||||
|
||||
|
||||
#ifndef _OPENBEOS_AUTOLOCK_H
|
||||
#define _OPENBEOS_AUTOLOCK_H
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _SUPPORT_AUTOLOCK_H
|
||||
#define _SUPPORT_AUTOLOCK_H
|
||||
|
||||
|
||||
#include <Locker.h>
|
||||
#include <Looper.h>
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
namespace OpenBeOS {
|
||||
#endif
|
||||
|
||||
class BAutolock {
|
||||
public:
|
||||
inline BAutolock(BLooper *looper);
|
||||
inline BAutolock(BLocker *locker);
|
||||
inline BAutolock(BLocker &locker);
|
||||
|
||||
inline ~BAutolock();
|
||||
|
||||
inline bool IsLocked(void);
|
||||
public:
|
||||
inline BAutolock(BLooper *looper);
|
||||
inline BAutolock(BLocker *locker);
|
||||
inline BAutolock(BLocker &locker);
|
||||
inline ~BAutolock();
|
||||
|
||||
private:
|
||||
BLocker *fTheLocker;
|
||||
BLooper *fTheLooper;
|
||||
bool fIsLocked;
|
||||
inline bool IsLocked(void);
|
||||
|
||||
private:
|
||||
BLocker *fLocker;
|
||||
BLooper *fLooper;
|
||||
bool fIsLocked;
|
||||
};
|
||||
|
||||
|
||||
inline BAutolock::BAutolock(BLooper *looper) :
|
||||
fTheLocker(NULL), fTheLooper(looper), fIsLocked(looper->Lock())
|
||||
inline
|
||||
BAutolock::BAutolock(BLooper *looper)
|
||||
: fLocker(NULL), fLooper(looper), fIsLocked(looper->Lock())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline BAutolock::BAutolock(BLocker *locker) :
|
||||
fTheLocker(locker), fTheLooper(NULL), fIsLocked(locker->Lock())
|
||||
inline
|
||||
BAutolock::BAutolock(BLocker *locker)
|
||||
: fLocker(locker), fLooper(NULL), fIsLocked(locker->Lock())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline BAutolock::BAutolock(BLocker &locker) :
|
||||
fTheLocker(&locker), fTheLooper(NULL), fIsLocked(locker.Lock())
|
||||
inline
|
||||
BAutolock::BAutolock(BLocker &locker)
|
||||
: fLocker(&locker), fLooper(NULL), fIsLocked(locker.Lock())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline BAutolock::~BAutolock()
|
||||
inline
|
||||
BAutolock::~BAutolock()
|
||||
{
|
||||
if (fIsLocked) {
|
||||
if (fTheLooper != NULL) {
|
||||
fTheLooper->Unlock();
|
||||
} else {
|
||||
fTheLocker->Unlock();
|
||||
}
|
||||
if (fLooper != NULL)
|
||||
fLooper->Unlock();
|
||||
else
|
||||
fLocker->Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool BAutolock::IsLocked()
|
||||
inline bool
|
||||
BAutolock::IsLocked()
|
||||
{
|
||||
return fIsLocked;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _OPENBEOS_LOCKER_H
|
||||
#endif // _SUPPORT_AUTOLOCK_H
|
||||
|
||||
+12
-19
@@ -1,29 +1,22 @@
|
||||
/******************************************************************************
|
||||
/
|
||||
/ File: Beep.h
|
||||
/
|
||||
/ Description: System beep function.
|
||||
/
|
||||
/ Copyright 1993-98, Be Incorporated
|
||||
/
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _BEEP_H
|
||||
#define _BEEP_H
|
||||
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
_IMPEXP_BE status_t beep();
|
||||
_IMPEXP_BE status_t system_beep(const char * event_name);
|
||||
#ifdef __cplusplus
|
||||
// These functions are only exported for C++
|
||||
|
||||
status_t beep();
|
||||
status_t system_beep(const char* eventName);
|
||||
status_t add_system_beep_event(const char* eventName, uint32 flags = 0);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define _BEEP_FLAGS = 0
|
||||
#else
|
||||
#define _BEEP_FLAGS
|
||||
#endif
|
||||
_IMPEXP_BE status_t add_system_beep_event(const char * event_name, uint32 flags _BEEP_FLAGS);
|
||||
|
||||
|
||||
#endif /* _BEEP_H */
|
||||
#endif // _BEEP_H
|
||||
|
||||
@@ -22,52 +22,43 @@
|
||||
#ifndef _BLOCK_CACHE_H
|
||||
#define _BLOCK_CACHE_H
|
||||
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <Locker.h>
|
||||
|
||||
/* The OpenBeOS implementation of the BBlockCache.
|
||||
* A class used to manage a pool of memory blocks.
|
||||
*/
|
||||
|
||||
/* The allocation type to be used in the constructor
|
||||
*/
|
||||
// The allocation type to be used in the constructor
|
||||
enum {
|
||||
B_OBJECT_CACHE = 0,
|
||||
B_MALLOC_CACHE = 1
|
||||
};
|
||||
|
||||
/* The BBlockCache class:
|
||||
*/
|
||||
class BBlockCache
|
||||
{
|
||||
public:
|
||||
BBlockCache(uint32 blockCount,
|
||||
size_t blockSize,
|
||||
uint32 allocationType);
|
||||
virtual ~BBlockCache();
|
||||
class BBlockCache {
|
||||
public:
|
||||
BBlockCache(uint32 blockCount, size_t blockSize,
|
||||
uint32 allocationType);
|
||||
virtual ~BBlockCache();
|
||||
|
||||
void * Get(size_t blockSize);
|
||||
void Save(void *pointer, size_t blockSize);
|
||||
void* Get(size_t blockSize);
|
||||
void Save(void *pointer, size_t blockSize);
|
||||
|
||||
/* Private or reserved functions and data
|
||||
*/
|
||||
private:
|
||||
virtual void _ReservedBlockCache1();
|
||||
virtual void _ReservedBlockCache2();
|
||||
private:
|
||||
virtual void _ReservedBlockCache1();
|
||||
virtual void _ReservedBlockCache2();
|
||||
|
||||
BBlockCache(const BBlockCache &);
|
||||
BBlockCache &operator=(const BBlockCache &);
|
||||
BBlockCache(const BBlockCache &);
|
||||
BBlockCache &operator=(const BBlockCache &);
|
||||
|
||||
struct _FreeBlock;
|
||||
struct _FreeBlock;
|
||||
|
||||
_FreeBlock *fFreeList;
|
||||
size_t fBlockSize;
|
||||
int32 fFreeBlocks;
|
||||
int32 fBlockCount;
|
||||
BLocker fLocker;
|
||||
void * (*fAlloc)(size_t size);
|
||||
void (*fFree)(void *pointer);
|
||||
uint32 _reserved[2];
|
||||
_FreeBlock* fFreeList;
|
||||
size_t fBlockSize;
|
||||
int32 fFreeBlocks;
|
||||
int32 fBlockCount;
|
||||
BLocker fLocker;
|
||||
void* (*fAlloc)(size_t size);
|
||||
void (*fFree)(void *pointer);
|
||||
uint32 _reserved[2];
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // _BLOCK_CACHE_H
|
||||
|
||||
@@ -1,73 +1,49 @@
|
||||
/******************************************************************************
|
||||
/
|
||||
/ File: BufferIO.h
|
||||
/
|
||||
/ Description: A buffered adapter for BPositionIO
|
||||
/
|
||||
/ Copyright 1998, Be Incorporated
|
||||
/
|
||||
******************************************************************************/
|
||||
|
||||
#if !defined(_BUFFER_IO_H)
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _BUFFER_IO_H
|
||||
#define _BUFFER_IO_H
|
||||
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
class BBufferIO : public BPositionIO
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
DEFAULT_BUF_SIZE = 65536L
|
||||
};
|
||||
|
||||
BBufferIO(
|
||||
BPositionIO * stream,
|
||||
size_t buf_size = DEFAULT_BUF_SIZE,
|
||||
bool owns_stream = true);
|
||||
virtual ~BBufferIO();
|
||||
class BBufferIO : public BPositionIO {
|
||||
public:
|
||||
BBufferIO(BPositionIO* stream, size_t bufferSize = 65536L,
|
||||
bool ownsStream = true);
|
||||
virtual ~BBufferIO();
|
||||
|
||||
virtual ssize_t ReadAt(
|
||||
off_t pos,
|
||||
void *buffer,
|
||||
size_t size);
|
||||
virtual ssize_t WriteAt(
|
||||
off_t pos,
|
||||
const void *buffer,
|
||||
size_t size);
|
||||
virtual off_t Seek(
|
||||
off_t position,
|
||||
uint32 seek_mode);
|
||||
virtual off_t Position() const;
|
||||
virtual status_t SetSize(
|
||||
off_t size);
|
||||
virtual status_t Flush();
|
||||
BPositionIO * Stream() const;
|
||||
virtual ssize_t ReadAt(off_t pos, void* buffer, size_t size);
|
||||
virtual ssize_t WriteAt(off_t pos, const void* buffer, size_t size);
|
||||
virtual off_t Seek(off_t position, uint32 seekMode);
|
||||
virtual off_t Position() const;
|
||||
virtual status_t SetSize(off_t size);
|
||||
virtual status_t Flush();
|
||||
BPositionIO* Stream() const;
|
||||
size_t BufferSize() const;
|
||||
bool OwnsStream() const;
|
||||
void SetOwnsStream(
|
||||
bool owns_stream);
|
||||
void SetOwnsStream(bool ownsStream);
|
||||
|
||||
void PrintToStream() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
virtual status_t _Reserved_BufferIO_0(void*);
|
||||
virtual status_t _Reserved_BufferIO_1(void*);
|
||||
virtual status_t _Reserved_BufferIO_2(void*);
|
||||
virtual status_t _Reserved_BufferIO_3(void*);
|
||||
virtual status_t _Reserved_BufferIO_4(void*);
|
||||
|
||||
off_t m_buffer_start;
|
||||
BPositionIO * m_stream;
|
||||
char * m_buffer;
|
||||
size_t m_buffer_phys;
|
||||
size_t m_buffer_used;
|
||||
off_t fBufferStart;
|
||||
BPositionIO* fStream;
|
||||
char* fBuffer;
|
||||
size_t fBufferSize;
|
||||
size_t fBufferUsed;
|
||||
uint32 _reserved_ints[6];
|
||||
bool m_buffer_dirty;
|
||||
bool m_owns_stream;
|
||||
bool fBufferIsDirty;
|
||||
bool fOwnsStream;
|
||||
bool _reserved_bools[6];
|
||||
|
||||
virtual status_t _Reserved_BufferIO_0(void *);
|
||||
virtual status_t _Reserved_BufferIO_1(void *);
|
||||
virtual status_t _Reserved_BufferIO_2(void *);
|
||||
virtual status_t _Reserved_BufferIO_3(void *);
|
||||
virtual status_t _Reserved_BufferIO_4(void *);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* _BUFFER_IO_H */
|
||||
#endif // _BUFFER_IO_H
|
||||
|
||||
+104
-116
@@ -1,21 +1,19 @@
|
||||
// Modified BeOS header. Just here to be able to compile and test BResources.
|
||||
// To be replaced by the OpenBeOS version to be provided by the IK Team.
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _BYTEORDER_H
|
||||
#define _BYTEORDER_H
|
||||
|
||||
#ifndef _sk_byte_order_h_
|
||||
#define _sk_byte_order_h_
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <endian.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <TypeConstants.h> /* For convenience */
|
||||
#include <TypeConstants.h>
|
||||
// for convenience
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/*------- Swap-direction constants, and swapping functions -------------*/
|
||||
|
||||
// swap directions
|
||||
typedef enum {
|
||||
B_SWAP_HOST_TO_LENDIAN,
|
||||
B_SWAP_HOST_TO_BENDIAN,
|
||||
@@ -24,121 +22,111 @@ typedef enum {
|
||||
B_SWAP_ALWAYS
|
||||
} swap_action;
|
||||
|
||||
extern status_t swap_data(type_code type, void *data, size_t length,
|
||||
swap_action action);
|
||||
|
||||
extern bool is_type_swapped(type_code type);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/*----- Private implementations -----------------------------------------*/
|
||||
extern double __swap_double(double arg);
|
||||
extern float __swap_float(float arg);
|
||||
extern uint64 __swap_int64(uint64 uarg);
|
||||
extern uint32 __swap_int32(uint32 uarg);
|
||||
extern uint16 __swap_int16(uint16 uarg);
|
||||
/*-------------------------------------------------------------*/
|
||||
// BSD/networking macros
|
||||
#ifndef htonl
|
||||
# define htonl(x) B_HOST_TO_BENDIAN_INT32(x)
|
||||
# define ntohl(x) B_BENDIAN_TO_HOST_INT32(x)
|
||||
# define htons(x) B_HOST_TO_BENDIAN_INT16(x)
|
||||
# define ntohs(x) B_BENDIAN_TO_HOST_INT16(x)
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--------- Host is Little --------------------------------------*/
|
||||
|
||||
#if BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define B_HOST_IS_LENDIAN 1
|
||||
#define B_HOST_IS_BENDIAN 0
|
||||
|
||||
/*--------- Host Native -> Little --------------------*/
|
||||
|
||||
#define B_HOST_TO_LENDIAN_DOUBLE(arg) (double)(arg)
|
||||
#define B_HOST_TO_LENDIAN_FLOAT(arg) (float)(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT64(arg) (uint64)(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT32(arg) (uint32)(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT16(arg) (uint16)(arg)
|
||||
|
||||
/*--------- Host Native -> Big ------------------------*/
|
||||
#define B_HOST_TO_BENDIAN_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_HOST_TO_BENDIAN_FLOAT(arg) __swap_float(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT64(arg) __swap_int64(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT32(arg) __swap_int32(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT16(arg) __swap_int16(arg)
|
||||
|
||||
/*--------- Little -> Host Native ---------------------*/
|
||||
#define B_LENDIAN_TO_HOST_DOUBLE(arg) (double)(arg)
|
||||
#define B_LENDIAN_TO_HOST_FLOAT(arg) (float)(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT64(arg) (uint64)(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT32(arg) (uint32)(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT16(arg) (uint16)(arg)
|
||||
|
||||
/*--------- Big -> Host Native ------------------------*/
|
||||
#define B_BENDIAN_TO_HOST_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_BENDIAN_TO_HOST_FLOAT(arg) __swap_float(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT64(arg) __swap_int64(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT32(arg) __swap_int32(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT16(arg) __swap_int16(arg)
|
||||
|
||||
#else /* __LITTLE_ENDIAN */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--------- Host is Big --------------------------------------*/
|
||||
|
||||
#define B_HOST_IS_LENDIAN 0
|
||||
#define B_HOST_IS_BENDIAN 1
|
||||
|
||||
/*--------- Host Native -> Little -------------------*/
|
||||
#define B_HOST_TO_LENDIAN_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_HOST_TO_LENDIAN_FLOAT(arg) __swap_float(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT64(arg) __swap_int64(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT32(arg) __swap_int32(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT16(arg) __swap_int16(arg)
|
||||
|
||||
/*--------- Host Native -> Big ------------------------*/
|
||||
#define B_HOST_TO_BENDIAN_DOUBLE(arg) (double)(arg)
|
||||
#define B_HOST_TO_BENDIAN_FLOAT(arg) (float)(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT64(arg) (uint64)(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT32(arg) (uint32)(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT16(arg) (uint16)(arg)
|
||||
|
||||
/*--------- Little -> Host Native ----------------------*/
|
||||
#define B_LENDIAN_TO_HOST_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_LENDIAN_TO_HOST_FLOAT(arg) __swap_float(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT64(arg) __swap_int64(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT32(arg) __swap_int32(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT16(arg) __swap_int16(arg)
|
||||
|
||||
/*--------- Big -> Host Native -------------------------*/
|
||||
#define B_BENDIAN_TO_HOST_DOUBLE(arg) (double)(arg)
|
||||
#define B_BENDIAN_TO_HOST_FLOAT(arg) (float)(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT64(arg) (uint64)(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT32(arg) (uint32)(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT16(arg) (uint16)(arg)
|
||||
|
||||
#endif /* __LITTLE_ENDIAN */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--------- Just-do-it macros ---------------------------------*/
|
||||
// always swap macros
|
||||
#define B_SWAP_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_SWAP_FLOAT(arg) __swap_float(arg)
|
||||
#define B_SWAP_INT64(arg) __swap_int64(arg)
|
||||
#define B_SWAP_INT32(arg) __swap_int32(arg)
|
||||
#define B_SWAP_INT16(arg) __swap_int16(arg)
|
||||
|
||||
#if BYTE_ORDER == __LITTLE_ENDIAN
|
||||
// Host is little endian
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*---------Berkeley macros -----------------------------------*/
|
||||
#ifndef htonl /* avoid collision with <netinet/in.h> */
|
||||
#define htonl(x) B_HOST_TO_BENDIAN_INT32(x)
|
||||
#define ntohl(x) B_BENDIAN_TO_HOST_INT32(x)
|
||||
#define htons(x) B_HOST_TO_BENDIAN_INT16(x)
|
||||
#define ntohs(x) B_BENDIAN_TO_HOST_INT16(x)
|
||||
#endif
|
||||
#define B_HOST_IS_LENDIAN 1
|
||||
#define B_HOST_IS_BENDIAN 0
|
||||
|
||||
// Host native to little endian
|
||||
#define B_HOST_TO_LENDIAN_DOUBLE(arg) (double)(arg)
|
||||
#define B_HOST_TO_LENDIAN_FLOAT(arg) (float)(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT64(arg) (uint64)(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT32(arg) (uint32)(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT16(arg) (uint16)(arg)
|
||||
|
||||
// Little endian to host native
|
||||
#define B_LENDIAN_TO_HOST_DOUBLE(arg) (double)(arg)
|
||||
#define B_LENDIAN_TO_HOST_FLOAT(arg) (float)(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT64(arg) (uint64)(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT32(arg) (uint32)(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT16(arg) (uint16)(arg)
|
||||
|
||||
// Host native to big endian
|
||||
#define B_HOST_TO_BENDIAN_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_HOST_TO_BENDIAN_FLOAT(arg) __swap_float(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT64(arg) __swap_int64(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT32(arg) __swap_int32(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT16(arg) __swap_int16(arg)
|
||||
|
||||
// Big endian to host native
|
||||
#define B_BENDIAN_TO_HOST_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_BENDIAN_TO_HOST_FLOAT(arg) __swap_float(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT64(arg) __swap_int64(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT32(arg) __swap_int32(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT16(arg) __swap_int16(arg)
|
||||
|
||||
#else // BYTE_ORDER
|
||||
// Host is big endian
|
||||
|
||||
#define B_HOST_IS_LENDIAN 0
|
||||
#define B_HOST_IS_BENDIAN 1
|
||||
|
||||
// Host native to little endian
|
||||
#define B_HOST_TO_LENDIAN_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_HOST_TO_LENDIAN_FLOAT(arg) __swap_float(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT64(arg) __swap_int64(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT32(arg) __swap_int32(arg)
|
||||
#define B_HOST_TO_LENDIAN_INT16(arg) __swap_int16(arg)
|
||||
|
||||
// Little endian to host native
|
||||
#define B_LENDIAN_TO_HOST_DOUBLE(arg) __swap_double(arg)
|
||||
#define B_LENDIAN_TO_HOST_FLOAT(arg) __swap_float(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT64(arg) __swap_int64(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT32(arg) __swap_int32(arg)
|
||||
#define B_LENDIAN_TO_HOST_INT16(arg) __swap_int16(arg)
|
||||
|
||||
// Host native to big endian
|
||||
#define B_HOST_TO_BENDIAN_DOUBLE(arg) (double)(arg)
|
||||
#define B_HOST_TO_BENDIAN_FLOAT(arg) (float)(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT64(arg) (uint64)(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT32(arg) (uint32)(arg)
|
||||
#define B_HOST_TO_BENDIAN_INT16(arg) (uint16)(arg)
|
||||
|
||||
// Big endian to host native
|
||||
#define B_BENDIAN_TO_HOST_DOUBLE(arg) (double)(arg)
|
||||
#define B_BENDIAN_TO_HOST_FLOAT(arg) (float)(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT64(arg) (uint64)(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT32(arg) (uint32)(arg)
|
||||
#define B_BENDIAN_TO_HOST_INT16(arg) (uint16)(arg)
|
||||
|
||||
#endif // BYTE_ORDER
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern status_t swap_data(type_code type, void *data, size_t length,
|
||||
swap_action action);
|
||||
extern bool is_type_swapped(type_code type);
|
||||
|
||||
|
||||
// Private implementations
|
||||
extern double __swap_double(double arg);
|
||||
extern float __swap_float(float arg);
|
||||
extern uint64 __swap_int64(uint64 arg);
|
||||
extern uint32 __swap_int32(uint32 arg);
|
||||
extern uint16 __swap_int16(uint16 arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
#endif // _sk_byte_order_h_
|
||||
#endif // _BYTEORDER_H
|
||||
|
||||
@@ -1,38 +1,24 @@
|
||||
/******************************************************************************
|
||||
/
|
||||
/ File: ClassInfo.h
|
||||
/
|
||||
/ Description: C++ class identification and casting macros
|
||||
/
|
||||
/ Copyright 1993-98, Be Incorporated
|
||||
/
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _CLASS_INFO_H
|
||||
#define _CLASS_INFO_H
|
||||
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
// deprecated, use standard RTTI calls instead
|
||||
// TODO: maybe get rid of this header completely?
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
namespace OpenBeOS {
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--------- Class Info Macros ---------------------------------*/
|
||||
|
||||
#define class_name(ptr) ((typeid(*(ptr))).name())
|
||||
#define cast_as(ptr, class) (dynamic_cast<class*>(ptr))
|
||||
#define is_kind_of(ptr, class) (cast_as(ptr, class) != 0)
|
||||
#define is_instance_of(ptr, class) (typeid(*(ptr)) == typeid(class))
|
||||
#define class_name(object) \
|
||||
((typeid(*(object))).name())
|
||||
#define cast_as(object, class) \
|
||||
(dynamic_cast<class*>(object))
|
||||
#define is_kind_of(object, class) \
|
||||
(dynamic_cast<class*>(object) != NULL)
|
||||
#define is_instance_of(object, class) \
|
||||
(typeid(*(object)) == typeid(class))
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
} // namespace OpenBeOS
|
||||
using namespace OpenBeOS;
|
||||
#endif
|
||||
|
||||
#endif /* _CLASS_INFO_H */
|
||||
#endif // _CLASS_INFO_H
|
||||
|
||||
@@ -1,36 +1,29 @@
|
||||
// Modified BeOS header. Just here to be able to compile and test BPath.
|
||||
// To be replaced by the OpenBeOS version to be provided by the IK Team.
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _FLATTENABLE_H
|
||||
#define _FLATTENABLE_H
|
||||
|
||||
#ifndef __sk_flattenable_h__
|
||||
#define __sk_flattenable_h__
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*----- BFlattenable class ------------------------------------*/
|
||||
|
||||
class BFlattenable {
|
||||
public:
|
||||
public:
|
||||
virtual bool IsFixedSize() const = 0;
|
||||
virtual type_code TypeCode() const = 0;
|
||||
virtual ssize_t FlattenedSize() const = 0;
|
||||
virtual status_t Flatten(void* buffer, ssize_t size) const = 0;
|
||||
virtual bool AllowsTypeCode(type_code code) const;
|
||||
virtual status_t Unflatten(type_code code, const void* buffer, ssize_t size) = 0;
|
||||
|
||||
virtual bool IsFixedSize() const = 0;
|
||||
virtual type_code TypeCode() const = 0;
|
||||
virtual ssize_t FlattenedSize() const = 0;
|
||||
virtual status_t Flatten(void *buffer, ssize_t size) const = 0;
|
||||
virtual bool AllowsTypeCode(type_code code) const;
|
||||
virtual status_t Unflatten(type_code c, const void *buf, ssize_t size) = 0;
|
||||
virtual ~BFlattenable();
|
||||
|
||||
virtual ~BFlattenable(); // was a reserved virtual in R4.0
|
||||
|
||||
/*----- Private or reserved ---------------*/
|
||||
|
||||
private:
|
||||
void _ReservedFlattenable1();
|
||||
virtual void _ReservedFlattenable2();
|
||||
virtual void _ReservedFlattenable3();
|
||||
private:
|
||||
void _ReservedFlattenable1();
|
||||
virtual void _ReservedFlattenable2();
|
||||
virtual void _ReservedFlattenable3();
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
#endif // __sk_flattenable_h__
|
||||
|
||||
#endif // _FLATTENABLE_H
|
||||
|
||||
+54
-83
@@ -1,98 +1,69 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// 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: List.h
|
||||
// Author(s): The Storage kit Team
|
||||
// Description: BList class provides storage for pointers.
|
||||
// Not thread safe..
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _BE_LIST_H
|
||||
#define _BE_LIST_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
/*----- BList class --------------------------------------*/
|
||||
|
||||
class BList {
|
||||
public:
|
||||
BList(int32 count = 20);
|
||||
BList(const BList& anotherList);
|
||||
virtual ~BList();
|
||||
|
||||
public:
|
||||
BList(int32 count = 20);
|
||||
BList(const BList& anotherList);
|
||||
virtual ~BList();
|
||||
BList& operator =(const BList &);
|
||||
|
||||
BList& operator =(const BList &);
|
||||
|
||||
/* Adding and removing items. */
|
||||
bool AddItem(void *item, int32 index);
|
||||
bool AddItem(void *item);
|
||||
bool AddList(const BList *list, int32 index);
|
||||
bool AddList(const BList *list);
|
||||
bool RemoveItem(void *item);
|
||||
void *RemoveItem(int32 index);
|
||||
bool RemoveItems(int32 index, int32 count);
|
||||
bool ReplaceItem(int32 index, void *newItem);
|
||||
void MakeEmpty();
|
||||
|
||||
/* Reordering items. */
|
||||
void SortItems(int (*compareFunc)(const void *, const void *));
|
||||
bool SwapItems(int32 indexA, int32 indexB);
|
||||
bool MoveItem(int32 fromIndex, int32 toIndex);
|
||||
/* Adding and removing items. */
|
||||
bool AddItem(void* item, int32 index);
|
||||
bool AddItem(void* item);
|
||||
bool AddList(const BList* list, int32 index);
|
||||
bool AddList(const BList* list);
|
||||
bool RemoveItem(void* item);
|
||||
void* RemoveItem(int32 index);
|
||||
bool RemoveItems(int32 index, int32 count);
|
||||
bool ReplaceItem(int32 index, void* newItem);
|
||||
void MakeEmpty();
|
||||
|
||||
/* Retrieving items. */
|
||||
void *ItemAt(int32 index) const;
|
||||
void *FirstItem() const;
|
||||
|
||||
/* Be careful when using this function, since it doesn't */
|
||||
/* check if the index you pass is valid, and can lead to */
|
||||
/* unexpected results when it isn't. */
|
||||
void *ItemAtFast(int32) const;
|
||||
|
||||
void *LastItem() const;
|
||||
void *Items() const;
|
||||
// Reorder items
|
||||
void SortItems(int (*compareFunc)(const void*, const void*));
|
||||
bool SwapItems(int32 indexA, int32 indexB);
|
||||
bool MoveItem(int32 fromIndex, int32 toIndex);
|
||||
|
||||
/* Querying the list. */
|
||||
bool HasItem(void *item) const;
|
||||
int32 IndexOf(void *item) const;
|
||||
int32 CountItems() const;
|
||||
bool IsEmpty() const;
|
||||
|
||||
/* Iterating over the list. */
|
||||
void DoForEach(bool (*func)(void *));
|
||||
void DoForEach(bool (*func)(void *, void *), void *arg2);
|
||||
|
||||
/*----- Private or reserved ---------------*/
|
||||
|
||||
private:
|
||||
virtual void _ReservedList1();
|
||||
virtual void _ReservedList2();
|
||||
// Retrieve items
|
||||
void* ItemAt(int32 index) const;
|
||||
void* FirstItem() const;
|
||||
void* ItemAtFast(int32) const;
|
||||
// does not check the array bounds!
|
||||
|
||||
// return type differs from BeOS version
|
||||
bool Resize(int32 count);
|
||||
void* LastItem() const;
|
||||
void* Items() const;
|
||||
|
||||
private:
|
||||
void** fObjectList;
|
||||
size_t fPhysicalSize;
|
||||
int32 fItemCount;
|
||||
int32 fBlockSize;
|
||||
uint32 _reserved[2];
|
||||
// Query
|
||||
bool HasItem(void* item) const;
|
||||
int32 IndexOf(void* item) const;
|
||||
int32 CountItems() const;
|
||||
bool IsEmpty() const;
|
||||
|
||||
// Iteration
|
||||
void DoForEach(bool (*func)(void* item));
|
||||
void DoForEach(bool (*func)(void* item, void* arg2), void *arg2);
|
||||
|
||||
private:
|
||||
virtual void _ReservedList1();
|
||||
virtual void _ReservedList2();
|
||||
|
||||
bool Resize(int32 count);
|
||||
|
||||
private:
|
||||
void** fObjectList;
|
||||
size_t fPhysicalSize;
|
||||
int32 fItemCount;
|
||||
int32 fBlockSize;
|
||||
uint32 _reserved[2];
|
||||
};
|
||||
|
||||
#endif // _BE_LIST_H
|
||||
|
||||
+30
-49
@@ -1,62 +1,43 @@
|
||||
//
|
||||
// $Id: Locker.h 10 2002-07-09 12:24:59Z ejakowatz $
|
||||
//
|
||||
// This is the BLocker interface for OpenBeOS. It has been created to
|
||||
// be source and binary compatible with the BeOS version of BLocker.
|
||||
//
|
||||
|
||||
|
||||
#ifndef _OPENBEOS_LOCKER_H
|
||||
#define _OPENBEOS_LOCKER_H
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _LOCKER_H
|
||||
#define _LOCKER_H
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
namespace OpenBeOS {
|
||||
#endif
|
||||
|
||||
class BLocker {
|
||||
public:
|
||||
BLocker();
|
||||
BLocker(const char *name);
|
||||
BLocker(bool benaphore_style);
|
||||
BLocker(const char *name, bool benaphore_style);
|
||||
|
||||
// The following constructor is not documented in the BeBook
|
||||
// and is only listed here to ensure binary compatibility.
|
||||
// DO NOT USE THIS CONSTRUCTOR!
|
||||
BLocker(const char *name, bool benaphore_style, bool);
|
||||
public:
|
||||
BLocker();
|
||||
BLocker(const char* name);
|
||||
BLocker(bool benaphoreStyle);
|
||||
BLocker(const char* name, bool benaphoreStyle);
|
||||
virtual ~BLocker();
|
||||
|
||||
virtual ~BLocker();
|
||||
bool Lock(void);
|
||||
status_t LockWithTimeout(bigtime_t timeout);
|
||||
void Unlock(void);
|
||||
|
||||
bool Lock(void);
|
||||
status_t LockWithTimeout(bigtime_t timeout);
|
||||
void Unlock(void);
|
||||
thread_id LockingThread(void) const;
|
||||
bool IsLocked(void) const;
|
||||
int32 CountLocks(void) const;
|
||||
int32 CountLockRequests(void) const;
|
||||
sem_id Sem(void) const;
|
||||
|
||||
thread_id LockingThread(void) const;
|
||||
bool IsLocked(void) const;
|
||||
int32 CountLocks(void) const;
|
||||
int32 CountLockRequests(void) const;
|
||||
sem_id Sem(void) const;
|
||||
private:
|
||||
BLocker(const char *name, bool benaphoreStyle, bool);
|
||||
void InitLocker(const char *name, bool benaphore_style);
|
||||
bool AcquireLock(bigtime_t timeout, status_t *error);
|
||||
|
||||
private:
|
||||
void InitLocker(const char *name, bool benaphore_style);
|
||||
bool AcquireLock(bigtime_t timeout, status_t *error);
|
||||
int32 fBenaphoreCount;
|
||||
sem_id fSemaphoreID;
|
||||
thread_id fLockOwner;
|
||||
int32 fRecursiveCount;
|
||||
|
||||
int32 fBenaphoreCount;
|
||||
sem_id fSemaphoreID;
|
||||
thread_id fLockOwner;
|
||||
int32 fRecursiveCount;
|
||||
|
||||
// Reserved space for future changes to BLocker
|
||||
int32 fReservedSpace[4];
|
||||
int32 _reserved[4];
|
||||
};
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _OPENBEOS_LOCKER_H
|
||||
#endif // _LOCKER_H
|
||||
|
||||
@@ -1,41 +1,38 @@
|
||||
#ifndef _BLUE_STOP_WATCH_H
|
||||
#define _BLUE_STOP_WATCH_H
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _STOP_WATCH_H
|
||||
#define _STOP_WATCH_H
|
||||
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
namespace OpenBeOS {
|
||||
#endif
|
||||
|
||||
class BStopWatch {
|
||||
public:
|
||||
BStopWatch(const char *name, bool silent = false);
|
||||
virtual ~BStopWatch();
|
||||
public:
|
||||
BStopWatch(const char* name, bool silent = false);
|
||||
virtual ~BStopWatch();
|
||||
|
||||
void Suspend();
|
||||
void Resume();
|
||||
bigtime_t Lap();
|
||||
bigtime_t ElapsedTime() const;
|
||||
void Reset();
|
||||
const char *Name() const;
|
||||
void Suspend();
|
||||
void Resume();
|
||||
bigtime_t Lap();
|
||||
bigtime_t ElapsedTime() const;
|
||||
void Reset();
|
||||
const char* Name() const;
|
||||
|
||||
private:
|
||||
virtual void _ReservedStopWatch1();
|
||||
virtual void _ReservedStopWatch2();
|
||||
private:
|
||||
virtual void _ReservedStopWatch1();
|
||||
virtual void _ReservedStopWatch2();
|
||||
|
||||
bigtime_t fStart;
|
||||
bigtime_t fSuspendTime;
|
||||
bigtime_t fLaps[10];
|
||||
int32 fLap;
|
||||
const char *fName;
|
||||
uint32 _reserved[2]; // these are for fName to be initiased
|
||||
bool fSilent;
|
||||
bigtime_t fStart;
|
||||
bigtime_t fSuspendTime;
|
||||
bigtime_t fLaps[10];
|
||||
int32 fLap;
|
||||
const char* fName;
|
||||
uint32 _reserved[2];
|
||||
bool fSilent;
|
||||
};
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
} // namespace OpenBeOS
|
||||
using namespace OpenBeOS;
|
||||
#endif
|
||||
|
||||
#endif /* _STOP_WATCH_H */
|
||||
#endif // _STOP_WATCH_H
|
||||
|
||||
@@ -1,49 +1,28 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2004-2005, Haiku
|
||||
//
|
||||
// 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: SupportDefs.h
|
||||
// Author: Erik Jaesler ([email protected])
|
||||
// Description: Common type definitions.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Author:
|
||||
* Erik Jaesler ([email protected])
|
||||
*/
|
||||
#ifndef _SUPPORT_DEFS_H
|
||||
#define _SUPPORT_DEFS_H
|
||||
|
||||
/* this !must! be located before the include of sys/types.h */
|
||||
|
||||
/* this must be located before the include of sys/types.h */
|
||||
#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned short ushort;
|
||||
#endif
|
||||
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <BeBuild.h>
|
||||
#include <sys/types.h>
|
||||
#include <Errors.h>
|
||||
|
||||
// Shorthand type formats ------------------------------------------------------
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
// Shorthand type formats
|
||||
typedef signed char int8;
|
||||
typedef unsigned char uint8;
|
||||
typedef volatile signed char vint8;
|
||||
@@ -59,9 +38,9 @@ typedef unsigned long uint32;
|
||||
typedef volatile long vint32;
|
||||
typedef volatile unsigned long vuint32;
|
||||
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
typedef volatile long long vint64;
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
typedef volatile long long vint64;
|
||||
typedef volatile unsigned long long vuint64;
|
||||
|
||||
typedef volatile long vlong;
|
||||
@@ -78,24 +57,20 @@ typedef unsigned char uchar;
|
||||
typedef unsigned short unichar;
|
||||
|
||||
|
||||
// Descriptive formats ---------------------------------------------------------
|
||||
// Descriptive formats
|
||||
typedef int32 status_t;
|
||||
typedef int64 bigtime_t;
|
||||
typedef uint32 type_code;
|
||||
typedef uint32 perform_code;
|
||||
|
||||
|
||||
// Empty string ("") -----------------------------------------------------------
|
||||
// Empty string ("")
|
||||
#ifdef __cplusplus
|
||||
extern _IMPEXP_BE const char *B_EMPTY_STRING;
|
||||
extern const char *B_EMPTY_STRING;
|
||||
#endif
|
||||
|
||||
|
||||
// min and max comparisons -----------------------------------------------------
|
||||
// min() and max() won't work in C++
|
||||
#define min_c(a,b) ((a)>(b)?(b):(a))
|
||||
#define max_c(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
// min and max comparisons
|
||||
#ifndef __cplusplus
|
||||
# ifndef min
|
||||
# define min(a,b) ((a)>(b)?(b):(a))
|
||||
@@ -105,8 +80,12 @@ extern _IMPEXP_BE const char *B_EMPTY_STRING;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// min() and max() won't work in C++
|
||||
#define min_c(a,b) ((a)>(b)?(b):(a))
|
||||
#define max_c(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
// Grandfathering --------------------------------------------------------------
|
||||
|
||||
// Grandfathering
|
||||
#ifndef __cplusplus
|
||||
# include <stdbool.h>
|
||||
#endif
|
||||
@@ -116,34 +95,33 @@ extern _IMPEXP_BE const char *B_EMPTY_STRING;
|
||||
#endif
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//----- Atomic functions; old value is returned --------------------------------
|
||||
extern _IMPEXP_ROOT int32 atomic_set(vint32 *value, int32 newValue);
|
||||
extern _IMPEXP_ROOT int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst);
|
||||
extern _IMPEXP_ROOT int32 atomic_add(vint32 *value, int32 addValue);
|
||||
extern _IMPEXP_ROOT int32 atomic_and(vint32 *value, int32 andValue);
|
||||
extern _IMPEXP_ROOT int32 atomic_or(vint32 *value, int32 orValue);
|
||||
extern _IMPEXP_ROOT int32 atomic_get(vint32 *value);
|
||||
// Atomic functions; previous value is returned
|
||||
extern int32 atomic_set(vint32 *value, int32 newValue);
|
||||
extern int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst);
|
||||
extern int32 atomic_add(vint32 *value, int32 addValue);
|
||||
extern int32 atomic_and(vint32 *value, int32 andValue);
|
||||
extern int32 atomic_or(vint32 *value, int32 orValue);
|
||||
extern int32 atomic_get(vint32 *value);
|
||||
|
||||
extern _IMPEXP_ROOT int64 atomic_set64(vint64 *value, int64 newValue);
|
||||
extern _IMPEXP_ROOT int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst);
|
||||
extern _IMPEXP_ROOT int64 atomic_add64(vint64 *value, int64 addValue);
|
||||
extern _IMPEXP_ROOT int64 atomic_and64(vint64 *value, int64 andValue);
|
||||
extern _IMPEXP_ROOT int64 atomic_or64(vint64 *value, int64 orValue);
|
||||
extern _IMPEXP_ROOT int64 atomic_get64(vint64 *value);
|
||||
extern int64 atomic_set64(vint64 *value, int64 newValue);
|
||||
extern int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst);
|
||||
extern int64 atomic_add64(vint64 *value, int64 addValue);
|
||||
extern int64 atomic_and64(vint64 *value, int64 andValue);
|
||||
extern int64 atomic_or64(vint64 *value, int64 orValue);
|
||||
extern int64 atomic_get64(vint64 *value);
|
||||
|
||||
// Other stuff -----------------------------------------------------------------
|
||||
extern _IMPEXP_ROOT void * get_stack_frame(void);
|
||||
// Other stuff
|
||||
extern void* get_stack_frame(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
//-------- Obsolete or discouraged API -----------------------------------------
|
||||
// Obsolete or discouraged API
|
||||
|
||||
// use 'true' and 'false'
|
||||
#ifndef FALSE
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
/*
|
||||
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _TLS_H
|
||||
#define _TLS_H
|
||||
/*
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
/* A maximum of 64 keys is allowed to store in TLS - the key is reserved
|
||||
* process-wide. Note that tls_allocate() will return B_NO_MEMORY if you
|
||||
* try to exceed this limit.
|
||||
*/
|
||||
#define TLS_MAX_KEYS 64
|
||||
#define TLS_MAX_KEYS 64
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+44
-55
@@ -1,70 +1,59 @@
|
||||
/******************************************************************************
|
||||
/
|
||||
/ File: UTF8.h
|
||||
/
|
||||
/ Description: UTF-8 conversion functions.
|
||||
/
|
||||
/ Copyright 1993-98, Be Incorporated
|
||||
/
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _UTF8_H
|
||||
#define _UTF8_H
|
||||
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
/*------- Conversion Flavors ---------------------------------*/
|
||||
|
||||
// Conversion Flavors
|
||||
enum {
|
||||
B_ISO1_CONVERSION, /* ISO 8859-1 */
|
||||
B_ISO2_CONVERSION, /* ISO 8859-2 */
|
||||
B_ISO3_CONVERSION, /* ISO 8859-3 */
|
||||
B_ISO4_CONVERSION, /* ISO 8859-4 */
|
||||
B_ISO5_CONVERSION, /* ISO 8859-5 */
|
||||
B_ISO6_CONVERSION, /* ISO 8859-6 */
|
||||
B_ISO7_CONVERSION, /* ISO 8859-7 */
|
||||
B_ISO8_CONVERSION, /* ISO 8859-8 */
|
||||
B_ISO9_CONVERSION, /* ISO 8859-9 */
|
||||
B_ISO10_CONVERSION, /* ISO 8859-10 */
|
||||
B_MAC_ROMAN_CONVERSION, /* Macintosh Roman */
|
||||
B_SJIS_CONVERSION, /* Shift-JIS */
|
||||
B_EUC_CONVERSION, /* EUC Packed Japanese */
|
||||
B_JIS_CONVERSION, /* JIS X 0208-1990 */
|
||||
B_MS_WINDOWS_CONVERSION, /* MS-Windows Codepage 1252 */
|
||||
B_UNICODE_CONVERSION, /* Unicode 2.0 */
|
||||
B_KOI8R_CONVERSION, /* KOI8-R */
|
||||
B_MS_WINDOWS_1251_CONVERSION, /* MS-Windows Codepage 1251 */
|
||||
B_MS_DOS_866_CONVERSION, /* MS-DOS Codepage 866 */
|
||||
B_MS_DOS_CONVERSION, /* MS-DOS Codepage 437 */
|
||||
B_EUC_KR_CONVERSION, /* EUC Korean */
|
||||
B_ISO13_CONVERSION, /* ISO 8859-13 */
|
||||
B_ISO14_CONVERSION, /* ISO 8859-14 */
|
||||
B_ISO15_CONVERSION, /* ISO 8859-15 */
|
||||
B_ISO1_CONVERSION, // ISO 8859-x
|
||||
B_ISO2_CONVERSION,
|
||||
B_ISO3_CONVERSION,
|
||||
B_ISO4_CONVERSION,
|
||||
B_ISO5_CONVERSION,
|
||||
B_ISO6_CONVERSION,
|
||||
B_ISO7_CONVERSION,
|
||||
B_ISO8_CONVERSION,
|
||||
B_ISO9_CONVERSION,
|
||||
B_ISO10_CONVERSION,
|
||||
B_MAC_ROMAN_CONVERSION, // Macintosh Roman
|
||||
B_SJIS_CONVERSION, // Shift-JIS
|
||||
B_EUC_CONVERSION, // EUC Packed Japanese
|
||||
B_JIS_CONVERSION, // JIS X 0208-1990
|
||||
B_MS_WINDOWS_CONVERSION, // Windows Latin-1 Codepage 1252
|
||||
B_UNICODE_CONVERSION, // Unicode 2.0, UCS-2
|
||||
B_KOI8R_CONVERSION, // KOI8-R
|
||||
B_MS_WINDOWS_1251_CONVERSION, // Windows Cyrillic Codepage 1251
|
||||
B_MS_DOS_866_CONVERSION, // MS-DOS Codepage 866
|
||||
B_MS_DOS_CONVERSION, // MS-DOS Codepage 437
|
||||
B_EUC_KR_CONVERSION, // EUC Korean
|
||||
B_ISO13_CONVERSION,
|
||||
B_ISO14_CONVERSION,
|
||||
B_ISO15_CONVERSION,
|
||||
B_BIG5_CONVERSION, // Chinese Big5
|
||||
B_GBK_CONVERSION, // Chinese GB18030
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*------- Conversion Functions --------------------------------*/
|
||||
|
||||
_IMPEXP_TEXTENCODING status_t convert_to_utf8(uint32 srcEncoding,
|
||||
const char *src,
|
||||
int32 *srcLen,
|
||||
char *dst,
|
||||
int32 *dstLen,
|
||||
int32 *state,
|
||||
char substitute = B_SUBSTITUTE);
|
||||
// Conversion Functions
|
||||
|
||||
_IMPEXP_TEXTENCODING status_t convert_from_utf8(uint32 dstEncoding,
|
||||
const char *src,
|
||||
int32 *srcLen,
|
||||
char *dst,
|
||||
int32 *dstLen,
|
||||
int32 *state,
|
||||
char substitute = B_SUBSTITUTE);
|
||||
#ifdef __cplusplus
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
status_t convert_to_utf8(uint32 sourceEncoding, const char* source,
|
||||
int32* sourceLength, char* dest, int32* destLength, int32* state,
|
||||
char substitute = B_SUBSTITUTE);
|
||||
|
||||
status_t convert_from_utf8(uint32 destEncoding, const char* source,
|
||||
int32* sourceLength, char* dest, int32* destLength, int32* state,
|
||||
char substitute = B_SUBSTITUTE);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _UTF8_H */
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/*
|
||||
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PARSEDATE_H
|
||||
#define _PARSEDATE_H
|
||||
/*
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <time.h>
|
||||
@@ -20,10 +21,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern time_t parsedate(const char *dateString, time_t now);
|
||||
extern time_t parsedate_etc(const char *dateString, time_t now, int *_storedFlags);
|
||||
extern time_t parsedate(const char *dateString, time_t now);
|
||||
extern time_t parsedate_etc(const char *dateString, time_t now, int *_storedFlags);
|
||||
|
||||
extern void set_dateformats(const char *table[]);
|
||||
extern void set_dateformats(const char *table[]);
|
||||
extern const char **get_dateformats(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+109
-102
@@ -1,17 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2005, Haiku
|
||||
* Copyright (c) 2001-2007, Haiku
|
||||
* Distributed under the terms of the MIT license
|
||||
*
|
||||
* Authors:
|
||||
Stefano Ceccherini ([email protected])
|
||||
* Stefano Ceccherini ([email protected])
|
||||
*/
|
||||
|
||||
// A buffered adapter for BPositionIO objects.
|
||||
|
||||
//! A buffered adapter for BPositionIO objects.
|
||||
|
||||
|
||||
#include <BufferIO.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <BufferIO.h>
|
||||
|
||||
/*! \class BBufferIO
|
||||
\brief A buffered adapter for BPositionIO objects.
|
||||
@@ -28,43 +31,46 @@
|
||||
\param buf_size The size of the buffer that the object will allocate and use.
|
||||
\param owns_stream Specifies if the object will delete the stream on destruction.
|
||||
*/
|
||||
BBufferIO::BBufferIO(BPositionIO *stream, size_t buf_size, bool owns_stream)
|
||||
:m_buffer_start(0),
|
||||
m_stream(stream),
|
||||
m_buffer(NULL),
|
||||
m_buffer_used(0),
|
||||
m_buffer_dirty(false),
|
||||
m_owns_stream(owns_stream)
|
||||
BBufferIO::BBufferIO(BPositionIO *stream, size_t bufferSize, bool ownsStream)
|
||||
:
|
||||
fBufferStart(0),
|
||||
fStream(stream),
|
||||
fBuffer(NULL),
|
||||
fBufferUsed(0),
|
||||
fBufferIsDirty(false),
|
||||
fOwnsStream(ownsStream)
|
||||
|
||||
{
|
||||
if (buf_size < 512)
|
||||
buf_size = 512;
|
||||
if (bufferSize < 512)
|
||||
bufferSize = 512;
|
||||
|
||||
m_buffer_phys = buf_size;
|
||||
fBufferSize = bufferSize;
|
||||
|
||||
// What can we do if this malloc fails ?
|
||||
// I think R5 uses new, but doesn't catch the thrown exception
|
||||
// (if you specify a very big buffer, the application just
|
||||
// terminates with abort).
|
||||
m_buffer = (char *)malloc(m_buffer_phys * sizeof(char));
|
||||
// terminates with abort).
|
||||
fBuffer = (char *)malloc(fBufferSize);
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Frees the resources allocated by the object
|
||||
|
||||
|
||||
Flushes pending changes to the stream and frees the allocated memory.
|
||||
If the owns_stream property is true, the destructor also
|
||||
deletes the stream associated with the BBufferIO object.
|
||||
*/
|
||||
BBufferIO::~BBufferIO()
|
||||
{
|
||||
if (m_buffer_dirty)
|
||||
Flush(); // Writes pending changes to the stream
|
||||
if (fBufferIsDirty) {
|
||||
// Write pending changes to the stream
|
||||
Flush();
|
||||
}
|
||||
|
||||
free(m_buffer);
|
||||
|
||||
if (m_owns_stream)
|
||||
delete m_stream;
|
||||
free(fBuffer);
|
||||
|
||||
if (fOwnsStream)
|
||||
delete fStream;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,41 +86,40 @@ BBufferIO::ReadAt(off_t pos, void *buffer, size_t size)
|
||||
// We refuse to crash, even if
|
||||
// you were lazy and didn't give a valid
|
||||
// stream on construction.
|
||||
if (m_stream == NULL)
|
||||
if (fStream == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
|
||||
if (buffer == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
|
||||
// If the amount of data we want doesn't fit in the buffer, just
|
||||
// read it directly from the disk (and don't touch the buffer).
|
||||
if (size > m_buffer_phys) {
|
||||
if (m_buffer_dirty)
|
||||
if (size > fBufferSize) {
|
||||
if (fBufferIsDirty)
|
||||
Flush();
|
||||
return m_stream->ReadAt(pos, buffer, size);
|
||||
return fStream->ReadAt(pos, buffer, size);
|
||||
}
|
||||
|
||||
|
||||
// If the data we are looking for is not in the buffer...
|
||||
if (size > m_buffer_used
|
||||
|| pos < m_buffer_start
|
||||
|| pos > m_buffer_start + m_buffer_used
|
||||
|| pos + size > m_buffer_start + m_buffer_used) {
|
||||
|
||||
if (m_buffer_dirty)
|
||||
if (size > fBufferUsed
|
||||
|| pos < fBufferStart
|
||||
|| pos > fBufferStart + fBufferUsed
|
||||
|| pos + size > fBufferStart + fBufferUsed) {
|
||||
if (fBufferIsDirty)
|
||||
Flush(); // If there are pending writes, do them.
|
||||
|
||||
|
||||
// ...cache as much as we can from the stream
|
||||
m_buffer_used = m_stream->ReadAt(pos, m_buffer, m_buffer_phys);
|
||||
|
||||
if (m_buffer_used > 0)
|
||||
m_buffer_start = pos; // The data is buffered starting from this offset
|
||||
fBufferUsed = fStream->ReadAt(pos, fBuffer, fBufferSize);
|
||||
|
||||
if (fBufferUsed > 0)
|
||||
fBufferStart = pos; // The data is buffered starting from this offset
|
||||
}
|
||||
|
||||
size = min_c(size, m_buffer_used);
|
||||
|
||||
|
||||
size = min_c(size, fBufferUsed);
|
||||
|
||||
// copy data from the cache to the given buffer
|
||||
memcpy(buffer, m_buffer + pos - m_buffer_start, size);
|
||||
|
||||
memcpy(buffer, fBuffer + pos - fBufferStart, size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -128,45 +133,45 @@ BBufferIO::ReadAt(off_t pos, void *buffer, size_t size)
|
||||
ssize_t
|
||||
BBufferIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
||||
{
|
||||
if (m_stream == NULL)
|
||||
if (fStream == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
|
||||
if (buffer == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
|
||||
// If data doesn't fit into the buffer, write it directly to the stream
|
||||
if (size > m_buffer_phys)
|
||||
return m_stream->WriteAt(pos, buffer, size);
|
||||
|
||||
if (size > fBufferSize)
|
||||
return fStream->WriteAt(pos, buffer, size);
|
||||
|
||||
// If we have cached data in the buffer, whose offset into the stream
|
||||
// is > 0, and the buffer isn't dirty, drop the data.
|
||||
if (!m_buffer_dirty && m_buffer_start > pos) {
|
||||
m_buffer_start = 0;
|
||||
m_buffer_used = 0;
|
||||
if (!fBufferIsDirty && fBufferStart > pos) {
|
||||
fBufferStart = 0;
|
||||
fBufferUsed = 0;
|
||||
}
|
||||
|
||||
|
||||
// If we want to write beyond the cached data...
|
||||
if (pos > m_buffer_start + m_buffer_used
|
||||
|| pos < m_buffer_start) {
|
||||
if (pos > fBufferStart + fBufferUsed
|
||||
|| pos < fBufferStart) {
|
||||
ssize_t read;
|
||||
off_t where = pos;
|
||||
|
||||
if (pos + size <= m_buffer_phys) // Can we just cache from the beginning ?
|
||||
|
||||
if (pos + size <= fBufferSize) // Can we just cache from the beginning ?
|
||||
where = 0;
|
||||
|
||||
|
||||
// ...cache more.
|
||||
read = m_stream->ReadAt(where, m_buffer, m_buffer_phys);
|
||||
read = fStream->ReadAt(where, fBuffer, fBufferSize);
|
||||
if (read > 0) {
|
||||
m_buffer_used = read;
|
||||
m_buffer_start = where;
|
||||
fBufferUsed = read;
|
||||
fBufferStart = where;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(m_buffer + pos - m_buffer_start, buffer, size);
|
||||
|
||||
m_buffer_dirty = true;
|
||||
m_buffer_used = max_c((size + pos), m_buffer_used);
|
||||
|
||||
|
||||
memcpy(fBuffer + pos - fBufferStart, buffer, size);
|
||||
|
||||
fBufferIsDirty = true;
|
||||
fBufferUsed = max_c((size + pos), fBufferUsed);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -194,12 +199,12 @@ BBufferIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
||||
from the beginning of the stream.
|
||||
*/
|
||||
off_t
|
||||
BBufferIO::Seek(off_t position, uint32 seek_mode)
|
||||
BBufferIO::Seek(off_t position, uint32 seekMode)
|
||||
{
|
||||
if (m_stream == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return m_stream->Seek(position, seek_mode);
|
||||
if (fStream == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fStream->Seek(position, seekMode);
|
||||
}
|
||||
|
||||
|
||||
@@ -210,10 +215,10 @@ BBufferIO::Seek(off_t position, uint32 seek_mode)
|
||||
off_t
|
||||
BBufferIO::Position() const
|
||||
{
|
||||
if (m_stream == NULL)
|
||||
if (fStream == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return m_stream->Position();
|
||||
|
||||
return fStream->Position();
|
||||
}
|
||||
|
||||
|
||||
@@ -224,10 +229,10 @@ BBufferIO::Position() const
|
||||
status_t
|
||||
BBufferIO::SetSize(off_t size)
|
||||
{
|
||||
if (m_stream == NULL)
|
||||
if (fStream == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return m_stream->SetSize(size);
|
||||
return fStream->SetSize(size);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,16 +242,15 @@ BBufferIO::SetSize(off_t size)
|
||||
status_t
|
||||
BBufferIO::Flush()
|
||||
{
|
||||
if (!m_buffer_dirty)
|
||||
if (!fBufferIsDirty)
|
||||
return B_OK;
|
||||
|
||||
|
||||
// Write the cached data to the stream
|
||||
status_t err = m_stream->WriteAt(m_buffer_start, m_buffer, m_buffer_used);
|
||||
|
||||
if (err > 0)
|
||||
m_buffer_dirty = false;
|
||||
|
||||
return (err < 0) ? err : B_OK;
|
||||
ssize_t bytesWritten = fStream->WriteAt(fBufferStart, fBuffer, fBufferUsed);
|
||||
if (bytesWritten > 0)
|
||||
fBufferIsDirty = false;
|
||||
|
||||
return (bytesWritten < 0) ? bytesWritten : B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -256,7 +260,7 @@ BBufferIO::Flush()
|
||||
BPositionIO *
|
||||
BBufferIO::Stream() const
|
||||
{
|
||||
return m_stream;
|
||||
return fStream;
|
||||
}
|
||||
|
||||
|
||||
@@ -266,7 +270,7 @@ BBufferIO::Stream() const
|
||||
size_t
|
||||
BBufferIO::BufferSize() const
|
||||
{
|
||||
return m_buffer_phys;
|
||||
return fBufferSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -277,7 +281,7 @@ BBufferIO::BufferSize() const
|
||||
bool
|
||||
BBufferIO::OwnsStream() const
|
||||
{
|
||||
return m_owns_stream;
|
||||
return fOwnsStream;
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +292,7 @@ BBufferIO::OwnsStream() const
|
||||
void
|
||||
BBufferIO::SetOwnsStream(bool owns_stream)
|
||||
{
|
||||
m_owns_stream = owns_stream;
|
||||
fOwnsStream = owns_stream;
|
||||
}
|
||||
|
||||
|
||||
@@ -297,18 +301,21 @@ BBufferIO::SetOwnsStream(bool owns_stream)
|
||||
void
|
||||
BBufferIO::PrintToStream() const
|
||||
{
|
||||
printf("stream %p\n", m_stream);
|
||||
printf("buffer %p\n", m_buffer);
|
||||
printf("start %lld\n", m_buffer_start);
|
||||
printf("used %ld\n", m_buffer_used);
|
||||
printf("phys %ld\n", m_buffer_phys);
|
||||
printf("dirty %s\n", (m_buffer_dirty) ? "true" : "false");
|
||||
printf("owns %s\n", (m_owns_stream) ? "true" : "false");
|
||||
printf("stream %p\n", fStream);
|
||||
printf("buffer %p\n", fBuffer);
|
||||
printf("start %lld\n", fBufferStart);
|
||||
printf("used %ld\n", fBufferUsed);
|
||||
printf("phys %ld\n", fBufferSize);
|
||||
printf("dirty %s\n", (fBufferIsDirty) ? "true" : "false");
|
||||
printf("owns %s\n", (fOwnsStream) ? "true" : "false");
|
||||
}
|
||||
|
||||
|
||||
// These functions are here to maintain future binary
|
||||
// compatibility.
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
// These functions are here to maintain future binary
|
||||
// compatibility.
|
||||
status_t BBufferIO::_Reserved_BufferIO_0(void *) { return B_ERROR; }
|
||||
status_t BBufferIO::_Reserved_BufferIO_1(void *) { return B_ERROR; }
|
||||
status_t BBufferIO::_Reserved_BufferIO_2(void *) { return B_ERROR; }
|
||||
|
||||
Reference in New Issue
Block a user