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 <image.h> 10 11 #include <DiskDeviceDefs.h> 12 #include <Messenger.h> 13 #include <SupportDefs.h> 14 15 class BDirectory; 16 class BDiskDevice; 17 class BDiskDeviceJob; 18 class BDiskDeviceVisiting; 19 class BDiskDeviceVisitor; 20 class BDiskScannerPartitionAddOn; 21 class BDiskSystem; 22 class BPartition; 23 24 namespace BPrivate { 25 class AddOnImage; 26 } 27 28 // watchable events 29 enum { 30 // Basic masks 31 B_DEVICE_REQUEST_MOUNT_POINT = 0x0001, // mount point changes 32 B_DEVICE_REQUEST_MOUNTING = 0x0002, // mounting/unmounting 33 B_DEVICE_REQUEST_PARTITION = 0x0004, // partition changes 34 B_DEVICE_REQUEST_DEVICE = 0x0008, // device changes (media changes) 35 B_DEVICE_REQUEST_DEVICE_LIST = 0x0010, // device additions/removals 36 B_DEVICE_REQUEST_JOB_LIST = 0x0020, // job addition/initiation/cancellation/completion 37 B_DEVICE_REQUEST_JOB_SIMPLE_PROGRESS = 0x0040, // simple job progress (i.e. "% complete" only) 38 B_DEVICE_REQUEST_JOB_EXTRA_PROGRESS = 0x0080, // extra info on job progress (no "% complete" info) 39 40 // Combination masks 41 B_DEVICE_REQUEST_JOB_COMPLETE_PROGRESS = 0x00C0, // complete job progress info 42 B_DEVICE_REQUEST_ALL = 0xffff, // all events 43 }; 44 45 // notification message "what" field 46 // TODO: move to app/AppDefs.h 47 enum { 48 B_DEVICE_UPDATE = 'DUPD' 49 }; 50 51 // notification message "event" field values 52 enum { 53 B_DEVICE_MOUNT_POINT_MOVED, // mount point moved/renamed 54 B_DEVICE_PARTITION_MOUNTED, // partition mounted 55 B_DEVICE_PARTITION_UNMOUNTED, // partition unmounted 56 B_DEVICE_PARTITION_INITIALIZED, // partition initialized 57 B_DEVICE_PARTITION_RESIZED, // partition resized 58 B_DEVICE_PARTITION_MOVED, // partition moved 59 B_DEVICE_PARTITION_CREATED, // partition created 60 B_DEVICE_PARTITION_DELETED, // partition deleted 61 B_DEVICE_PARTITION_DEFRAGMENTED, // partition defragmented 62 B_DEVICE_PARTITION_REPAIRED, // partition repaired 63 B_DEVICE_MEDIA_CHANGED, // media changed 64 B_DEVICE_ADDED, // device added 65 B_DEVICE_REMOVED, // device removed 66 B_DEVICE_JOB_SCHEDULED, // job added 67 B_DEVICE_JOB_INITIATED, // job initiated 68 B_DEVICE_JOB_CANCELED, // job canceled 69 B_DEVICE_JOB_FINISHED, // job finished 70 B_DEVICE_JOB_SIMPLE_PROGRESS, // job percent complete progress 71 B_DEVICE_JOB_EXTRA_PROGRESS, // extended job progress info 72 }; 73 74 // notification message "cause" field values 75 enum { 76 // helpful causes 77 B_DEVICE_CAUSE_MEDIA_CHANGED, 78 B_DEVICE_CAUSE_FORMATTED, // is this still applicable? 79 B_DEVICE_CAUSE_PARTITIONED, // is this still applicable? 80 B_DEVICE_CAUSE_INITIALIZED, // is this still applicable? 81 // unknown cause 82 B_DEVICE_CAUSE_UNKNOWN, 83 // for internal use only (e.g.: partition added, because device added) 84 B_DEVICE_CAUSE_PARENT_CHANGED, 85 }; 86 87 class BDiskDeviceRoster { 88 public: 89 BDiskDeviceRoster(); 90 ~BDiskDeviceRoster(); 91 92 status_t GetNextDevice(BDiskDevice *device); 93 status_t RewindDevices(); 94 95 status_t GetNextDiskSystem(BDiskSystem *system); 96 status_t RewindDiskSystems(); 97 98 // Active jobs are those that are scheduled or in-progress 99 status_t GetNextActiveJob(BDiskDeviceJob *job); 100 status_t RewindActiveJobs(); 101 102 partition_id RegisterFileDevice(const char *filename); 103 // publishes: /dev/disk/virtual/files/<disk device ID>/raw 104 status_t UnregisterFileDevice(const char *filename); 105 status_t UnregisterFileDevice(partition_id device); 106 107 bool VisitEachDevice(BDiskDeviceVisitor *visitor, 108 BDiskDevice *device = NULL); 109 bool VisitEachPartition(BDiskDeviceVisitor *visitor, 110 BDiskDevice *device = NULL, 111 BPartition **partition = NULL); 112 113 bool VisitEachMountedPartition(BDiskDeviceVisitor *visitor, 114 BDiskDevice *device = NULL, 115 BPartition **partition = NULL); 116 bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor, 117 BDiskDevice *device = NULL, 118 BPartition **partition = NULL); 119 120 status_t GetDeviceWithID(partition_id id, BDiskDevice *device) const; 121 status_t GetPartitionWithID(partition_id id, BDiskDevice *device, 122 BPartition **partition) const; 123 124 status_t GetDeviceForPath(const char *filename, BDiskDevice *device); 125 status_t GetPartitionForPath(const char *filename, BDiskDevice *device, 126 BPartition **partition); 127 128 status_t StartWatching(BMessenger target, 129 uint32 eventMask = B_DEVICE_REQUEST_ALL); 130 status_t StartWatchingJob(BDiskDeviceJob *job, BMessenger target, 131 uint32 eventMask = B_DEVICE_REQUEST_JOB_COMPLETE_PROGRESS); 132 // TODO: Maybe better a BDiskDeviceJob::{Start,Stop}Watching()? 133 status_t StopWatching(BMessenger target); 134 135 private: 136 #if 0 137 status_t _GetObjectWithID(const char *fieldName, partition_id id, 138 BDiskDevice *device) const; 139 140 // TODO: Introduce iterators instead of these functions. 141 142 static status_t _GetNextAddOn(BDirectory **directory, int32 *index, 143 const char *subdir, 144 BPrivate::AddOnImage *image); 145 static status_t _GetNextAddOn(BDirectory *directory, 146 BPrivate::AddOnImage *image); 147 static status_t _GetNextAddOnDir(BPath *path, int32 *index, 148 const char *subdir); 149 static status_t _GetNextAddOnDir(BDirectory **directory, int32 *index, 150 const char *subdir); 151 152 static status_t _LoadPartitionAddOn(const char *partitioningSystem, 153 BPrivate::AddOnImage *image, 154 BDiskScannerPartitionAddOn **addOn); 155 #endif // 0 156 private: 157 int32 fDeviceCookie; 158 int32 fDiskSystemCookie; 159 int32 fJobCookie; 160 // BDirectory *fPartitionAddOnDir; 161 // BDirectory *fFSAddOnDir; 162 // int32 fPartitionAddOnDirIndex; 163 // int32 fFSAddOnDirIndex; 164 }; 165 166 #endif // _DISK_DEVICE_ROSTER_H 167