/** * Use the DiskArbitration Daemon to inform us of media changes */ void MonitorThreadDarwin::run(void) { CFDictionaryRef match = kDADiskDescriptionMatchVolumeMountable; DASessionRef daSession = DASessionCreate(kCFAllocatorDefault); IOMasterPort(MACH_PORT_NULL, &sMasterPort); DARegisterDiskAppearedCallback(daSession, match, diskAppearedCallback, this); DARegisterDiskDisappearedCallback(daSession, match, diskDisappearedCallback, this); DARegisterDiskDescriptionChangedCallback(daSession, match, kDADiskDescriptionWatchVolumeName, diskChangedCallback, this); DASessionScheduleWithRunLoop(daSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); // Nice and simple, as long as our monitor is valid and active, // loop and let daSession check the devices. while (m_Monitor && m_Monitor->IsActive()) { // Run the run loop for interval (milliseconds) - this will // handle any disk arbitration appeared/dissappeared events CFRunLoopRunInMode(kCFRunLoopDefaultMode, (float) m_Interval / 1000.0f, false ); } DAUnregisterCallback(daSession, (void(*))diskChangedCallback, this); DAUnregisterCallback(daSession, (void(*))diskDisappearedCallback, this); DAUnregisterCallback(daSession, (void(*))diskAppearedCallback, this); CFRelease(daSession); }
DiskArbitrationDispatcher::DiskArbitrationDispatcher() : m_impl(new Impl) { m_impl->session = DASessionCreate(kCFAllocatorDefault); DARegisterDiskAppearedCallback(m_impl->session, nullptr, [](DADiskRef disk, void * ctx) { static_cast<DiskArbitrationDispatcher*>(ctx)->diskAppeared(disk); }, this); DARegisterDiskDisappearedCallback(m_impl->session, nullptr, [](DADiskRef disk, void * ctx) { static_cast<DiskArbitrationDispatcher*>(ctx)->diskDisappeared(disk); }, this); }
bool QDeviceWatcherPrivate::init() { //get sDevices //FSGetVolumeInfo() mSession = DASessionCreate(kCFAllocatorDefault); DARegisterDiskAppearedCallback(mSession, NULL, onDiskAppear, this); DARegisterDiskDisappearedCallback(mSession, NULL, onDiskDisappear, this); }
__private_extern__ void ExternalMedia_prime(void) { gExternalMediaSet = CFSetCreateMutable(0, 0, &kCFTypeSetCallBacks); if (!gExternalMediaSet) return; gDASession = DASessionCreate(0); DARegisterDiskAppearedCallback(gDASession, kDADiskDescriptionMatchVolumeMountable, _DiskAppeared, NULL); DARegisterDiskDisappearedCallback(gDASession, kDADiskDescriptionMatchVolumeMountable, _DiskDisappeared, NULL); DASessionScheduleWithRunLoop(gDASession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); }
void DiskArbitrationEventPublisher::restart() { if (run_loop_ == nullptr) { return; } stop(); WriteLock lock(mutex_); session_ = DASessionCreate(kCFAllocatorDefault); DARegisterDiskAppearedCallback( session_, nullptr, DiskArbitrationEventPublisher::DiskAppearedCallback, nullptr); DARegisterDiskDisappearedCallback( session_, nullptr, DiskArbitrationEventPublisher::DiskDisappearedCallback, nullptr); DASessionScheduleWithRunLoop(session_, run_loop_, kCFRunLoopDefaultMode); }