예제 #1
0
/* Eject the media in the currently opened device */
int PortBurn_EjectDevice(void *handle)
{
   PBHandle *h = (PBHandle *)handle;

   if (!h)
      return pbErrNoHandle;

   if (!h->device)
      return pbErrDeviceNotOpen;

   h->err = DRDeviceOpenTray(h->device);
   if (noErr == h->err)
      return pbSuccess;  /* success */

   h->err = DRDeviceEjectMedia(h->device);
   if (noErr == h->err)
      return pbSuccess;  /* success */

   return pbErrCannotEject;
}
예제 #2
0
/*
	druPromptForErasableMediaInDevice
	
	Interactively prompts for erasable media in a particular device.  The type of media 
	is not considered.
	
	When the call completes, there is erasable media in the drive and we have a reservation
	on the media (so nobody else can burn to it or grab it out from underneath us).
*/
void
druPromptForErasableMediaInDevice(DRDeviceRef device)
{
	DRNotificationCenterRef	notificationCenter = NULL;
	CFRunLoopSourceRef		source = NULL;
		
	/* If the device contains erasable media right now, then we're done. */
	if (druDeviceContainsErasableMedia(device))
		return;
	
	/* Display a prompt. */
	printf("Please insert erasable media.\n");
	
	/* Open the tray (and eject existing media, if any). */
	/* This call may or may not work - the media in the device may be busy
		and can't be unmounted, or the device may not even have a tray (slot-load
		drives are an example of this).  However, we don't really care; this is just
		a convenience to the user and will do the right thing if the right thing
		can be done. */
	/* We also don't want to eject the media if it's still spinning up -
		the user may have just inserted it, and it takes a good 5-10 seconds
		on some drives for discs to be recognized. */
	if (!druDeviceIsBecomingReady(device))
		DRDeviceEjectMedia(device);
	
	/* Sign up for device status notifications, and enter a tiny runloop so that we can avoid polling. */
	notificationCenter = DRNotificationCenterCreate();
	source = DRNotificationCenterCreateRunLoopSource(notificationCenter);
	CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
	DRNotificationCenterAddObserver(notificationCenter, NULL, druWaitForErasableMedia, NULL, device);
	CFRunLoopRun();
	CFRunLoopSourceInvalidate(source);
	
	/* Clean up memory and we're done. */
	if (notificationCenter != NULL)	CFRelease(notificationCenter);
	if (source != NULL)				CFRelease(source);
}
예제 #3
0
/* Eject the media in the currently opened device */
int PortBurn_EjectDevice(void *handle)
{
   PBHandle *h = (PBHandle *)handle;

   if (h == NULL) {
      return pbErrNoHandle;
   }

   if (h->device == NULL) {
      return pbErrDeviceNotOpen;
   }

   h->err = DRDeviceOpenTray(h->device);
   if (h->err == noErr) {
      return pbSuccess;  /* success */
   }

   h->err = DRDeviceEjectMedia(h->device);
   if (h->err == noErr) {
      return pbSuccess;  /* success */
   }

   return pbErrCannotEject;
}
예제 #4
0
파일: JDRDevice.c 프로젝트: ezavaleta/toys
JNIEXPORT jboolean JNICALL Java_jdrlib_JDRDevice_nativeEject(JNIEnv *env, jobject obj, jlong dev)
{
	DRDeviceRef device = (DRDeviceRef)(long)dev;
	
	return DRDeviceEjectMedia(device) == noErr ? 1 : 0;
}