1*23b03456SIngo Weinhold /*
2*23b03456SIngo Weinhold * Copyright 2003-2006, Haiku Inc.
3*23b03456SIngo Weinhold * Distributed under the terms of the MIT License.
4*23b03456SIngo Weinhold *
5*23b03456SIngo Weinhold * Authors:
6*23b03456SIngo Weinhold * Ingo Weinhold, bonefish@users.sf.net
7*23b03456SIngo Weinhold */
8*23b03456SIngo Weinhold
9*23b03456SIngo Weinhold #include <DiskDeviceList.h>
10*23b03456SIngo Weinhold
11*23b03456SIngo Weinhold #include <AutoLocker.h>
12*23b03456SIngo Weinhold #include <DiskDevice.h>
13*23b03456SIngo Weinhold #include <DiskDevicePrivate.h>
14*23b03456SIngo Weinhold #include <DiskDeviceRoster.h>
15*23b03456SIngo Weinhold #include <Locker.h>
16*23b03456SIngo Weinhold #include <Looper.h>
17*23b03456SIngo Weinhold #include <Partition.h>
18*23b03456SIngo Weinhold
19*23b03456SIngo Weinhold #include <new>
20*23b03456SIngo Weinhold using namespace std;
21*23b03456SIngo Weinhold
22*23b03456SIngo Weinhold // constructor
23*23b03456SIngo Weinhold /*! \brief Creates an empty BDiskDeviceList object.
24*23b03456SIngo Weinhold */
BDiskDeviceList(bool useOwnLocker)25*23b03456SIngo Weinhold BDiskDeviceList::BDiskDeviceList(bool useOwnLocker)
26*23b03456SIngo Weinhold : fLocker(NULL),
27*23b03456SIngo Weinhold fDevices(20, true),
28*23b03456SIngo Weinhold fSubscribed(false)
29*23b03456SIngo Weinhold {
30*23b03456SIngo Weinhold if (useOwnLocker)
31*23b03456SIngo Weinhold fLocker = new(nothrow) BLocker("BDiskDeviceList_fLocker");
32*23b03456SIngo Weinhold }
33*23b03456SIngo Weinhold
34*23b03456SIngo Weinhold // destructor
35*23b03456SIngo Weinhold /*! \brief Frees all resources associated with the object.
36*23b03456SIngo Weinhold */
~BDiskDeviceList()37*23b03456SIngo Weinhold BDiskDeviceList::~BDiskDeviceList()
38*23b03456SIngo Weinhold {
39*23b03456SIngo Weinhold delete fLocker;
40*23b03456SIngo Weinhold }
41*23b03456SIngo Weinhold
42*23b03456SIngo Weinhold // MessageReceived
43*23b03456SIngo Weinhold /*! \brief Implemented to handle notification messages.
44*23b03456SIngo Weinhold */
45*23b03456SIngo Weinhold void
MessageReceived(BMessage * message)46*23b03456SIngo Weinhold BDiskDeviceList::MessageReceived(BMessage *message)
47*23b03456SIngo Weinhold {
48*23b03456SIngo Weinhold AutoLocker<BDiskDeviceList> _(this);
49*23b03456SIngo Weinhold switch (message->what) {
50*23b03456SIngo Weinhold case B_DEVICE_UPDATE:
51*23b03456SIngo Weinhold {
52*23b03456SIngo Weinhold uint32 event;
53*23b03456SIngo Weinhold if (message->FindInt32("event", (int32*)&event) == B_OK) {
54*23b03456SIngo Weinhold switch (event) {
55*23b03456SIngo Weinhold case B_DEVICE_MOUNT_POINT_MOVED:
56*23b03456SIngo Weinhold _MountPointMoved(message);
57*23b03456SIngo Weinhold break;
58*23b03456SIngo Weinhold case B_DEVICE_PARTITION_MOUNTED:
59*23b03456SIngo Weinhold _PartitionMounted(message);
60*23b03456SIngo Weinhold break;
61*23b03456SIngo Weinhold case B_DEVICE_PARTITION_UNMOUNTED:
62*23b03456SIngo Weinhold _PartitionUnmounted(message);
63*23b03456SIngo Weinhold break;
64*23b03456SIngo Weinhold case B_DEVICE_PARTITION_INITIALIZED:
65*23b03456SIngo Weinhold _PartitionInitialized(message);
66*23b03456SIngo Weinhold break;
67*23b03456SIngo Weinhold case B_DEVICE_PARTITION_RESIZED:
68*23b03456SIngo Weinhold _PartitionResized(message);
69*23b03456SIngo Weinhold break;
70*23b03456SIngo Weinhold case B_DEVICE_PARTITION_MOVED:
71*23b03456SIngo Weinhold _PartitionMoved(message);
72*23b03456SIngo Weinhold break;
73*23b03456SIngo Weinhold case B_DEVICE_PARTITION_CREATED:
74*23b03456SIngo Weinhold _PartitionCreated(message);
75*23b03456SIngo Weinhold break;
76*23b03456SIngo Weinhold case B_DEVICE_PARTITION_DELETED:
77*23b03456SIngo Weinhold _PartitionDeleted(message);
78*23b03456SIngo Weinhold break;
79*23b03456SIngo Weinhold case B_DEVICE_PARTITION_DEFRAGMENTED:
80*23b03456SIngo Weinhold _PartitionDefragmented(message);
81*23b03456SIngo Weinhold break;
82*23b03456SIngo Weinhold case B_DEVICE_PARTITION_REPAIRED:
83*23b03456SIngo Weinhold _PartitionRepaired(message);
84*23b03456SIngo Weinhold break;
85*23b03456SIngo Weinhold case B_DEVICE_MEDIA_CHANGED:
86*23b03456SIngo Weinhold _MediaChanged(message);
87*23b03456SIngo Weinhold break;
88*23b03456SIngo Weinhold case B_DEVICE_ADDED:
89*23b03456SIngo Weinhold _DeviceAdded(message);
90*23b03456SIngo Weinhold break;
91*23b03456SIngo Weinhold case B_DEVICE_REMOVED:
92*23b03456SIngo Weinhold _DeviceRemoved(message);
93*23b03456SIngo Weinhold break;
94*23b03456SIngo Weinhold }
95*23b03456SIngo Weinhold }
96*23b03456SIngo Weinhold }
97*23b03456SIngo Weinhold default:
98*23b03456SIngo Weinhold BHandler::MessageReceived(message);
99*23b03456SIngo Weinhold }
100*23b03456SIngo Weinhold }
101*23b03456SIngo Weinhold
102*23b03456SIngo Weinhold // SetNextHandler
103*23b03456SIngo Weinhold /*! \brief Implemented to unsubscribe from notification services when going
104*23b03456SIngo Weinhold to be detached from looper.
105*23b03456SIngo Weinhold */
106*23b03456SIngo Weinhold void
SetNextHandler(BHandler * handler)107*23b03456SIngo Weinhold BDiskDeviceList::SetNextHandler(BHandler *handler)
108*23b03456SIngo Weinhold {
109*23b03456SIngo Weinhold if (!handler) {
110*23b03456SIngo Weinhold AutoLocker<BDiskDeviceList> _(this);
111*23b03456SIngo Weinhold if (fSubscribed)
112*23b03456SIngo Weinhold _StopWatching();
113*23b03456SIngo Weinhold }
114*23b03456SIngo Weinhold BHandler::SetNextHandler(handler);
115*23b03456SIngo Weinhold }
116*23b03456SIngo Weinhold
117*23b03456SIngo Weinhold // Fetch
118*23b03456SIngo Weinhold /*! \brief Empties the list and refills it according to the current state.
119*23b03456SIngo Weinhold
120*23b03456SIngo Weinhold Furthermore, if added to a looper, the list subscribes to notification
121*23b03456SIngo Weinhold services needed to keep the list up-to-date.
122*23b03456SIngo Weinhold
123*23b03456SIngo Weinhold If an error occurs, the list Unset()s itself.
124*23b03456SIngo Weinhold
125*23b03456SIngo Weinhold The object doesn't need to be locked, when this method is invoked. The
126*23b03456SIngo Weinhold method does itself try to lock the list, but doesn't fail, if that
127*23b03456SIngo Weinhold doesn't succeed. That way an object can be used without locking in a
128*23b03456SIngo Weinhold single threaded environment.
129*23b03456SIngo Weinhold
130*23b03456SIngo Weinhold \return \c B_OK, if everything went fine, another error code otherwise.
131*23b03456SIngo Weinhold */
132*23b03456SIngo Weinhold status_t
Fetch()133*23b03456SIngo Weinhold BDiskDeviceList::Fetch()
134*23b03456SIngo Weinhold {
135*23b03456SIngo Weinhold Unset();
136*23b03456SIngo Weinhold AutoLocker<BDiskDeviceList> _(this);
137*23b03456SIngo Weinhold // register for notifications
138*23b03456SIngo Weinhold status_t error = B_OK;
139*23b03456SIngo Weinhold if (Looper())
140*23b03456SIngo Weinhold error = _StartWatching();
141*23b03456SIngo Weinhold // get the devices
142*23b03456SIngo Weinhold BDiskDeviceRoster roster;
143*23b03456SIngo Weinhold while (error == B_OK) {
144*23b03456SIngo Weinhold if (BDiskDevice *device = new(nothrow) BDiskDevice) {
145*23b03456SIngo Weinhold status_t status = roster.GetNextDevice(device);
146*23b03456SIngo Weinhold if (status == B_OK)
147*23b03456SIngo Weinhold fDevices.AddItem(device);
148*23b03456SIngo Weinhold else if (status == B_ENTRY_NOT_FOUND)
149*23b03456SIngo Weinhold break;
150*23b03456SIngo Weinhold else
151*23b03456SIngo Weinhold error = status;
152*23b03456SIngo Weinhold } else
153*23b03456SIngo Weinhold error = B_NO_MEMORY;
154*23b03456SIngo Weinhold }
155*23b03456SIngo Weinhold // cleanup on error
156*23b03456SIngo Weinhold if (error != B_OK)
157*23b03456SIngo Weinhold Unset();
158*23b03456SIngo Weinhold return error;
159*23b03456SIngo Weinhold }
160*23b03456SIngo Weinhold
161*23b03456SIngo Weinhold // Unset
162*23b03456SIngo Weinhold /*! \brief Empties the list and unsubscribes from all notification services.
163*23b03456SIngo Weinhold
164*23b03456SIngo Weinhold The object doesn't need to be locked, when this method is invoked. The
165*23b03456SIngo Weinhold method does itself try to lock the list, but doesn't fail, if that
166*23b03456SIngo Weinhold doesn't succeed. That way an object can be used without locking in a
167*23b03456SIngo Weinhold single threaded environment.
168*23b03456SIngo Weinhold */
169*23b03456SIngo Weinhold void
Unset()170*23b03456SIngo Weinhold BDiskDeviceList::Unset()
171*23b03456SIngo Weinhold {
172*23b03456SIngo Weinhold AutoLocker<BDiskDeviceList> _(this);
173*23b03456SIngo Weinhold // unsubscribe from notification services
174*23b03456SIngo Weinhold _StopWatching();
175*23b03456SIngo Weinhold // empty the list
176*23b03456SIngo Weinhold fDevices.MakeEmpty();
177*23b03456SIngo Weinhold }
178*23b03456SIngo Weinhold
179*23b03456SIngo Weinhold // Lock
180*23b03456SIngo Weinhold /*! \brief Locks the list.
181*23b03456SIngo Weinhold
182*23b03456SIngo Weinhold If on construction it had been specified, that the list shall use an
183*23b03456SIngo Weinhold own BLocker, then this locker is locked, otherwise LockLooper() is
184*23b03456SIngo Weinhold invoked.
185*23b03456SIngo Weinhold
186*23b03456SIngo Weinhold \return \c true, if the list could be locked successfully, \c false
187*23b03456SIngo Weinhold otherwise.
188*23b03456SIngo Weinhold */
189*23b03456SIngo Weinhold bool
Lock()190*23b03456SIngo Weinhold BDiskDeviceList::Lock()
191*23b03456SIngo Weinhold {
192*23b03456SIngo Weinhold if (fLocker)
193*23b03456SIngo Weinhold return fLocker->Lock();
194*23b03456SIngo Weinhold return LockLooper();
195*23b03456SIngo Weinhold }
196*23b03456SIngo Weinhold
197*23b03456SIngo Weinhold // Unlock
198*23b03456SIngo Weinhold /*! \brief Unlocks the list.
199*23b03456SIngo Weinhold
200*23b03456SIngo Weinhold If on construction it had been specified, that the list shall use an
201*23b03456SIngo Weinhold own BLocker, then this locker is unlocked, otherwise UnlockLooper() is
202*23b03456SIngo Weinhold invoked.
203*23b03456SIngo Weinhold */
204*23b03456SIngo Weinhold void
Unlock()205*23b03456SIngo Weinhold BDiskDeviceList::Unlock()
206*23b03456SIngo Weinhold {
207*23b03456SIngo Weinhold if (fLocker)
208*23b03456SIngo Weinhold return fLocker->Unlock();
209*23b03456SIngo Weinhold return UnlockLooper();
210*23b03456SIngo Weinhold }
211*23b03456SIngo Weinhold
212*23b03456SIngo Weinhold // CountDevices
213*23b03456SIngo Weinhold /*! \brief Returns the number of devices in the list.
214*23b03456SIngo Weinhold
215*23b03456SIngo Weinhold The list must be locked.
216*23b03456SIngo Weinhold
217*23b03456SIngo Weinhold \return The number of devices in the list.
218*23b03456SIngo Weinhold */
219*23b03456SIngo Weinhold int32
CountDevices() const220*23b03456SIngo Weinhold BDiskDeviceList::CountDevices() const
221*23b03456SIngo Weinhold {
222*23b03456SIngo Weinhold return fDevices.CountItems();
223*23b03456SIngo Weinhold }
224*23b03456SIngo Weinhold
225*23b03456SIngo Weinhold // DeviceAt
226*23b03456SIngo Weinhold /*! \brief Retrieves a device by index.
227*23b03456SIngo Weinhold
228*23b03456SIngo Weinhold The list must be locked.
229*23b03456SIngo Weinhold
230*23b03456SIngo Weinhold \param index The list index of the device to be returned.
231*23b03456SIngo Weinhold \return The device with index \a index, or \c NULL, if the list is not
232*23b03456SIngo Weinhold locked or \a index is out of range.
233*23b03456SIngo Weinhold */
234*23b03456SIngo Weinhold BDiskDevice *
DeviceAt(int32 index) const235*23b03456SIngo Weinhold BDiskDeviceList::DeviceAt(int32 index) const
236*23b03456SIngo Weinhold {
237*23b03456SIngo Weinhold return fDevices.ItemAt(index);
238*23b03456SIngo Weinhold }
239*23b03456SIngo Weinhold
240*23b03456SIngo Weinhold // VisitEachDevice
241*23b03456SIngo Weinhold /*! \brief Iterates through the all devices in the list.
242*23b03456SIngo Weinhold
243*23b03456SIngo Weinhold The supplied visitor's Visit(BDiskDevice*) is invoked for each device.
244*23b03456SIngo Weinhold If Visit() returns \c true, the iteration is terminated and this method
245*23b03456SIngo Weinhold returns the respective device.
246*23b03456SIngo Weinhold
247*23b03456SIngo Weinhold The list must be locked.
248*23b03456SIngo Weinhold
249*23b03456SIngo Weinhold \param visitor The visitor.
250*23b03456SIngo Weinhold \return The respective device, if the iteration was terminated early,
251*23b03456SIngo Weinhold \c NULL otherwise.
252*23b03456SIngo Weinhold */
253*23b03456SIngo Weinhold BDiskDevice *
VisitEachDevice(BDiskDeviceVisitor * visitor)254*23b03456SIngo Weinhold BDiskDeviceList::VisitEachDevice(BDiskDeviceVisitor *visitor)
255*23b03456SIngo Weinhold {
256*23b03456SIngo Weinhold if (visitor) {
257*23b03456SIngo Weinhold for (int32 i = 0; BDiskDevice *device = DeviceAt(i); i++) {
258*23b03456SIngo Weinhold if (visitor->Visit(device))
259*23b03456SIngo Weinhold return device;
260*23b03456SIngo Weinhold }
261*23b03456SIngo Weinhold }
262*23b03456SIngo Weinhold return NULL;
263*23b03456SIngo Weinhold }
264*23b03456SIngo Weinhold
265*23b03456SIngo Weinhold // VisitEachPartition
266*23b03456SIngo Weinhold /*! \brief Iterates through the all devices' partitions.
267*23b03456SIngo Weinhold
268*23b03456SIngo Weinhold The supplied visitor's Visit(BPartition*) is invoked for each partition.
269*23b03456SIngo Weinhold If Visit() returns \c true, the iteration is terminated and this method
270*23b03456SIngo Weinhold returns the respective partition.
271*23b03456SIngo Weinhold
272*23b03456SIngo Weinhold The list must be locked.
273*23b03456SIngo Weinhold
274*23b03456SIngo Weinhold \param visitor The visitor.
275*23b03456SIngo Weinhold \return The respective partition, if the iteration was terminated early,
276*23b03456SIngo Weinhold \c NULL otherwise.
277*23b03456SIngo Weinhold */
278*23b03456SIngo Weinhold BPartition *
VisitEachPartition(BDiskDeviceVisitor * visitor)279*23b03456SIngo Weinhold BDiskDeviceList::VisitEachPartition(BDiskDeviceVisitor *visitor)
280*23b03456SIngo Weinhold {
281*23b03456SIngo Weinhold if (visitor) {
282*23b03456SIngo Weinhold for (int32 i = 0; BDiskDevice *device = DeviceAt(i); i++) {
283*23b03456SIngo Weinhold if (BPartition *partition = device->VisitEachDescendant(visitor))
284*23b03456SIngo Weinhold return partition;
285*23b03456SIngo Weinhold }
286*23b03456SIngo Weinhold }
287*23b03456SIngo Weinhold return NULL;
288*23b03456SIngo Weinhold }
289*23b03456SIngo Weinhold
290*23b03456SIngo Weinhold // VisitEachMountedPartition
291*23b03456SIngo Weinhold /*! \brief Iterates through the all devices' partitions that are mounted.
292*23b03456SIngo Weinhold
293*23b03456SIngo Weinhold The supplied visitor's Visit(BPartition*) is invoked for each mounted
294*23b03456SIngo Weinhold partition.
295*23b03456SIngo Weinhold If Visit() returns \c true, the iteration is terminated and this method
296*23b03456SIngo Weinhold returns the respective partition.
297*23b03456SIngo Weinhold
298*23b03456SIngo Weinhold The list must be locked.
299*23b03456SIngo Weinhold
300*23b03456SIngo Weinhold \param visitor The visitor.
301*23b03456SIngo Weinhold \return The respective partition, if the iteration was terminated early,
302*23b03456SIngo Weinhold \c NULL otherwise.
303*23b03456SIngo Weinhold */
304*23b03456SIngo Weinhold BPartition *
VisitEachMountedPartition(BDiskDeviceVisitor * visitor)305*23b03456SIngo Weinhold BDiskDeviceList::VisitEachMountedPartition(BDiskDeviceVisitor *visitor)
306*23b03456SIngo Weinhold {
307*23b03456SIngo Weinhold BPartition *partition = NULL;
308*23b03456SIngo Weinhold if (visitor) {
309*23b03456SIngo Weinhold struct MountedPartitionFilter : public PartitionFilter {
310*23b03456SIngo Weinhold virtual ~MountedPartitionFilter() {};
311*23b03456SIngo Weinhold virtual bool Filter(BPartition *partition, int32 level)
312*23b03456SIngo Weinhold { return partition->IsMounted(); }
313*23b03456SIngo Weinhold } filter;
314*23b03456SIngo Weinhold PartitionFilterVisitor filterVisitor(visitor, &filter);
315*23b03456SIngo Weinhold partition = VisitEachPartition(&filterVisitor);
316*23b03456SIngo Weinhold }
317*23b03456SIngo Weinhold return partition;
318*23b03456SIngo Weinhold }
319*23b03456SIngo Weinhold
320*23b03456SIngo Weinhold // VisitEachMountablePartition
321*23b03456SIngo Weinhold /*! \brief Iterates through the all devices' partitions that are mountable.
322*23b03456SIngo Weinhold
323*23b03456SIngo Weinhold The supplied visitor's Visit(BPartition*) is invoked for each mountable
324*23b03456SIngo Weinhold partition.
325*23b03456SIngo Weinhold If Visit() returns \c true, the iteration is terminated and this method
326*23b03456SIngo Weinhold returns the respective partition.
327*23b03456SIngo Weinhold
328*23b03456SIngo Weinhold The list must be locked.
329*23b03456SIngo Weinhold
330*23b03456SIngo Weinhold \param visitor The visitor.
331*23b03456SIngo Weinhold \return The respective partition, if the iteration was terminated early,
332*23b03456SIngo Weinhold \c NULL otherwise.
333*23b03456SIngo Weinhold */
334*23b03456SIngo Weinhold BPartition *
VisitEachMountablePartition(BDiskDeviceVisitor * visitor)335*23b03456SIngo Weinhold BDiskDeviceList::VisitEachMountablePartition(BDiskDeviceVisitor *visitor)
336*23b03456SIngo Weinhold {
337*23b03456SIngo Weinhold BPartition *partition = NULL;
338*23b03456SIngo Weinhold if (visitor) {
339*23b03456SIngo Weinhold struct MountablePartitionFilter : public PartitionFilter {
340*23b03456SIngo Weinhold virtual ~MountablePartitionFilter() {};
341*23b03456SIngo Weinhold virtual bool Filter(BPartition *partition, int32 level)
342*23b03456SIngo Weinhold { return partition->ContainsFileSystem(); }
343*23b03456SIngo Weinhold } filter;
344*23b03456SIngo Weinhold PartitionFilterVisitor filterVisitor(visitor, &filter);
345*23b03456SIngo Weinhold partition = VisitEachPartition(&filterVisitor);
346*23b03456SIngo Weinhold }
347*23b03456SIngo Weinhold return partition;
348*23b03456SIngo Weinhold }
349*23b03456SIngo Weinhold
350*23b03456SIngo Weinhold // DeviceWithID
351*23b03456SIngo Weinhold /*! \brief Retrieves a device by ID.
352*23b03456SIngo Weinhold
353*23b03456SIngo Weinhold The list must be locked.
354*23b03456SIngo Weinhold
355*23b03456SIngo Weinhold \param id The ID of the device to be returned.
356*23b03456SIngo Weinhold \return The device with ID \a id, or \c NULL, if the list is not
357*23b03456SIngo Weinhold locked or no device with ID \a id is in the list.
358*23b03456SIngo Weinhold */
359*23b03456SIngo Weinhold BDiskDevice *
DeviceWithID(int32 id) const360*23b03456SIngo Weinhold BDiskDeviceList::DeviceWithID(int32 id) const
361*23b03456SIngo Weinhold {
362*23b03456SIngo Weinhold IDFinderVisitor visitor(id);
363*23b03456SIngo Weinhold return const_cast<BDiskDeviceList*>(this)->VisitEachDevice(&visitor);
364*23b03456SIngo Weinhold }
365*23b03456SIngo Weinhold
366*23b03456SIngo Weinhold // PartitionWithID
367*23b03456SIngo Weinhold /*! \brief Retrieves a partition by ID.
368*23b03456SIngo Weinhold
369*23b03456SIngo Weinhold The list must be locked.
370*23b03456SIngo Weinhold
371*23b03456SIngo Weinhold \param id The ID of the partition to be returned.
372*23b03456SIngo Weinhold \return The partition with ID \a id, or \c NULL, if the list is not
373*23b03456SIngo Weinhold locked or no partition with ID \a id is in the list.
374*23b03456SIngo Weinhold */
375*23b03456SIngo Weinhold BPartition *
PartitionWithID(int32 id) const376*23b03456SIngo Weinhold BDiskDeviceList::PartitionWithID(int32 id) const
377*23b03456SIngo Weinhold {
378*23b03456SIngo Weinhold IDFinderVisitor visitor(id);
379*23b03456SIngo Weinhold return const_cast<BDiskDeviceList*>(this)->VisitEachPartition(&visitor);
380*23b03456SIngo Weinhold }
381*23b03456SIngo Weinhold
382*23b03456SIngo Weinhold // MountPointMoved
383*23b03456SIngo Weinhold /*! \brief Invoked, when the mount point of a partition has been moved.
384*23b03456SIngo Weinhold
385*23b03456SIngo Weinhold The list is locked, when this method is invoked.
386*23b03456SIngo Weinhold
387*23b03456SIngo Weinhold \param partition The concerned partition.
388*23b03456SIngo Weinhold */
389*23b03456SIngo Weinhold void
MountPointMoved(BPartition * partition)390*23b03456SIngo Weinhold BDiskDeviceList::MountPointMoved(BPartition *partition)
391*23b03456SIngo Weinhold {
392*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_MOUNT_POINT_MOVED);
393*23b03456SIngo Weinhold }
394*23b03456SIngo Weinhold
395*23b03456SIngo Weinhold // PartitionMounted
396*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been mounted.
397*23b03456SIngo Weinhold
398*23b03456SIngo Weinhold The list is locked, when this method is invoked.
399*23b03456SIngo Weinhold
400*23b03456SIngo Weinhold \param partition The concerned partition.
401*23b03456SIngo Weinhold */
402*23b03456SIngo Weinhold void
PartitionMounted(BPartition * partition)403*23b03456SIngo Weinhold BDiskDeviceList::PartitionMounted(BPartition *partition)
404*23b03456SIngo Weinhold {
405*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_MOUNTED);
406*23b03456SIngo Weinhold }
407*23b03456SIngo Weinhold
408*23b03456SIngo Weinhold // PartitionUnmounted
409*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been unmounted.
410*23b03456SIngo Weinhold
411*23b03456SIngo Weinhold The list is locked, when this method is invoked.
412*23b03456SIngo Weinhold
413*23b03456SIngo Weinhold \param partition The concerned partition.
414*23b03456SIngo Weinhold */
415*23b03456SIngo Weinhold void
PartitionUnmounted(BPartition * partition)416*23b03456SIngo Weinhold BDiskDeviceList::PartitionUnmounted(BPartition *partition)
417*23b03456SIngo Weinhold {
418*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_UNMOUNTED);
419*23b03456SIngo Weinhold }
420*23b03456SIngo Weinhold
421*23b03456SIngo Weinhold // PartitionInitialized
422*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been initialized.
423*23b03456SIngo Weinhold
424*23b03456SIngo Weinhold The list is locked, when this method is invoked.
425*23b03456SIngo Weinhold
426*23b03456SIngo Weinhold \param partition The concerned partition.
427*23b03456SIngo Weinhold */
428*23b03456SIngo Weinhold void
PartitionInitialized(BPartition * partition)429*23b03456SIngo Weinhold BDiskDeviceList::PartitionInitialized(BPartition *partition)
430*23b03456SIngo Weinhold {
431*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_INITIALIZED);
432*23b03456SIngo Weinhold }
433*23b03456SIngo Weinhold
434*23b03456SIngo Weinhold // PartitionResized
435*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been resized.
436*23b03456SIngo Weinhold
437*23b03456SIngo Weinhold The list is locked, when this method is invoked.
438*23b03456SIngo Weinhold
439*23b03456SIngo Weinhold \param partition The concerned partition.
440*23b03456SIngo Weinhold */
441*23b03456SIngo Weinhold void
PartitionResized(BPartition * partition)442*23b03456SIngo Weinhold BDiskDeviceList::PartitionResized(BPartition *partition)
443*23b03456SIngo Weinhold {
444*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_RESIZED);
445*23b03456SIngo Weinhold }
446*23b03456SIngo Weinhold
447*23b03456SIngo Weinhold // PartitionMoved
448*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been moved.
449*23b03456SIngo Weinhold
450*23b03456SIngo Weinhold The list is locked, when this method is invoked.
451*23b03456SIngo Weinhold
452*23b03456SIngo Weinhold \param partition The concerned partition.
453*23b03456SIngo Weinhold */
454*23b03456SIngo Weinhold void
PartitionMoved(BPartition * partition)455*23b03456SIngo Weinhold BDiskDeviceList::PartitionMoved(BPartition *partition)
456*23b03456SIngo Weinhold {
457*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_MOVED);
458*23b03456SIngo Weinhold }
459*23b03456SIngo Weinhold
460*23b03456SIngo Weinhold // PartitionCreated
461*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been created.
462*23b03456SIngo Weinhold
463*23b03456SIngo Weinhold The list is locked, when this method is invoked.
464*23b03456SIngo Weinhold
465*23b03456SIngo Weinhold \param partition The concerned partition.
466*23b03456SIngo Weinhold */
467*23b03456SIngo Weinhold void
PartitionCreated(BPartition * partition)468*23b03456SIngo Weinhold BDiskDeviceList::PartitionCreated(BPartition *partition)
469*23b03456SIngo Weinhold {
470*23b03456SIngo Weinhold }
471*23b03456SIngo Weinhold
472*23b03456SIngo Weinhold // PartitionDeleted
473*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been deleted.
474*23b03456SIngo Weinhold
475*23b03456SIngo Weinhold The method is called twice for a deleted partition. The first time
476*23b03456SIngo Weinhold before the BDiskDevice the partition belongs to has been updated. The
477*23b03456SIngo Weinhold \a partition parameter will point to a still valid BPartition object.
478*23b03456SIngo Weinhold On the second invocation the device object will have been updated and
479*23b03456SIngo Weinhold the partition object will have been deleted -- \a partition will be
480*23b03456SIngo Weinhold \c NULL then.
481*23b03456SIngo Weinhold
482*23b03456SIngo Weinhold The list is locked, when this method is invoked.
483*23b03456SIngo Weinhold
484*23b03456SIngo Weinhold \param partition The concerned partition. Only non- \c NULL on the first
485*23b03456SIngo Weinhold invocation.
486*23b03456SIngo Weinhold \param partitionID The ID of the concerned partition.
487*23b03456SIngo Weinhold */
488*23b03456SIngo Weinhold void
PartitionDeleted(BPartition * partition,partition_id partitionID)489*23b03456SIngo Weinhold BDiskDeviceList::PartitionDeleted(BPartition *partition,
490*23b03456SIngo Weinhold partition_id partitionID)
491*23b03456SIngo Weinhold {
492*23b03456SIngo Weinhold }
493*23b03456SIngo Weinhold
494*23b03456SIngo Weinhold // PartitionDefragmented
495*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been defragmented.
496*23b03456SIngo Weinhold
497*23b03456SIngo Weinhold The list is locked, when this method is invoked.
498*23b03456SIngo Weinhold
499*23b03456SIngo Weinhold \param partition The concerned partition.
500*23b03456SIngo Weinhold */
501*23b03456SIngo Weinhold void
PartitionDefragmented(BPartition * partition)502*23b03456SIngo Weinhold BDiskDeviceList::PartitionDefragmented(BPartition *partition)
503*23b03456SIngo Weinhold {
504*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_DEFRAGMENTED);
505*23b03456SIngo Weinhold }
506*23b03456SIngo Weinhold
507*23b03456SIngo Weinhold // PartitionRepaired
508*23b03456SIngo Weinhold /*! \brief Invoked, when a partition has been repaired.
509*23b03456SIngo Weinhold
510*23b03456SIngo Weinhold The list is locked, when this method is invoked.
511*23b03456SIngo Weinhold
512*23b03456SIngo Weinhold \param partition The concerned partition.
513*23b03456SIngo Weinhold */
514*23b03456SIngo Weinhold void
PartitionRepaired(BPartition * partition)515*23b03456SIngo Weinhold BDiskDeviceList::PartitionRepaired(BPartition *partition)
516*23b03456SIngo Weinhold {
517*23b03456SIngo Weinhold PartitionChanged(partition, B_DEVICE_PARTITION_REPAIRED);
518*23b03456SIngo Weinhold }
519*23b03456SIngo Weinhold
520*23b03456SIngo Weinhold // PartitionChanged
521*23b03456SIngo Weinhold /*! \brief Catch-all method invoked by the \c Partition*() hooks, save by
522*23b03456SIngo Weinhold PartitionCreated() and PartitionDeleted().
523*23b03456SIngo Weinhold
524*23b03456SIngo Weinhold If you're interested only in the fact, that something about the partition
525*23b03456SIngo Weinhold changed, you can just override this hook instead of the ones telling you
526*23b03456SIngo Weinhold exactly what happened.
527*23b03456SIngo Weinhold
528*23b03456SIngo Weinhold \param partition The concerned partition.
529*23b03456SIngo Weinhold \param event The event that occurred, if you are interested in it after all.
530*23b03456SIngo Weinhold */
531*23b03456SIngo Weinhold void
PartitionChanged(BPartition * partition,uint32 event)532*23b03456SIngo Weinhold BDiskDeviceList::PartitionChanged(BPartition *partition, uint32 event)
533*23b03456SIngo Weinhold {
534*23b03456SIngo Weinhold }
535*23b03456SIngo Weinhold
536*23b03456SIngo Weinhold // MediaChanged
537*23b03456SIngo Weinhold /*! \brief Invoked, when the media of a device has been changed.
538*23b03456SIngo Weinhold
539*23b03456SIngo Weinhold The list is locked, when this method is invoked.
540*23b03456SIngo Weinhold
541*23b03456SIngo Weinhold \param device The concerned device.
542*23b03456SIngo Weinhold */
543*23b03456SIngo Weinhold void
MediaChanged(BDiskDevice * device)544*23b03456SIngo Weinhold BDiskDeviceList::MediaChanged(BDiskDevice *device)
545*23b03456SIngo Weinhold {
546*23b03456SIngo Weinhold }
547*23b03456SIngo Weinhold
548*23b03456SIngo Weinhold // DeviceAdded
549*23b03456SIngo Weinhold /*! \brief Invoked, when a device has been added.
550*23b03456SIngo Weinhold
551*23b03456SIngo Weinhold The list is locked, when this method is invoked.
552*23b03456SIngo Weinhold
553*23b03456SIngo Weinhold \param device The concerned device.
554*23b03456SIngo Weinhold */
555*23b03456SIngo Weinhold void
DeviceAdded(BDiskDevice * device)556*23b03456SIngo Weinhold BDiskDeviceList::DeviceAdded(BDiskDevice *device)
557*23b03456SIngo Weinhold {
558*23b03456SIngo Weinhold }
559*23b03456SIngo Weinhold
560*23b03456SIngo Weinhold // DeviceRemoved
561*23b03456SIngo Weinhold /*! \brief Invoked, when a device has been removed.
562*23b03456SIngo Weinhold
563*23b03456SIngo Weinhold The supplied object is already removed from the list and is going to be
564*23b03456SIngo Weinhold deleted after the hook returns.
565*23b03456SIngo Weinhold
566*23b03456SIngo Weinhold The list is locked, when this method is invoked.
567*23b03456SIngo Weinhold
568*23b03456SIngo Weinhold \param device The concerned device.
569*23b03456SIngo Weinhold */
570*23b03456SIngo Weinhold void
DeviceRemoved(BDiskDevice * device)571*23b03456SIngo Weinhold BDiskDeviceList::DeviceRemoved(BDiskDevice *device)
572*23b03456SIngo Weinhold {
573*23b03456SIngo Weinhold }
574*23b03456SIngo Weinhold
575*23b03456SIngo Weinhold // _StartWatching
576*23b03456SIngo Weinhold /*! \brief Starts watching for disk device notifications.
577*23b03456SIngo Weinhold
578*23b03456SIngo Weinhold The object must be locked (if possible at all), when this method is
579*23b03456SIngo Weinhold invoked.
580*23b03456SIngo Weinhold
581*23b03456SIngo Weinhold \return \c B_OK, if everything went fine, another error code otherwise.
582*23b03456SIngo Weinhold */
583*23b03456SIngo Weinhold status_t
_StartWatching()584*23b03456SIngo Weinhold BDiskDeviceList::_StartWatching()
585*23b03456SIngo Weinhold {
586*23b03456SIngo Weinhold if (!Looper() || fSubscribed)
587*23b03456SIngo Weinhold return B_BAD_VALUE;
588*23b03456SIngo Weinhold
589*23b03456SIngo Weinhold status_t error = BDiskDeviceRoster().StartWatching(BMessenger(this));
590*23b03456SIngo Weinhold fSubscribed = (error == B_OK);
591*23b03456SIngo Weinhold return error;
592*23b03456SIngo Weinhold }
593*23b03456SIngo Weinhold
594*23b03456SIngo Weinhold // _StopWatching
595*23b03456SIngo Weinhold /*! \brief Stop watching for disk device notifications.
596*23b03456SIngo Weinhold
597*23b03456SIngo Weinhold The object must be locked (if possible at all), when this method is
598*23b03456SIngo Weinhold invoked.
599*23b03456SIngo Weinhold */
600*23b03456SIngo Weinhold void
_StopWatching()601*23b03456SIngo Weinhold BDiskDeviceList::_StopWatching()
602*23b03456SIngo Weinhold {
603*23b03456SIngo Weinhold if (fSubscribed) {
604*23b03456SIngo Weinhold BDiskDeviceRoster().StopWatching(BMessenger(this));
605*23b03456SIngo Weinhold fSubscribed = false;
606*23b03456SIngo Weinhold }
607*23b03456SIngo Weinhold }
608*23b03456SIngo Weinhold
609*23b03456SIngo Weinhold // _MountPointMoved
610*23b03456SIngo Weinhold /*! \brief Handles a "mount point moved" message.
611*23b03456SIngo Weinhold \param message The respective notification message.
612*23b03456SIngo Weinhold */
613*23b03456SIngo Weinhold void
_MountPointMoved(BMessage * message)614*23b03456SIngo Weinhold BDiskDeviceList::_MountPointMoved(BMessage *message)
615*23b03456SIngo Weinhold {
616*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
617*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
618*23b03456SIngo Weinhold MountPointMoved(partition);
619*23b03456SIngo Weinhold }
620*23b03456SIngo Weinhold }
621*23b03456SIngo Weinhold
622*23b03456SIngo Weinhold // _PartitionMounted
623*23b03456SIngo Weinhold /*! \brief Handles a "partition mounted" message.
624*23b03456SIngo Weinhold \param message The respective notification message.
625*23b03456SIngo Weinhold */
626*23b03456SIngo Weinhold void
_PartitionMounted(BMessage * message)627*23b03456SIngo Weinhold BDiskDeviceList::_PartitionMounted(BMessage *message)
628*23b03456SIngo Weinhold {
629*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
630*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
631*23b03456SIngo Weinhold PartitionMounted(partition);
632*23b03456SIngo Weinhold }
633*23b03456SIngo Weinhold }
634*23b03456SIngo Weinhold
635*23b03456SIngo Weinhold // _PartitionUnmounted
636*23b03456SIngo Weinhold /*! \brief Handles a "partition unmounted" message.
637*23b03456SIngo Weinhold \param message The respective notification message.
638*23b03456SIngo Weinhold */
639*23b03456SIngo Weinhold void
_PartitionUnmounted(BMessage * message)640*23b03456SIngo Weinhold BDiskDeviceList::_PartitionUnmounted(BMessage *message)
641*23b03456SIngo Weinhold {
642*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
643*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
644*23b03456SIngo Weinhold PartitionUnmounted(partition);
645*23b03456SIngo Weinhold }
646*23b03456SIngo Weinhold }
647*23b03456SIngo Weinhold
648*23b03456SIngo Weinhold // _PartitionInitialized
649*23b03456SIngo Weinhold /*! \brief Handles a "partition initialized" message.
650*23b03456SIngo Weinhold \param message The respective notification message.
651*23b03456SIngo Weinhold */
652*23b03456SIngo Weinhold void
_PartitionInitialized(BMessage * message)653*23b03456SIngo Weinhold BDiskDeviceList::_PartitionInitialized(BMessage *message)
654*23b03456SIngo Weinhold {
655*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
656*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
657*23b03456SIngo Weinhold PartitionInitialized(partition);
658*23b03456SIngo Weinhold }
659*23b03456SIngo Weinhold }
660*23b03456SIngo Weinhold
661*23b03456SIngo Weinhold // _PartitionResized
662*23b03456SIngo Weinhold /*! \brief Handles a "partition resized" message.
663*23b03456SIngo Weinhold \param message The respective notification message.
664*23b03456SIngo Weinhold */
665*23b03456SIngo Weinhold void
_PartitionResized(BMessage * message)666*23b03456SIngo Weinhold BDiskDeviceList::_PartitionResized(BMessage *message)
667*23b03456SIngo Weinhold {
668*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
669*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
670*23b03456SIngo Weinhold PartitionResized(partition);
671*23b03456SIngo Weinhold }
672*23b03456SIngo Weinhold }
673*23b03456SIngo Weinhold
674*23b03456SIngo Weinhold // _PartitionMoved
675*23b03456SIngo Weinhold /*! \brief Handles a "partition moved" message.
676*23b03456SIngo Weinhold \param message The respective notification message.
677*23b03456SIngo Weinhold */
678*23b03456SIngo Weinhold void
_PartitionMoved(BMessage * message)679*23b03456SIngo Weinhold BDiskDeviceList::_PartitionMoved(BMessage *message)
680*23b03456SIngo Weinhold {
681*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
682*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
683*23b03456SIngo Weinhold PartitionMoved(partition);
684*23b03456SIngo Weinhold }
685*23b03456SIngo Weinhold }
686*23b03456SIngo Weinhold
687*23b03456SIngo Weinhold // _PartitionCreated
688*23b03456SIngo Weinhold /*! \brief Handles a "partition created" message.
689*23b03456SIngo Weinhold \param message The respective notification message.
690*23b03456SIngo Weinhold */
691*23b03456SIngo Weinhold void
_PartitionCreated(BMessage * message)692*23b03456SIngo Weinhold BDiskDeviceList::_PartitionCreated(BMessage *message)
693*23b03456SIngo Weinhold {
694*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
695*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
696*23b03456SIngo Weinhold PartitionCreated(partition);
697*23b03456SIngo Weinhold }
698*23b03456SIngo Weinhold }
699*23b03456SIngo Weinhold
700*23b03456SIngo Weinhold // _PartitionDeleted
701*23b03456SIngo Weinhold /*! \brief Handles a "partition deleted" message.
702*23b03456SIngo Weinhold \param message The respective notification message.
703*23b03456SIngo Weinhold */
704*23b03456SIngo Weinhold void
_PartitionDeleted(BMessage * message)705*23b03456SIngo Weinhold BDiskDeviceList::_PartitionDeleted(BMessage *message)
706*23b03456SIngo Weinhold {
707*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message)) {
708*23b03456SIngo Weinhold partition_id id = partition->ID();
709*23b03456SIngo Weinhold PartitionDeleted(partition, id);
710*23b03456SIngo Weinhold if (_UpdateDevice(message))
711*23b03456SIngo Weinhold PartitionDeleted(NULL, id);
712*23b03456SIngo Weinhold }
713*23b03456SIngo Weinhold }
714*23b03456SIngo Weinhold
715*23b03456SIngo Weinhold // _PartitionDefragmented
716*23b03456SIngo Weinhold /*! \brief Handles a "partition defragmented" message.
717*23b03456SIngo Weinhold \param message The respective notification message.
718*23b03456SIngo Weinhold */
719*23b03456SIngo Weinhold void
_PartitionDefragmented(BMessage * message)720*23b03456SIngo Weinhold BDiskDeviceList::_PartitionDefragmented(BMessage *message)
721*23b03456SIngo Weinhold {
722*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
723*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
724*23b03456SIngo Weinhold PartitionDefragmented(partition);
725*23b03456SIngo Weinhold }
726*23b03456SIngo Weinhold }
727*23b03456SIngo Weinhold
728*23b03456SIngo Weinhold // _PartitionRepaired
729*23b03456SIngo Weinhold /*! \brief Handles a "partition repaired" message.
730*23b03456SIngo Weinhold \param message The respective notification message.
731*23b03456SIngo Weinhold */
732*23b03456SIngo Weinhold void
_PartitionRepaired(BMessage * message)733*23b03456SIngo Weinhold BDiskDeviceList::_PartitionRepaired(BMessage *message)
734*23b03456SIngo Weinhold {
735*23b03456SIngo Weinhold if (_UpdateDevice(message) != NULL) {
736*23b03456SIngo Weinhold if (BPartition *partition = _FindPartition(message))
737*23b03456SIngo Weinhold PartitionRepaired(partition);
738*23b03456SIngo Weinhold }
739*23b03456SIngo Weinhold }
740*23b03456SIngo Weinhold
741*23b03456SIngo Weinhold // _MediaChanged
742*23b03456SIngo Weinhold /*! \brief Handles a "media changed" message.
743*23b03456SIngo Weinhold \param message The respective notification message.
744*23b03456SIngo Weinhold */
745*23b03456SIngo Weinhold void
_MediaChanged(BMessage * message)746*23b03456SIngo Weinhold BDiskDeviceList::_MediaChanged(BMessage *message)
747*23b03456SIngo Weinhold {
748*23b03456SIngo Weinhold if (BDiskDevice *device = _UpdateDevice(message))
749*23b03456SIngo Weinhold MediaChanged(device);
750*23b03456SIngo Weinhold }
751*23b03456SIngo Weinhold
752*23b03456SIngo Weinhold // _DeviceAdded
753*23b03456SIngo Weinhold /*! \brief Handles a "device added" message.
754*23b03456SIngo Weinhold \param message The respective notification message.
755*23b03456SIngo Weinhold */
756*23b03456SIngo Weinhold void
_DeviceAdded(BMessage * message)757*23b03456SIngo Weinhold BDiskDeviceList::_DeviceAdded(BMessage *message)
758*23b03456SIngo Weinhold {
759*23b03456SIngo Weinhold int32 id;
760*23b03456SIngo Weinhold if (message->FindInt32("device_id", &id) == B_OK && !DeviceWithID(id)) {
761*23b03456SIngo Weinhold BDiskDevice *device = new(nothrow) BDiskDevice;
762*23b03456SIngo Weinhold if (BDiskDeviceRoster().GetDeviceWithID(id, device) == B_OK) {
763*23b03456SIngo Weinhold fDevices.AddItem(device);
764*23b03456SIngo Weinhold DeviceAdded(device);
765*23b03456SIngo Weinhold } else
766*23b03456SIngo Weinhold delete device;
767*23b03456SIngo Weinhold }
768*23b03456SIngo Weinhold }
769*23b03456SIngo Weinhold
770*23b03456SIngo Weinhold // _DeviceRemoved
771*23b03456SIngo Weinhold /*! \brief Handles a "device removed" message.
772*23b03456SIngo Weinhold \param message The respective notification message.
773*23b03456SIngo Weinhold */
774*23b03456SIngo Weinhold void
_DeviceRemoved(BMessage * message)775*23b03456SIngo Weinhold BDiskDeviceList::_DeviceRemoved(BMessage *message)
776*23b03456SIngo Weinhold {
777*23b03456SIngo Weinhold if (BDiskDevice *device = _FindDevice(message)) {
778*23b03456SIngo Weinhold fDevices.RemoveItem(device, false);
779*23b03456SIngo Weinhold DeviceRemoved(device);
780*23b03456SIngo Weinhold delete device;
781*23b03456SIngo Weinhold }
782*23b03456SIngo Weinhold }
783*23b03456SIngo Weinhold
784*23b03456SIngo Weinhold // _FindDevice
785*23b03456SIngo Weinhold /*! \brief Returns the device for the ID contained in a motification message.
786*23b03456SIngo Weinhold \param message The notification message.
787*23b03456SIngo Weinhold \return The device with the ID, or \c NULL, if the ID or the device could
788*23b03456SIngo Weinhold not be found.
789*23b03456SIngo Weinhold */
790*23b03456SIngo Weinhold BDiskDevice *
_FindDevice(BMessage * message)791*23b03456SIngo Weinhold BDiskDeviceList::_FindDevice(BMessage *message)
792*23b03456SIngo Weinhold {
793*23b03456SIngo Weinhold BDiskDevice *device = NULL;
794*23b03456SIngo Weinhold int32 id;
795*23b03456SIngo Weinhold if (message->FindInt32("device_id", &id) == B_OK)
796*23b03456SIngo Weinhold device = DeviceWithID(id);
797*23b03456SIngo Weinhold return device;
798*23b03456SIngo Weinhold }
799*23b03456SIngo Weinhold
800*23b03456SIngo Weinhold // _FindPartition
801*23b03456SIngo Weinhold /*! \brief Returns the partition for the ID contained in a motification
802*23b03456SIngo Weinhold message.
803*23b03456SIngo Weinhold \param message The notification message.
804*23b03456SIngo Weinhold \return The partition with the ID, or \c NULL, if the ID or the partition
805*23b03456SIngo Weinhold could not be found.*/
806*23b03456SIngo Weinhold BPartition *
_FindPartition(BMessage * message)807*23b03456SIngo Weinhold BDiskDeviceList::_FindPartition(BMessage *message)
808*23b03456SIngo Weinhold {
809*23b03456SIngo Weinhold BPartition *partition = NULL;
810*23b03456SIngo Weinhold int32 id;
811*23b03456SIngo Weinhold if (message->FindInt32("partition_id", &id) == B_OK)
812*23b03456SIngo Weinhold partition = PartitionWithID(id);
813*23b03456SIngo Weinhold return partition;
814*23b03456SIngo Weinhold }
815*23b03456SIngo Weinhold
816*23b03456SIngo Weinhold // _UpdateDevice
817*23b03456SIngo Weinhold /*! \brief Finds the device for the ID contained in a motification message
818*23b03456SIngo Weinhold and updates it.
819*23b03456SIngo Weinhold \param message The notification message.
820*23b03456SIngo Weinhold \return The device with the ID, or \c NULL, if the ID or the device could
821*23b03456SIngo Weinhold not be found.
822*23b03456SIngo Weinhold */
823*23b03456SIngo Weinhold BDiskDevice *
_UpdateDevice(BMessage * message)824*23b03456SIngo Weinhold BDiskDeviceList::_UpdateDevice(BMessage *message)
825*23b03456SIngo Weinhold {
826*23b03456SIngo Weinhold BDiskDevice *device = _FindDevice(message);
827*23b03456SIngo Weinhold if (device) {
828*23b03456SIngo Weinhold if (device->Update() != B_OK) {
829*23b03456SIngo Weinhold fDevices.RemoveItem(device);
830*23b03456SIngo Weinhold device = NULL;
831*23b03456SIngo Weinhold }
832*23b03456SIngo Weinhold }
833*23b03456SIngo Weinhold return device;
834*23b03456SIngo Weinhold }
835*23b03456SIngo Weinhold
836