Skip to content

Loading…

Volume/device attachment and removal events #4

Open
wants to merge 1 commit into from

1 participant

@eisnerd

This adds platform-specific code to fire global "volume.added" and "volume.removed" events when removable devices containing filesystems are attached or ejected/removed. One event is fired per device, rather than per filesystem, and no specific information about the device(s) in question is provided.

I have added these same simple, you might say crude, system-related events to this branch for Windows and to the master branch with a similar implementation for Mac. Rather than providing a full device/volume information API, we have found simply being notified that some kind of change has occurred very useful in our application, with further platform-specific code that it may not be worth lumbering the SDK with being used in response to these events to identify and examine the devices of interest, such as USB flash drives.

Though this may not seem very polished or broadly useful, it would be useful to have this small additional feature incorporated in the official SDK, particularly on Windows where it is by far easiest to get this information from the message pumping code of the main application window than to achieve the same without it.

Thank you for considering this submission.

@eisnerd eisnerd Report volume removal and attachment events
on Windows, as volume.removed and volume.added
72b0408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 15, 2011
  1. @eisnerd

    Report volume removal and attachment events

    eisnerd committed
    on Windows, as volume.removed and volume.added
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 0 deletions.
  1. +15 −0 modules/ti.UI/win/UserWindowWin.cpp
View
15 modules/ti.UI/win/UserWindowWin.cpp
@@ -23,6 +23,7 @@
#include <comutil.h>
#include <shellapi.h>
#include <shlobj.h>
+#include <dbt.h>
#include "MenuItemWin.h"
#include "MenuWin.h"
@@ -197,6 +198,20 @@ static LRESULT CALLBACK UserWindowWndProc(HWND hWnd, UINT message, WPARAM wParam
}
}
break;
+ case WM_DEVICECHANGE:
+ {
+ const char *evt = "volume.added";
+ switch(wParam)
+ {
+ case DBT_DEVICEREMOVECOMPLETE:
+ evt = "volume.removed";
+ case DBT_DEVICEARRIVAL:
+ PDEV_BROADCAST_HDR dev = (PDEV_BROADCAST_HDR)lParam;
+ if (dev->dbch_devicetype == DBT_DEVTYP_VOLUME)
+ GlobalObject::GetInstance()->FireEvent(evt);
+ }
+ }
+ break;
}
if (!handled)
Something went wrong with that request. Please try again.