Updated BDiskDeviceList. The implementation was still reflecting the first version of the DiskDevice API. Untested.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9709 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
08387795eb
commit
5198376e54
@ -11,6 +11,7 @@
|
|||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
|
|
||||||
class BDiskDevice;
|
class BDiskDevice;
|
||||||
|
class BDiskDeviceRoster;
|
||||||
class BPartition;
|
class BPartition;
|
||||||
class BSession;
|
class BSession;
|
||||||
|
|
||||||
@ -33,11 +34,9 @@ public:
|
|||||||
|
|
||||||
BDiskDevice *VisitEachDevice(BDiskDeviceVisitor *visitor);
|
BDiskDevice *VisitEachDevice(BDiskDeviceVisitor *visitor);
|
||||||
BPartition *VisitEachPartition(BDiskDeviceVisitor *visitor);
|
BPartition *VisitEachPartition(BDiskDeviceVisitor *visitor);
|
||||||
bool Traverse(BDiskDeviceVisitor *visitor);
|
|
||||||
|
|
||||||
BPartition *VisitEachMountedPartition(BDiskDeviceVisitor *visitor);
|
BPartition *VisitEachMountedPartition(BDiskDeviceVisitor *visitor);
|
||||||
BPartition *VisitEachMountablePartition(BDiskDeviceVisitor *visitor);
|
BPartition *VisitEachMountablePartition(BDiskDeviceVisitor *visitor);
|
||||||
BPartition *VisitEachInitializablePartition(BDiskDeviceVisitor *visitor);
|
|
||||||
|
|
||||||
BDiskDevice *DeviceWithID(partition_id id) const;
|
BDiskDevice *DeviceWithID(partition_id id) const;
|
||||||
BPartition *PartitionWithID(partition_id id) const;
|
BPartition *PartitionWithID(partition_id id) const;
|
||||||
@ -45,17 +44,23 @@ public:
|
|||||||
virtual void MountPointMoved(BPartition *partition);
|
virtual void MountPointMoved(BPartition *partition);
|
||||||
virtual void PartitionMounted(BPartition *partition);
|
virtual void PartitionMounted(BPartition *partition);
|
||||||
virtual void PartitionUnmounted(BPartition *partition);
|
virtual void PartitionUnmounted(BPartition *partition);
|
||||||
|
virtual void PartitionInitialized(BPartition *partition);
|
||||||
virtual void PartitionResized(BPartition *partition);
|
virtual void PartitionResized(BPartition *partition);
|
||||||
virtual void PartitionMoved(BPartition *partition);
|
virtual void PartitionMoved(BPartition *partition);
|
||||||
virtual void PartitionCreated(BPartition *partition);
|
virtual void PartitionCreated(BPartition *partition);
|
||||||
virtual void PartitionDeleted(BPartition *partition);
|
virtual void PartitionDeleted(BPartition *partition,
|
||||||
|
partition_id partitionID);
|
||||||
virtual void PartitionDefragmented(BPartition *partition);
|
virtual void PartitionDefragmented(BPartition *partition);
|
||||||
virtual void PartitionRepaired(BPartition *partition);
|
virtual void PartitionRepaired(BPartition *partition);
|
||||||
|
virtual void PartitionChanged(BPartition *partition, uint32 event);
|
||||||
virtual void MediaChanged(BDiskDevice *device);
|
virtual void MediaChanged(BDiskDevice *device);
|
||||||
virtual void DeviceAdded(BDiskDevice *device);
|
virtual void DeviceAdded(BDiskDevice *device);
|
||||||
virtual void DeviceRemoved(BDiskDevice *device);
|
virtual void DeviceRemoved(BDiskDevice *device);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
status_t _StartWatching();
|
||||||
|
void _StopWatching();
|
||||||
|
|
||||||
void _MountPointMoved(BMessage *message);
|
void _MountPointMoved(BMessage *message);
|
||||||
void _PartitionMounted(BMessage *message);
|
void _PartitionMounted(BMessage *message);
|
||||||
void _PartitionUnmounted(BMessage *message);
|
void _PartitionUnmounted(BMessage *message);
|
||||||
|
@ -11,9 +11,12 @@
|
|||||||
#include <DiskDeviceRoster.h>
|
#include <DiskDeviceRoster.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
|
#include <ObjectLocker.h>
|
||||||
#include <Partition.h>
|
#include <Partition.h>
|
||||||
#include <Session.h>
|
#include <Session.h>
|
||||||
|
|
||||||
|
using BPrivate::BObjectLocker;
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
/*! \brief Creates an empty BDiskDeviceList object.
|
/*! \brief Creates an empty BDiskDeviceList object.
|
||||||
*/
|
*/
|
||||||
@ -41,7 +44,7 @@ BDiskDeviceList::~BDiskDeviceList()
|
|||||||
void
|
void
|
||||||
BDiskDeviceList::MessageReceived(BMessage *message)
|
BDiskDeviceList::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
bool locked = Lock();
|
BObjectLocker<BDiskDeviceList> _(this);
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case B_DEVICE_UPDATE:
|
case B_DEVICE_UPDATE:
|
||||||
{
|
{
|
||||||
@ -57,20 +60,26 @@ BDiskDeviceList::MessageReceived(BMessage *message)
|
|||||||
case B_DEVICE_PARTITION_UNMOUNTED:
|
case B_DEVICE_PARTITION_UNMOUNTED:
|
||||||
_PartitionUnmounted(message);
|
_PartitionUnmounted(message);
|
||||||
break;
|
break;
|
||||||
case B_DEVICE_PARTITION_CHANGED:
|
case B_DEVICE_PARTITION_INITIALIZED:
|
||||||
_PartitionChanged(message);
|
_PartitionInitialized(message);
|
||||||
break;
|
break;
|
||||||
case B_DEVICE_PARTITION_ADDED:
|
case B_DEVICE_PARTITION_RESIZED:
|
||||||
_PartitionAdded(message);
|
_PartitionResized(message);
|
||||||
break;
|
break;
|
||||||
case B_DEVICE_PARTITION_REMOVED:
|
case B_DEVICE_PARTITION_MOVED:
|
||||||
_PartitionRemoved(message);
|
_PartitionMoved(message);
|
||||||
break;
|
break;
|
||||||
case B_DEVICE_SESSION_ADDED:
|
case B_DEVICE_PARTITION_CREATED:
|
||||||
_SessionAdded(message);
|
_PartitionCreated(message);
|
||||||
break;
|
break;
|
||||||
case B_DEVICE_SESSION_REMOVED:
|
case B_DEVICE_PARTITION_DELETED:
|
||||||
_SessionRemoved(message);
|
_PartitionDeleted(message);
|
||||||
|
break;
|
||||||
|
case B_DEVICE_PARTITION_DEFRAGMENTED:
|
||||||
|
_PartitionDefragmented(message);
|
||||||
|
break;
|
||||||
|
case B_DEVICE_PARTITION_REPAIRED:
|
||||||
|
_PartitionRepaired(message);
|
||||||
break;
|
break;
|
||||||
case B_DEVICE_MEDIA_CHANGED:
|
case B_DEVICE_MEDIA_CHANGED:
|
||||||
_MediaChanged(message);
|
_MediaChanged(message);
|
||||||
@ -87,8 +96,6 @@ BDiskDeviceList::MessageReceived(BMessage *message)
|
|||||||
default:
|
default:
|
||||||
BHandler::MessageReceived(message);
|
BHandler::MessageReceived(message);
|
||||||
}
|
}
|
||||||
if (locked)
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNextHandler
|
// SetNextHandler
|
||||||
@ -98,13 +105,12 @@ BDiskDeviceList::MessageReceived(BMessage *message)
|
|||||||
void
|
void
|
||||||
BDiskDeviceList::SetNextHandler(BHandler *handler)
|
BDiskDeviceList::SetNextHandler(BHandler *handler)
|
||||||
{
|
{
|
||||||
if (!handler && fSubscribed) {
|
if (!handler) {
|
||||||
bool locked = Lock();
|
BObjectLocker<BDiskDeviceList> _(this);
|
||||||
BDiskDeviceRoster().StopWatching(BMessenger(this));
|
if (fSubscribed)
|
||||||
fSubscribed = false;
|
_StopWatching();
|
||||||
if (locked)
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
BHandler::SetNextHandler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch
|
// Fetch
|
||||||
@ -126,11 +132,14 @@ status_t
|
|||||||
BDiskDeviceList::Fetch()
|
BDiskDeviceList::Fetch()
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
bool locked = Lock();
|
BObjectLocker<BDiskDeviceList> _(this);
|
||||||
// get the devices
|
// register for notifications
|
||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
|
if (Looper())
|
||||||
|
error = _StartWatching();
|
||||||
|
// get the devices
|
||||||
BDiskDeviceRoster roster;
|
BDiskDeviceRoster roster;
|
||||||
do {
|
while (error == B_OK) {
|
||||||
if (BDiskDevice *device = new(nothrow) BDiskDevice) {
|
if (BDiskDevice *device = new(nothrow) BDiskDevice) {
|
||||||
status_t status = roster.GetNextDevice(device);
|
status_t status = roster.GetNextDevice(device);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
@ -141,17 +150,10 @@ BDiskDeviceList::Fetch()
|
|||||||
error = status;
|
error = status;
|
||||||
} else
|
} else
|
||||||
error = B_NO_MEMORY;
|
error = B_NO_MEMORY;
|
||||||
} while (error == B_OK);
|
|
||||||
// register for notifications
|
|
||||||
if (error == B_OK && Looper()) {
|
|
||||||
error = roster.StartWatching(BMessenger(this));
|
|
||||||
fSubscribed = (error == B_OK);
|
|
||||||
}
|
}
|
||||||
// cleanup on error
|
// cleanup on error
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
Unset();
|
Unset();
|
||||||
if (locked)
|
|
||||||
Unlock();
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,16 +168,11 @@ BDiskDeviceList::Fetch()
|
|||||||
void
|
void
|
||||||
BDiskDeviceList::Unset()
|
BDiskDeviceList::Unset()
|
||||||
{
|
{
|
||||||
bool locked = Lock();
|
BObjectLocker<BDiskDeviceList> _(this);
|
||||||
// unsubscribe from notification services
|
// unsubscribe from notification services
|
||||||
if (fSubscribed) {
|
_StopWatching();
|
||||||
BDiskDeviceRoster().StopWatching(BMessenger(this));
|
|
||||||
fSubscribed = false;
|
|
||||||
}
|
|
||||||
// empty the list
|
// empty the list
|
||||||
fDevices.MakeEmpty();
|
fDevices.MakeEmpty();
|
||||||
if (locked)
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock
|
// Lock
|
||||||
@ -264,31 +261,6 @@ BDiskDeviceList::VisitEachDevice(BDiskDeviceVisitor *visitor)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitEachSession
|
|
||||||
/*! \brief Iterates through the all devices' sessions.
|
|
||||||
|
|
||||||
The supplied visitor's Visit(BSession*) is invoked for each session.
|
|
||||||
If Visit() returns \c true, the iteration is terminated and this method
|
|
||||||
returns the respective session.
|
|
||||||
|
|
||||||
The list must be locked.
|
|
||||||
|
|
||||||
\param visitor The visitor.
|
|
||||||
\return The respective session, if the iteration was terminated early,
|
|
||||||
\c NULL otherwise.
|
|
||||||
*/
|
|
||||||
BSession *
|
|
||||||
BDiskDeviceList::VisitEachSession(BDiskDeviceVisitor *visitor)
|
|
||||||
{
|
|
||||||
if (visitor) {
|
|
||||||
for (int32 i = 0; BDiskDevice *device = DeviceAt(i); i++) {
|
|
||||||
if (BSession *session = device->VisitEachSession(visitor))
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// VisitEachPartition
|
// VisitEachPartition
|
||||||
/*! \brief Iterates through the all devices' partitions.
|
/*! \brief Iterates through the all devices' partitions.
|
||||||
|
|
||||||
@ -307,37 +279,13 @@ BDiskDeviceList::VisitEachPartition(BDiskDeviceVisitor *visitor)
|
|||||||
{
|
{
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
for (int32 i = 0; BDiskDevice *device = DeviceAt(i); i++) {
|
for (int32 i = 0; BDiskDevice *device = DeviceAt(i); i++) {
|
||||||
if (BPartition *partition = device->VisitEachPartition(visitor))
|
if (BPartition *partition = device->VisitEachDescendant(visitor))
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse
|
|
||||||
/*! \brief Pre-order traverses the trees of the spanned by the BDiskDevices
|
|
||||||
and their subobjects.
|
|
||||||
|
|
||||||
The supplied visitor's Visit() is invoked for each device, for each
|
|
||||||
session and for each partition.
|
|
||||||
If Visit() returns \c true, the iteration is terminated and this method
|
|
||||||
returns \c true as well.
|
|
||||||
|
|
||||||
\param visitor The visitor.
|
|
||||||
\return \c true, if the iteration was terminated, \c false otherwise.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
BDiskDeviceList::Traverse(BDiskDeviceVisitor *visitor)
|
|
||||||
{
|
|
||||||
if (visitor) {
|
|
||||||
for (int32 i = 0; BDiskDevice *device = DeviceAt(i); i++) {
|
|
||||||
if (device->Traverse(visitor))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// VisitEachMountedPartition
|
// VisitEachMountedPartition
|
||||||
/*! \brief Iterates through the all devices' partitions that are mounted.
|
/*! \brief Iterates through the all devices' partitions that are mounted.
|
||||||
|
|
||||||
@ -358,7 +306,7 @@ BDiskDeviceList::VisitEachMountedPartition(BDiskDeviceVisitor *visitor)
|
|||||||
BPartition *partition = NULL;
|
BPartition *partition = NULL;
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
struct MountedPartitionFilter : public PartitionFilter {
|
struct MountedPartitionFilter : public PartitionFilter {
|
||||||
virtual bool Filter(BPartition *partition)
|
virtual bool Filter(BPartition *partition, int32 level)
|
||||||
{ return partition->IsMounted(); }
|
{ return partition->IsMounted(); }
|
||||||
} filter;
|
} filter;
|
||||||
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
||||||
@ -387,7 +335,7 @@ BDiskDeviceList::VisitEachMountablePartition(BDiskDeviceVisitor *visitor)
|
|||||||
BPartition *partition = NULL;
|
BPartition *partition = NULL;
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
struct MountablePartitionFilter : public PartitionFilter {
|
struct MountablePartitionFilter : public PartitionFilter {
|
||||||
virtual bool Filter(BPartition *partition)
|
virtual bool Filter(BPartition *partition, int32 level)
|
||||||
{ return partition->ContainsFileSystem(); }
|
{ return partition->ContainsFileSystem(); }
|
||||||
} filter;
|
} filter;
|
||||||
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
||||||
@ -396,35 +344,6 @@ BDiskDeviceList::VisitEachMountablePartition(BDiskDeviceVisitor *visitor)
|
|||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitEachInitializablePartition
|
|
||||||
/*! \brief Iterates through the all devices' partitions that are initializable.
|
|
||||||
|
|
||||||
The supplied visitor's Visit(BPartition*) is invoked for each
|
|
||||||
initializable partition.
|
|
||||||
If Visit() returns \c true, the iteration is terminated and this method
|
|
||||||
returns the respective partition.
|
|
||||||
|
|
||||||
The list must be locked.
|
|
||||||
|
|
||||||
\param visitor The visitor.
|
|
||||||
\return The respective partition, if the iteration was terminated early,
|
|
||||||
\c NULL otherwise.
|
|
||||||
*/
|
|
||||||
BPartition *
|
|
||||||
BDiskDeviceList::VisitEachInitializablePartition(BDiskDeviceVisitor *visitor)
|
|
||||||
{
|
|
||||||
BPartition *partition = NULL;
|
|
||||||
if (visitor) {
|
|
||||||
struct InitializablePartitionFilter : public PartitionFilter {
|
|
||||||
virtual bool Filter(BPartition *partition)
|
|
||||||
{ return !partition->IsHidden(); }
|
|
||||||
} filter;
|
|
||||||
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
|
||||||
partition = VisitEachPartition(&filterVisitor);
|
|
||||||
}
|
|
||||||
return partition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeviceWithID
|
// DeviceWithID
|
||||||
/*! \brief Retrieves a device by ID.
|
/*! \brief Retrieves a device by ID.
|
||||||
|
|
||||||
@ -441,22 +360,6 @@ BDiskDeviceList::DeviceWithID(int32 id) const
|
|||||||
return const_cast<BDiskDeviceList*>(this)->VisitEachDevice(&visitor);
|
return const_cast<BDiskDeviceList*>(this)->VisitEachDevice(&visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionWithID
|
|
||||||
/*! \brief Retrieves a session by ID.
|
|
||||||
|
|
||||||
The list must be locked.
|
|
||||||
|
|
||||||
\param id The ID of the session to be returned.
|
|
||||||
\return The session with ID \a id, or \c NULL, if the list is not
|
|
||||||
locked or no session with ID \a id is in the list.
|
|
||||||
*/
|
|
||||||
BSession *
|
|
||||||
BDiskDeviceList::SessionWithID(int32 id) const
|
|
||||||
{
|
|
||||||
IDFinderVisitor visitor(id);
|
|
||||||
return const_cast<BDiskDeviceList*>(this)->VisitEachSession(&visitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartitionWithID
|
// PartitionWithID
|
||||||
/*! \brief Retrieves a partition by ID.
|
/*! \brief Retrieves a partition by ID.
|
||||||
|
|
||||||
@ -483,6 +386,7 @@ BDiskDeviceList::PartitionWithID(int32 id) const
|
|||||||
void
|
void
|
||||||
BDiskDeviceList::MountPointMoved(BPartition *partition)
|
BDiskDeviceList::MountPointMoved(BPartition *partition)
|
||||||
{
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_MOUNT_POINT_MOVED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartitionMounted
|
// PartitionMounted
|
||||||
@ -495,6 +399,7 @@ BDiskDeviceList::MountPointMoved(BPartition *partition)
|
|||||||
void
|
void
|
||||||
BDiskDeviceList::PartitionMounted(BPartition *partition)
|
BDiskDeviceList::PartitionMounted(BPartition *partition)
|
||||||
{
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_MOUNTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartitionUnmounted
|
// PartitionUnmounted
|
||||||
@ -507,71 +412,121 @@ BDiskDeviceList::PartitionMounted(BPartition *partition)
|
|||||||
void
|
void
|
||||||
BDiskDeviceList::PartitionUnmounted(BPartition *partition)
|
BDiskDeviceList::PartitionUnmounted(BPartition *partition)
|
||||||
{
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_UNMOUNTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionInitialized
|
||||||
|
/*! \brief Invoked, when a partition has been initialized.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionInitialized(BPartition *partition)
|
||||||
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_INITIALIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionResized
|
||||||
|
/*! \brief Invoked, when a partition has been resized.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionResized(BPartition *partition)
|
||||||
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_RESIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionMoved
|
||||||
|
/*! \brief Invoked, when a partition has been moved.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionMoved(BPartition *partition)
|
||||||
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_MOVED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionCreated
|
||||||
|
/*! \brief Invoked, when a partition has been created.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionCreated(BPartition *partition)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionDeleted
|
||||||
|
/*! \brief Invoked, when a partition has been deleted.
|
||||||
|
|
||||||
|
The method is called twice for a deleted partition. The first time
|
||||||
|
before the BDiskDevice the partition belongs to has been updated. The
|
||||||
|
\a partition parameter will point to a still valid BPartition object.
|
||||||
|
On the second invocation the device object will have been updated and
|
||||||
|
the partition object will have been deleted -- \a partition will be
|
||||||
|
\c NULL then.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition. Only non- \c NULL on the first
|
||||||
|
invocation.
|
||||||
|
\param partitionID The ID of the concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionDeleted(BPartition *partition,
|
||||||
|
partition_id partitionID)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionDefragmented
|
||||||
|
/*! \brief Invoked, when a partition has been defragmented.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionDefragmented(BPartition *partition)
|
||||||
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_DEFRAGMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionRepaired
|
||||||
|
/*! \brief Invoked, when a partition has been repaired.
|
||||||
|
|
||||||
|
The list is locked, when this method is invoked.
|
||||||
|
|
||||||
|
\param partition The concerned partition.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::PartitionRepaired(BPartition *partition)
|
||||||
|
{
|
||||||
|
PartitionChanged(partition, B_DEVICE_PARTITION_REPAIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartitionChanged
|
// PartitionChanged
|
||||||
/*! \brief Invoked, when data concerning a partition have changed.
|
/*! \brief Catch-all method invoked by the \c Partition*() hooks, save by
|
||||||
|
PartitionCreated() and PartitionDeleted().
|
||||||
|
|
||||||
The list is locked, when this method is invoked.
|
If you're interested only in the fact, that something about the partition
|
||||||
|
changed, you can just override this hook instead of the ones telling you
|
||||||
|
exactly what happened.
|
||||||
|
|
||||||
\param partition The concerned partition.
|
\param partition The concerned partition.
|
||||||
|
\param event The event that occurred, if you are interested in it after all.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDiskDeviceList::PartitionChanged(BPartition *partition)
|
BDiskDeviceList::PartitionChanged(BPartition *partition, uint32 event)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartitionAdded
|
|
||||||
/*! \brief Invoked, when a partition has been added.
|
|
||||||
|
|
||||||
The list is locked, when this method is invoked.
|
|
||||||
|
|
||||||
\param partition The concerned partition.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
BDiskDeviceList::PartitionAdded(BPartition *partition)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartitionRemoved
|
|
||||||
/*! \brief Invoked, when a partition has been removed.
|
|
||||||
|
|
||||||
The supplied object is already removed from the list and is going to be
|
|
||||||
deleted after the hook returns.
|
|
||||||
|
|
||||||
The list is locked, when this method is invoked.
|
|
||||||
|
|
||||||
\param partition The concerned partition.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
BDiskDeviceList::PartitionRemoved(BPartition *partition)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// SessionAdded
|
|
||||||
/*! \brief Invoked, when a session has been added.
|
|
||||||
|
|
||||||
The list is locked, when this method is invoked.
|
|
||||||
|
|
||||||
\param session The concerned session.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
BDiskDeviceList::SessionAdded(BSession *session)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// SessionRemoved
|
|
||||||
/*! \brief Invoked, when a session has been removed.
|
|
||||||
|
|
||||||
The supplied object is already removed from the list and is going to be
|
|
||||||
deleted after the hook returns.
|
|
||||||
|
|
||||||
The list is locked, when this method is invoked.
|
|
||||||
|
|
||||||
\param session The concerned session.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
BDiskDeviceList::SessionRemoved(BSession *session)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,6 +569,40 @@ BDiskDeviceList::DeviceRemoved(BDiskDevice *device)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _StartWatching
|
||||||
|
/*! \brief Starts watching for disk device notifications.
|
||||||
|
|
||||||
|
The object must be locked (if possible at all), when this method is
|
||||||
|
invoked.
|
||||||
|
|
||||||
|
\return \c B_OK, if everything went fine, another error code otherwise.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
BDiskDeviceList::_StartWatching()
|
||||||
|
{
|
||||||
|
if (!Looper() || fSubscribed)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
status_t error = BDiskDeviceRoster().StartWatching(BMessenger(this));
|
||||||
|
fSubscribed = (error == B_OK);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _StopWatching
|
||||||
|
/*! \brief Stop watching for disk device notifications.
|
||||||
|
|
||||||
|
The object must be locked (if possible at all), when this method is
|
||||||
|
invoked.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::_StopWatching()
|
||||||
|
{
|
||||||
|
if (fSubscribed) {
|
||||||
|
BDiskDeviceRoster().StopWatching(BMessenger(this));
|
||||||
|
fSubscribed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// _MountPointMoved
|
// _MountPointMoved
|
||||||
/*! \brief Handles a "mount point moved" message.
|
/*! \brief Handles a "mount point moved" message.
|
||||||
\param message The respective notification message.
|
\param message The respective notification message.
|
||||||
@ -653,72 +642,96 @@ BDiskDeviceList::_PartitionUnmounted(BMessage *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _PartitionChanged
|
// _PartitionInitialized
|
||||||
/*! \brief Handles a "partition changed" message.
|
/*! \brief Handles a "partition initialized" message.
|
||||||
\param message The respective notification message.
|
\param message The respective notification message.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDiskDeviceList::_PartitionChanged(BMessage *message)
|
BDiskDeviceList::_PartitionInitialized(BMessage *message)
|
||||||
{
|
{
|
||||||
if (BDiskDevice *device = _UpdateDevice(message)) {
|
if (BDiskDevice *device = _UpdateDevice(message)) {
|
||||||
if (BPartition *partition = _FindPartition(message))
|
if (BPartition *partition = _FindPartition(message))
|
||||||
PartitionChanged(partition);
|
PartitionInitialized(partition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _PartitionAdded
|
// _PartitionResized
|
||||||
/*! \brief Handles a "partition added" message.
|
/*! \brief Handles a "partition resized" message.
|
||||||
\param message The respective notification message.
|
\param message The respective notification message.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDiskDeviceList::_PartitionAdded(BMessage *message)
|
BDiskDeviceList::_PartitionResized(BMessage *message)
|
||||||
{
|
{
|
||||||
if (BDiskDevice *device = _UpdateDevice(message)) {
|
if (BDiskDevice *device = _UpdateDevice(message)) {
|
||||||
if (BPartition *partition = _FindPartition(message))
|
if (BPartition *partition = _FindPartition(message))
|
||||||
PartitionAdded(partition);
|
PartitionResized(partition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _PartitionRemoved
|
// _PartitionMoved
|
||||||
/*! \brief Handles a "partition removed" message.
|
/*! \brief Handles a "partition moved" message.
|
||||||
\param message The respective notification message.
|
\param message The respective notification message.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDiskDeviceList::_PartitionRemoved(BMessage *message)
|
BDiskDeviceList::_PartitionMoved(BMessage *message)
|
||||||
|
{
|
||||||
|
if (BDiskDevice *device = _UpdateDevice(message)) {
|
||||||
|
if (BPartition *partition = _FindPartition(message))
|
||||||
|
PartitionMoved(partition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// _PartitionCreated
|
||||||
|
/*! \brief Handles a "partition created" message.
|
||||||
|
\param message The respective notification message.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::_PartitionCreated(BMessage *message)
|
||||||
|
{
|
||||||
|
if (BDiskDevice *device = _UpdateDevice(message)) {
|
||||||
|
if (BPartition *partition = _FindPartition(message))
|
||||||
|
PartitionCreated(partition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// _PartitionDeleted
|
||||||
|
/*! \brief Handles a "partition deleted" message.
|
||||||
|
\param message The respective notification message.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BDiskDeviceList::_PartitionDeleted(BMessage *message)
|
||||||
{
|
{
|
||||||
if (BPartition *partition = _FindPartition(message)) {
|
if (BPartition *partition = _FindPartition(message)) {
|
||||||
partition->Session()->fPartitions.RemoveItem(partition, false);
|
partition_id id = partition->ID();
|
||||||
if (_UpdateDevice(message) && !_FindPartition(message))
|
PartitionDeleted(partition, id);
|
||||||
PartitionRemoved(partition);
|
if (_UpdateDevice(message))
|
||||||
delete partition;
|
PartitionDeleted(NULL, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SessionAdded
|
// _PartitionDefragmented
|
||||||
/*! \brief Handles a "session added" message.
|
/*! \brief Handles a "partition defragmented" message.
|
||||||
\param message The respective notification message.
|
\param message The respective notification message.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDiskDeviceList::_SessionAdded(BMessage *message)
|
BDiskDeviceList::_PartitionDefragmented(BMessage *message)
|
||||||
{
|
{
|
||||||
if (BDiskDevice *device = _UpdateDevice(message)) {
|
if (BDiskDevice *device = _UpdateDevice(message)) {
|
||||||
if (BSession *session = _FindSession(message))
|
if (BPartition *partition = _FindPartition(message))
|
||||||
SessionAdded(session);
|
PartitionDefragmented(partition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SessionRemoved
|
// _PartitionRepaired
|
||||||
/*! \brief Handles a "session removed" message.
|
/*! \brief Handles a "partition repaired" message.
|
||||||
\param message The respective notification message.
|
\param message The respective notification message.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDiskDeviceList::_SessionRemoved(BMessage *message)
|
BDiskDeviceList::_PartitionRepaired(BMessage *message)
|
||||||
{
|
{
|
||||||
if (BSession *session = _FindSession(message)) {
|
if (BDiskDevice *device = _UpdateDevice(message)) {
|
||||||
session->Device()->fSessions.RemoveItem(session, false);
|
if (BPartition *partition = _FindPartition(message))
|
||||||
if (_UpdateDevice(message) && !_FindSession(message))
|
PartitionRepaired(partition);
|
||||||
SessionRemoved(session);
|
|
||||||
delete session;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,22 +794,6 @@ BDiskDeviceList::_FindDevice(BMessage *message)
|
|||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _FindSession
|
|
||||||
/*! \brief Returns the session for the ID contained in a motification message.
|
|
||||||
\param message The notification message.
|
|
||||||
\return The session with the ID, or \c NULL, if the ID or the session could
|
|
||||||
not be found.
|
|
||||||
*/
|
|
||||||
BSession *
|
|
||||||
BDiskDeviceList::_FindSession(BMessage *message)
|
|
||||||
{
|
|
||||||
BSession *session = NULL;
|
|
||||||
int32 id;
|
|
||||||
if (message->FindInt32("session_id", &id) == B_OK)
|
|
||||||
session = SessionWithID(id);
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _FindPartition
|
// _FindPartition
|
||||||
/*! \brief Returns the partition for the ID contained in a motification
|
/*! \brief Returns the partition for the ID contained in a motification
|
||||||
message.
|
message.
|
||||||
|
@ -56,6 +56,7 @@ STORAGE_KIT_SOURCE_HAIKU_ONLY =
|
|||||||
# storage: DiskDevice API
|
# storage: DiskDevice API
|
||||||
DiskDevice.cpp
|
DiskDevice.cpp
|
||||||
DiskDeviceJob.cpp
|
DiskDeviceJob.cpp
|
||||||
|
DiskDeviceList.cpp
|
||||||
DiskDevicePrivate.cpp
|
DiskDevicePrivate.cpp
|
||||||
DiskDeviceRoster.cpp
|
DiskDeviceRoster.cpp
|
||||||
DiskDeviceTypes.cpp
|
DiskDeviceTypes.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user