xref: /haiku/headers/private/storage/DiskDeviceRoster.h (revision d7496886521c82fdc76cd4b6b80bab61ffa2471e)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 
6 #ifndef _DISK_DEVICE_ROSTER_H
7 #define _DISK_DEVICE_ROSTER_H
8 
9 #include <DiskDeviceVisitor.h>
10 #include <Messenger.h>
11 #include <SupportDefs.h>
12 
13 class BDiskDevice;
14 class BPartition;
15 class BSession;
16 
17 // watchable events
18 enum {
19 	B_DEVICE_REQUEST_MOUNT_POINT	= 0x01,	// mount point changes
20 	B_DEVICE_REQUEST_MOUNTING		= 0x02,	// mounting/unmounting
21 	B_DEVICE_REQUEST_PARTITION		= 0x04,	// partition changes (initial.)
22 	B_DEVICE_REQUEST_SESSION		= 0x08,	// session changes (partitioning)
23 	B_DEVICE_REQUEST_DEVICE			= 0x10,	// device changes (media changes)
24 	B_DEVICE_REQUEST_DEVICE_LIST	= 0x20,	// device additions/removals
25 	B_DEVICE_REQUEST_ALL			= 0xff,	// all events
26 };
27 
28 // notification message "what" field
29 // TODO: move to app/AppDefs.h
30 enum {
31 	B_DEVICE_UPDATE	= 'DUPD'
32 };
33 
34 // notification message "event" field values
35 enum {
36 	B_DEVICE_MOUNT_POINT_MOVED,			// mount point moved/renamed
37 	B_DEVICE_PARTITION_MOUNTED,			// partition mounted
38 	B_DEVICE_PARTITION_UNMOUNTED,		// partition unmounted
39 	B_DEVICE_PARTITION_CHANGED,			// partition changed, e.g. initialized
40 										// or resized
41 	B_DEVICE_PARTITION_ADDED,			// partition added
42 	B_DEVICE_PARTITION_REMOVED,			// partition removed
43 	B_DEVICE_SESSION_ADDED,				// session added
44 	B_DEVICE_SESSION_REMOVED,			// session removed
45 	B_DEVICE_MEDIA_CHANGED,				// media changed
46 	B_DEVICE_ADDED,						// device added
47 	B_DEVICE_REMOVED					// device removed
48 };
49 
50 // notification message "cause" field values
51 enum {
52 	// helpful causes
53 	B_DEVICE_CAUSE_MEDIA_CHANGED,
54 	B_DEVICE_CAUSE_FORMATTED,
55 	B_DEVICE_CAUSE_PARTITIONED,
56 	B_DEVICE_CAUSE_INITIALIZED,
57 	// unknown cause
58 	B_DEVICE_CAUSE_UNKNOWN,
59 	// for internal use only (e.g.: partition added, because device added)
60 	B_DEVICE_CAUSE_PARENT_CHANGED,
61 };
62 
63 class BDiskDeviceRoster {
64 public:
65 	BDiskDeviceRoster();
66 	~BDiskDeviceRoster();
67 
68 	status_t GetNextDevice(BDiskDevice *device);
69 	status_t Rewind();
70 
71 	bool VisitEachDevice(BDiskDeviceVisitor *visitor,
72 						 BDiskDevice *device = NULL);
73 	bool VisitEachSession(BDiskDeviceVisitor *visitor,
74 						  BDiskDevice *device = NULL,
75 						  BSession **session = NULL);
76 	bool VisitEachPartition(BDiskDeviceVisitor *visitor,
77 							BDiskDevice *device = NULL,
78 							BPartition **partition = NULL);
79 	bool Traverse(BDiskDeviceVisitor *visitor);
80 
81 	bool VisitEachMountedPartition(BDiskDeviceVisitor *visitor,
82 								   BDiskDevice *device = NULL,
83 								   BPartition **partition = NULL);
84 	bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
85 									 BDiskDevice *device = NULL,
86 									 BPartition **partition = NULL);
87 	bool VisitEachInitializablePartition(BDiskDeviceVisitor *visitor,
88 										 BDiskDevice *device = NULL,
89 										 BPartition **partition = NULL);
90 
91 
92 	status_t GetDeviceWithID(int32 id, BDiskDevice *device) const;
93 	status_t GetSessionWithID(int32 id, BDiskDevice *device,
94 							  BSession **session) const;
95 	status_t GetPartitionWithID(int32 id, BDiskDevice *device,
96 								BPartition **partition) const;
97 
98 	status_t StartWatching(BMessenger target,
99 						   uint32 eventMask = B_DEVICE_REQUEST_ALL);
100 	status_t StopWatching(BMessenger target);
101 
102 private:
103 	status_t _GetObjectWithID(const char *fieldName, int32 id,
104 							  BDiskDevice *device) const;
105 
106 private:
107 	BMessenger	fManager;
108 	int32		fCookie;
109 };
110 
111 #endif	// _DISK_DEVICE_ROSTER_H
112