site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Thread-index: AcixDK5OFD303bvnSfWpoo07qb/QWQAH4G6Q Thread-topic: Diskarbitration callback
I've written some code which uses the diskArbitration framework to unmount (and eject) a disk. It works, in that the disk gets unmounted, but my callback isn't being called, even though the operation is successful. Any chance of spotting the mistake in this code fragment? :-
I think you'll have to schedule the session with a run loop to get any callback actions.
Wow - works like a charm! When I say that, I mean it works, but I have no idea how! I'll have to go read up on run loops: in the meantime here's the working code for posterity - is this what you meant? And an awkward question: my 'real' code will be in a library, called from both command line tools, and from a cocoa app. Is this run-loop hocus pocus safe in both environments? struct Nothing { bool dummy; }; static void AndygDiskArbCallback( DADiskRef disk, DADissenterRef dissenter, void * context) { TRACE("callback..."); if (dissenter) { DAReturn status = DADissenterGetStatus( dissenter ); TRACE("DENIED (0x%x)!...", status); } else { TRACE("granted..."); Nothing * n = (Nothing *)context; assert(n); n->dummy = true; } // unlock the main thread CFRunLoopStop(CFRunLoopGetCurrent()); } int main(int argc, const char *argv[]) { const char * cStr = "disk3s10"; Nothing * n = new Nothing; n->dummy = false; DASessionRef diskArbSession = DASessionCreate(kCFAllocatorDefault); assert(diskArbSession); DASessionScheduleWithRunLoop(diskArbSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); DADiskRef disk = DADiskCreateFromBSDName( kCFAllocatorDefault, diskArbSession, cStr ); assert(disk); TRACE("confirming %s == %s??\n", DADiskGetBSDName(disk), cStr); DADiskRef whole = DADiskCopyWholeDisk( disk ); if ( whole ) { TRACE("wholedisk == %s\n", DADiskGetBSDName(whole)); DADiskUnmount(whole, kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce, AndygDiskArbCallback, n); TRACE("------Wait1..."); CFRunLoopRun(); TRACE("Ping!\n"); if (n->dummy) { TRACE("UNMOUNT successful\n"); n->dummy = false; DADiskEject( whole, kDADiskEjectOptionDefault, AndygDiskArbCallback, n ); TRACE("------Wait2..."); CFRunLoopRun(); TRACE("Ping!\n"); if (n->dummy) { TRACE("EJECT SUCCESSFUL\n"); } } CFRelease(whole); } CFRelease(disk); DASessionUnscheduleFromRunLoop(diskArbSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); CFRelease(diskArbSession); TRACE("AT THE END OF IT ALL, n=%d\n", n->dummy); delete(n); } _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Andy Green