Unmount support on Mac.
This commit is contained in:
parent
a9d75e628b
commit
8ffc77e5b4
@ -33,6 +33,11 @@ class MacDeviceLister : public DeviceLister {
|
|||||||
static void DiskAddedCallback(DADiskRef disk, void* context);
|
static void DiskAddedCallback(DADiskRef disk, void* context);
|
||||||
static void DiskRemovedCallback(DADiskRef disk, void* context);
|
static void DiskRemovedCallback(DADiskRef disk, void* context);
|
||||||
|
|
||||||
|
static void DiskUnmountCallback(
|
||||||
|
DADiskRef disk, DADissenterRef dissenter, void* context);
|
||||||
|
|
||||||
|
DASessionRef loop_session_;
|
||||||
|
|
||||||
QMap<QString, QString> current_devices_;
|
QMap<QString, QString> current_devices_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ MacDeviceLister::MacDeviceLister() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MacDeviceLister::~MacDeviceLister() {
|
MacDeviceLister::~MacDeviceLister() {
|
||||||
|
CFRelease(loop_session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacDeviceLister::Init() {
|
void MacDeviceLister::Init() {
|
||||||
@ -29,14 +30,12 @@ void MacDeviceLister::Init() {
|
|||||||
|
|
||||||
CFRunLoopRef run_loop = CFRunLoopGetCurrent();
|
CFRunLoopRef run_loop = CFRunLoopGetCurrent();
|
||||||
|
|
||||||
DASessionRef da_session = DASessionCreate(kCFAllocatorDefault);
|
loop_session_ = DASessionCreate(kCFAllocatorDefault);
|
||||||
DARegisterDiskAppearedCallback(
|
DARegisterDiskAppearedCallback(
|
||||||
da_session, kDADiskDescriptionMatchVolumeMountable, &DiskAddedCallback, reinterpret_cast<void*>(this));
|
loop_session_, kDADiskDescriptionMatchVolumeMountable, &DiskAddedCallback, reinterpret_cast<void*>(this));
|
||||||
DARegisterDiskDisappearedCallback(
|
DARegisterDiskDisappearedCallback(
|
||||||
da_session, NULL, &DiskRemovedCallback, reinterpret_cast<void*>(this));
|
loop_session_, NULL, &DiskRemovedCallback, reinterpret_cast<void*>(this));
|
||||||
DASessionScheduleWithRunLoop(da_session, run_loop, kCFRunLoopDefaultMode);
|
DASessionScheduleWithRunLoop(loop_session_, run_loop, kCFRunLoopDefaultMode);
|
||||||
|
|
||||||
CFRelease(da_session);
|
|
||||||
|
|
||||||
CFRunLoopRun();
|
CFRunLoopRun();
|
||||||
}
|
}
|
||||||
@ -328,6 +327,22 @@ quint64 MacDeviceLister::DeviceFreeSpace(const QString& serial){
|
|||||||
|
|
||||||
QVariantMap MacDeviceLister::DeviceHardwareInfo(const QString& id){return QVariantMap();}
|
QVariantMap MacDeviceLister::DeviceHardwareInfo(const QString& id){return QVariantMap();}
|
||||||
|
|
||||||
void MacDeviceLister::UnmountDevice(const QString &id) {
|
void MacDeviceLister::UnmountDevice(const QString& serial) {
|
||||||
qFatal("Fixme");
|
QString bsd_name = current_devices_[serial];
|
||||||
|
DADiskRef disk = DADiskCreateFromBSDName(
|
||||||
|
kCFAllocatorDefault, loop_session_, bsd_name.toAscii().constData());
|
||||||
|
|
||||||
|
DADiskUnmount(disk, kDADiskUnmountOptionDefault, &DiskUnmountCallback, this);
|
||||||
|
|
||||||
|
CFRelease(disk);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MacDeviceLister::DiskUnmountCallback(
|
||||||
|
DADiskRef disk, DADissenterRef dissenter, void* context) {
|
||||||
|
MacDeviceLister* me = reinterpret_cast<MacDeviceLister*>(context);
|
||||||
|
if (dissenter) {
|
||||||
|
qDebug() << "Another app blocked the unmount";
|
||||||
|
} else {
|
||||||
|
DiskRemovedCallback(disk, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user