* book.dox Reformat according to the guidelines
* BufferIO.dox Reformat according to the guidelines * DataIO.dox Reformat according to the guidelines * Flattenable.dox New documentation. * Locker.dox Finished documentation. * SupportDefs.dox Reformat according to the guidelines git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20511 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+3
-2
@@ -9,9 +9,10 @@
|
||||
|
||||
\section notes General Notes and Information
|
||||
- \ref compatibility
|
||||
- \ref apidoc
|
||||
*/
|
||||
|
||||
// Define main kits
|
||||
///// Define main kits /////
|
||||
|
||||
/*!
|
||||
\defgroup midi2 MIDI 2 Kit
|
||||
@@ -23,7 +24,7 @@
|
||||
\defgroup libroot (libroot.so)
|
||||
*/
|
||||
|
||||
// Subgroups
|
||||
///// Subgroups /////
|
||||
|
||||
/*!
|
||||
\defgroup support_globals Global functions in the support kit
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Documentation by:
|
||||
* Niels Sascha Reedijk <[email protected]>
|
||||
* Stefano Ceccherini ([email protected])
|
||||
* Corresponds to:
|
||||
* /trunk/headers/os/support/BufferIO.h rev 19972
|
||||
* /trunk/src/kits/support/BufferIO.cpp rev 20510
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file BufferIO.h
|
||||
\brief Provides the BBufferIO class.
|
||||
@@ -45,8 +57,10 @@ The constructor will create a buffer of the given size
|
||||
and associate the object with the given BPositionIO stream.
|
||||
|
||||
\param stream A pointer to a BPositionIO object.
|
||||
\param bufferSize The size of the buffer that the object will allocate and use.
|
||||
\param ownsStream Specifies if the object will delete the stream on destruction.
|
||||
\param bufferSize The size of the buffer that the object will allocate and
|
||||
use.
|
||||
\param ownsStream Specifies if the object will delete the stream on
|
||||
destruction.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -66,7 +80,8 @@ deletes the stream associated with the BBufferIO object.
|
||||
\param buffer A pointer to a buffer where to copy the read data.
|
||||
\param size The amount of bytes to read.
|
||||
\return The amount of bytes actually read, or an error code.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO stream.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO
|
||||
stream.
|
||||
\retval B_BAD_VALUE The \c buffer parameter is not valid.
|
||||
*/
|
||||
|
||||
@@ -77,7 +92,8 @@ deletes the stream associated with the BBufferIO object.
|
||||
\param buffer A pointer to a buffer which contains the data to write.
|
||||
\param size The amount of bytes to write.
|
||||
\return The amount of bytes actually written, or an error code.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO stream.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO
|
||||
stream.
|
||||
\retval B_BAD_VALUE The \c buffer parameter is not valid.
|
||||
*/
|
||||
|
||||
@@ -91,18 +107,19 @@ deletes the stream associated with the BBufferIO object.
|
||||
|
||||
\param position The position where you want to seek.
|
||||
\param seekMode Can have three values:
|
||||
- \c SEEK_SET. The position passed is an offset from the beginning of the stream;
|
||||
in other words, the current position is set to position.
|
||||
- \c SEEK_SET. The position passed is an offset from the beginning of the
|
||||
stream; in other words, the current position is set to position.
|
||||
For this mode, position should be a positive value.
|
||||
- \c SEEK_CUR. The position argument is an offset from the current position;
|
||||
the value of the argument is added to the current position.
|
||||
- \c SEEK_END. The position argument is an offset from the end of the stream.
|
||||
In this mode the position argument should be negative (or zero).
|
||||
- \c SEEK_END. The position argument is an offset from the end of the
|
||||
stream. In this mode the position argument should be negative (or zero).
|
||||
|
||||
\return The current position as an offset in bytes
|
||||
from the beginning of the stream.
|
||||
\return The current position as an offset in bytes from the beginning of
|
||||
the stream.
|
||||
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO stream.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO
|
||||
stream.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -110,7 +127,8 @@ deletes the stream associated with the BBufferIO object.
|
||||
\brief Return the current position in the stream.
|
||||
\return The current position as an offset in bytes
|
||||
from the beginning of the stream.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO stream.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO
|
||||
stream.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -118,13 +136,15 @@ deletes the stream associated with the BBufferIO object.
|
||||
\brief Call the SetSize() function of the assigned BPositionIO stream.
|
||||
\param size The new size of the BPositionIO object.
|
||||
\retval B_OK The stream is resized.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO stream.
|
||||
\retval B_NO_INIT The object is not associated with a valid BPositionIO
|
||||
stream.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn status_t BBufferIO::Flush()
|
||||
\brief Write pending modifications to the stream.
|
||||
\return The amount of bytes written, or if it failed it will return an error code.
|
||||
\return The amount of bytes written, or if it failed it will return an error
|
||||
code.
|
||||
*/
|
||||
|
||||
|
||||
@@ -144,9 +164,10 @@ deletes the stream associated with the BBufferIO object.
|
||||
/*!
|
||||
\fn bool BBufferIO::OwnsStream() const
|
||||
\brief Tell if the BBufferIO object "owns" the specified stream.
|
||||
\retval true The object "owns" the stream and will destroy it upon destruction.
|
||||
\retval true The object "owns" the stream and will destroy it upon
|
||||
destruction.
|
||||
\retval false The object does not own the stream.
|
||||
\sa SetOwnsStream()
|
||||
\see SetOwnsStream()
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
//
|
||||
// Copyright 2007, Haiku Inc. All Rights Reserved.
|
||||
//
|
||||
// Distributed under the terms of the MIT License.
|
||||
//
|
||||
//
|
||||
// Documentation by:
|
||||
// Niels Sascha Reedijk <[email protected]>
|
||||
// Stefano Ceccherini ([email protected])
|
||||
// Corresponds to:
|
||||
// /trunk/headers/os/support/DataIO.h rev 17981
|
||||
// /trunk/src/kits/support/DataIO.cpp rev 17981
|
||||
//
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Documentation by:
|
||||
* Niels Sascha Reedijk <[email protected]>
|
||||
* Stefano Ceccherini ([email protected])
|
||||
* Corresponds to:
|
||||
* /trunk/headers/os/support/DataIO.h rev 17981
|
||||
* /trunk/src/kits/support/DataIO.cpp rev 20510
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file DataIO.h
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Documentation written by:
|
||||
* Niels Sascha Reedijk <[email protected]>
|
||||
* Corresponds to:
|
||||
* /trunk/headers/os/support/Flattenable.h rev 19972
|
||||
* /trunk/src/kits/support/Flattenable.cpp rev 12963
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file Flattenable.h
|
||||
\brief Provides the BFlattenable interface
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class BFlattenable
|
||||
\ingroup support
|
||||
\ingroup libbe
|
||||
\brief Interface for classes that can flatten and unflatten themselves to
|
||||
a stream of bytes.
|
||||
|
||||
It is convenient that objects can be stored as a flat stream of bytes. In
|
||||
this way, they can be written to disk, exchanged between applications or send
|
||||
over networks. This ability, which is known in many other programming
|
||||
languages as marshalling, is not native in C++. The Haiku API has created a
|
||||
universal interface that classes have if they are able to be flattened. This
|
||||
class defines the interface. This class does nothing on its own, and
|
||||
therefore contains pure virtuals. By inheriting this class and inmplementing
|
||||
the methods in your own class, you will be able to use your objects as
|
||||
flattenable objects throughout the Haiku API.
|
||||
|
||||
Flattened objects can be used for example when sending messages within an
|
||||
application or between applications. The BMessage class uses the interface
|
||||
to store and transmit custom classes.
|
||||
|
||||
If you want to be able to flatten your objects, you will need to implement
|
||||
various methods. Flatten() and Unflatten() are where the magic happen. These
|
||||
methods handle the actual flattening and unflattening. To identify flattened
|
||||
data in for example BMessage, the object has a type_code. Type codes are
|
||||
four byte long integers. You can choose to flatten to one of the existing
|
||||
types, if you are certain that you are compatible to those, but you'll
|
||||
usually define your own type. Your best option is by using a multicharacter
|
||||
constant, such as 'STRI'. Implement TypeCode() to return the type you
|
||||
support. Implement FlattenedSize() to make sure that other objects can
|
||||
provide the right buffers. Implement IsFixedSize() to return whether your
|
||||
objects always store to a fixed size.
|
||||
|
||||
See the following example:
|
||||
\code
|
||||
type_code CUSTOM_STRING_TYPE = 'CUST';
|
||||
|
||||
class CustomString : public BFlattenable
|
||||
{
|
||||
public:
|
||||
char data[100];
|
||||
|
||||
// From BFlattenable
|
||||
bool IsFixedSize() const { return false; };
|
||||
type_code TypeCode() const { return CUSTOM_STRING_TYPE; };
|
||||
ssize_t FlattenedSize() const { return strlen(data); };
|
||||
|
||||
status_t Flatten(void* buffer, ssize_t size) const
|
||||
{
|
||||
if ((strlen(data) + 1) < size)
|
||||
return B_BAD_VALUE;
|
||||
memcpy(buffer, data, size);
|
||||
return B_OK;
|
||||
};
|
||||
|
||||
status_t Unflatten(type_code code, const void* buffer, ssize_t size)
|
||||
{
|
||||
if (code != CUSTOM_STRING_TYPE)
|
||||
return B_BAD_TYPE;
|
||||
if (size > 100)
|
||||
return B_NO_MEMORY;
|
||||
memcpy(data, buffer, size);
|
||||
return B_OK;
|
||||
};
|
||||
};
|
||||
\endcode
|
||||
|
||||
Have a look at TypeConstants.h for a list of all the types that the Haiku
|
||||
API defines.
|
||||
|
||||
The Haiku API has a second interface for storing objects, which is with
|
||||
BArchivable. BArchivable is for more complex cases. Instead of one flat
|
||||
datastream, it stores an object in a BMessage. In that way you can reflect
|
||||
internals of a class better. It also provides an interface for instantiating
|
||||
objects, that is, for objects to restore themselves from a BMessage. In
|
||||
essence, BArchivable is more suitable for objects that are alive. In short
|
||||
BFlattenable is for data objects, BArchivable is for 'live' objects.
|
||||
|
||||
Other classes in the API that support flattening and unflattening are for
|
||||
example BMessage, which enables you to conveniently write flattened data
|
||||
to disk. Another example is BPath. Because of that you can store paths and
|
||||
send them over via messages. Throughout the Haiku API you will find classes
|
||||
that provide the flattening interface.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual bool BFlattenable::IsFixedSize() const = 0
|
||||
\brief Pure virtual that should return whether or not flattened objects of
|
||||
this type always have a fixed size.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual type_code BFlattenable::TypeCode() const = 0
|
||||
\brief Pure virtual that should return which type_code this class flattens
|
||||
to.
|
||||
|
||||
\return Either one of the existing typecodes, found in TypeConstants.h,
|
||||
<em>if your class actually is compatible to those formats</em>, or a custom
|
||||
four byte integer constant.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual ssize_t BFlattenable::FlattenedSize() const = 0
|
||||
\brief Pure virtual that should return the size of the flattened object in
|
||||
bytes.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual status_t BFlattenable::Flatten(void* buffer, ssize_t size) const = 0
|
||||
\brief Pure virtual that should flatten the object into the supplied
|
||||
\a buffer.
|
||||
|
||||
Please make sure that you check that the supplied buffer is not a \c NULL
|
||||
pointer. Also make sure that the size of the flattened object does isn't
|
||||
larger than the size of the buffer.
|
||||
|
||||
\param buffer The buffer to flatten in.
|
||||
\param size The size of the buffer.
|
||||
\retval B_OK The object was flattened.
|
||||
\retval B_NO_MEMORY The buffer was smaller than required.
|
||||
\retval B_BAD_VALUE The buffer was a \c NULL pointer.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool BFlattenable::AllowsTypeCode(type_code code) const
|
||||
\brief Return whether or not the supplied type_code is supported.
|
||||
|
||||
This default implementation checks the \a code argument against the type_code
|
||||
returned by TypeCode().
|
||||
|
||||
\param code The type_code constant you want to check for.
|
||||
\retval true The type_code is supported.
|
||||
\retval false The type_code is not supported.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual status_t BFlattenable::Unflatten(type_code code, const void* buffer, ssize_t size) = 0
|
||||
\brief Pure virtual that should unflatten the buffer and put the contents
|
||||
into the current object.
|
||||
|
||||
Make sure that the supplied buffer is not \c NULL and that you actually
|
||||
support the typecode.
|
||||
|
||||
\param code The type_code this data is.
|
||||
\param buffer The buffer to unflatten the data from.
|
||||
\param size The size of the data.
|
||||
\retval B_OK The object is unflattened.
|
||||
\retval B_BAD_VALUE The \a buffer pointer is \c NULL or the data is invalid.
|
||||
\retval B_BAD_TYPE You don't support data with this \a code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual BFlattenable::~BFlattenable()
|
||||
\brief Destructor. Does nothing.
|
||||
*/
|
||||
@@ -1,3 +1,14 @@
|
||||
/*
|
||||
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Documentation by:
|
||||
* Niels Sascha Reedijk <[email protected]>
|
||||
* Corresponds to:
|
||||
* /trunk/headers/os/support/Locker.h rev 19972
|
||||
* /trunk/src/kits/support/Locker.cpp rev 13826
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file Locker.h
|
||||
\brief Provides locking class BLocker.
|
||||
@@ -27,7 +38,8 @@ most from it's speed.
|
||||
|
||||
The other feature of BLocker that improves basic semaphore handling is that
|
||||
it allows for recursive locks. The following piece of code works with a
|
||||
BLocker, but block inevitably with a semaphore. Let's pretend I call \c Water():
|
||||
BLocker, but block inevitably with a semaphore. Let's pretend I call
|
||||
\c Water():
|
||||
|
||||
\code
|
||||
status_t
|
||||
@@ -64,51 +76,111 @@ pair every Lock() with an Unlock() though, or you'll create a deadlock.
|
||||
/*!
|
||||
\fn BLocker::BLocker()
|
||||
\brief Constructor.
|
||||
|
||||
Create a new BLocker with the default name of <tt>some BLocker</tt>. This
|
||||
BLocker will use the benaphore-style locking.
|
||||
|
||||
\note For debugging purposes, it's extremely convenient to actually give a
|
||||
name to the object. In case of a deadlock, it's easier to track down which
|
||||
BLocker object might have caused the problems.
|
||||
|
||||
\see BLocker(const char* name, bool benaphoreStyle) for all the options.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn BLocker::BLocker(const char* name)
|
||||
\brief Constructor.
|
||||
|
||||
Create a new BLocker with benaphore-style locking.
|
||||
|
||||
\param name A NULL-terminated string that contains the name of the semaphore.
|
||||
Note that the length of the names are limited to B_OS_NAME_LENGTH constant,
|
||||
which includes the \c \\0 character.
|
||||
|
||||
\see BLocker(const char* name, bool benaphoreStyle) for all the options.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn BLocker::BLocker(bool benaphoreStyle)
|
||||
\brief Constructor.
|
||||
|
||||
Creates a BLocker with the default name of <tt>some BLocker</tt>.
|
||||
|
||||
\note For debugging purposes, it's extremely convenient to actually give a
|
||||
name to the object. In case of a deadlock, it's easier to track down which
|
||||
BLocker object might have caused the problems.
|
||||
|
||||
\param benaphoreStyle If you pass \c true, the locker will be in benaphore
|
||||
style (which is the default option for other constructors). If you pass
|
||||
\c false, the object will completely rely on semaphores for it's
|
||||
functioning.
|
||||
|
||||
\see BLocker(const char* name, bool benaphoreStyle) if you also want to set a
|
||||
name.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn BLocker::BLocker(const char* name, bool benaphoreStyle)
|
||||
\brief Constructor.
|
||||
|
||||
\param name A NULL-terminated string that contains the name of the semaphore.
|
||||
Note that the length of the names are limited to B_OS_NAME_LENGTH constant,
|
||||
which includes the \c \\0 character.
|
||||
\param benaphoreStyle If you pass \c true, the locker will be in benaphore
|
||||
style (which is the default option for other constructors). If you pass
|
||||
\c false, the object will completely rely on semaphores for it's
|
||||
functioning.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual BLocker::~BLocker()
|
||||
\brief Destructor.
|
||||
|
||||
Release the internal semaphore. Because of this, any pending Lock() calls
|
||||
from other threads be cancelled. The return code will be \c false for
|
||||
those calls.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool BLocker::Lock(void)
|
||||
\fn bool BLocker::Lock()
|
||||
\brief Add a lock request and block on it until we get it.
|
||||
|
||||
\retval true Lock acquired succesfully.
|
||||
\retval false Failed to acquire the lock. Most probable cause is that the
|
||||
object is deleted. This frees the semaphore and releases the pending Lock()
|
||||
requests.
|
||||
|
||||
\see LockWithTimeout(bigtime_t timeout), Unlock()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn status_t BLocker::LockWithTimeout(bigtime_t timeout)
|
||||
\brief Add a lock request and block until we get it with a maximum time.
|
||||
\brief Add a lock request and block until we get it or until it times out.
|
||||
|
||||
\param timeout This is a timeout in microseconds (one millionth of a second),
|
||||
\e relative from now.
|
||||
|
||||
\see Lock(), Unlock()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void BLocker::Unlock(void)
|
||||
\brief Give up the lock count.
|
||||
\brief Release the lock that's currently held.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn thread_id BLocker::LockingThread(void) const
|
||||
\brief Return the \c thread_id of the thread that's currently holding the lock.
|
||||
\brief Return the \c thread_id of the thread that's currently holding the
|
||||
lock.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool BLocker::IsLocked(void) const
|
||||
\brief Check if your lock succeeded.
|
||||
\brief Check if the calling thread is actually holding the lock.
|
||||
|
||||
\retval true The thread from which this method is called from is currently
|
||||
holding the lock.
|
||||
\retval false The object is unlocked or the lock is held by another thread.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -118,10 +190,15 @@ pair every Lock() with an Unlock() though, or you'll create a deadlock.
|
||||
|
||||
/*!
|
||||
\fn nt32 BLocker::CountLockRequests(void) const
|
||||
\brief Return the number of pending lock requests.
|
||||
\brief Return the number of threads with a pending lock request.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn sem_id BLocker::Sem(void) const
|
||||
\brief Return the sem_id of the semaphore this object holds.
|
||||
|
||||
\warning Like any other internal objects that the Haiku API might expose,
|
||||
this semaphore id should in general be left alone. You should not use any
|
||||
of the public low-level semaphore functions on this semaphore, because it
|
||||
will harm the internal consistency of the object.
|
||||
*/
|
||||
|
||||
@@ -174,7 +174,8 @@
|
||||
|
||||
/*!
|
||||
\typedef typedef uint32 type_code
|
||||
\brief Represents a type code. See TypeCode.h for possible values.
|
||||
\brief Represents a certain type of data. See TypeConstants.h for possible
|
||||
values.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user