RE: Diskarbitration callback
RE: Diskarbitration callback
- Subject: RE: Diskarbitration callback
- From: "Andy Green" <email@hidden>
- Date: Thu, 8 May 2008 17:58:51 +0100
- 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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden