Volume arrival/removal notifications

Hi Jules, could you add arrival/removal notifications for drive volumes?

TIA
/R

No time at the moment! Is it even possible on all OSes? I’ve never looked into how you’d do this.

Hmm… only know howto on Windows, on Mac there are kernel queues but I don’t know if they can handle volume adding. Removal should work though…

Edit: Just found this on the darwin devlist: http://lists.apple.com/archives/darwin-development/2001/Nov/msg00332.html
/R

on Windows:

check for case
WM_DEVICECHANGE:

with case DBT_DEVICEARRIVAL:
and case DBT_DEVICEREMOVECOMPLETE:

on Mac

[code]EventTypeSpec windowEvents[]={ { kEventClassVolume, kEventVolumeMounted}, { kEventClassVolume, kEventVolumeUnmounted} };

mEventHandlerUPP = NewEventHandlerUPP(::VolumeEventHandler);
OSErr err = InstallApplicationEventHandler(mEventHandlerUPP,
GetEventTypeCount(windowEvents),
windowEvents,
(void*) this,
&mEventHandlerRef);

pascal OSStatus VolumeEventHandler (EventHandlerCallRef eventHandlerCallRef, EventRef eventRef, void* userData)
{
UInt32 eventKind = GetEventKind(eventRef);
UInt32 eventClass = GetEventClass (eventRef);

switch (eventClass)
{
case kEventClassVolume:
{
FSVolumeRefNum refNum = 0;
GetEventParameter (eventRef, kEventParamDirectObject, typeFSVolumeRefNum, NULL, sizeof(refNum), NULL, &refNum);

  switch (eventKind)
  {
    case kEventVolumeMounted:
    {

// volume mounted
}
break;
case kEventVolumeUnmounted:
{
//volume unmounted
}
break;
}
}
}
return noErr;
}[/code]

Sorry but don’t have time to implement this in Juce myslef.
HTH

Thanks, very handy for reference if I get chance to add this!

Since I needed it a bit badly, I’ve implemented it for Win32 where I now can get volume change notifications. (tried to do it in juce-style :), will send you patches later on jules).

Will do it soon for Mac with the code above from otristan (thanks!)

Merry Christmas & Happy New Year!
/R

HAL (through dbus) can be leveraged to get this information on Linux-based systems, as well.
http://freedesktop.org/wiki/Software/hal
as well as http://en.wikipedia.org/wiki/D-Bus#Examples

Sounds like you’ve already solved the problem, but for future reference you could use the code posted here (Windows only):

http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=2469