64 #include <sbIDevice.h>
65 #include <sbIDeviceController.h>
66 #include <sbIDeviceControllerRegistrar.h>
67 #include <sbIDeviceEvent.h>
70 #include <nsIClassInfoImpl.h>
71 #include <nsIProgrammingLanguage.h>
72 #include <nsIWritablePropertyBag.h>
74 #include <nsServiceManagerUtils.h>
120 NS_ENSURE_ARG_POINTER(aRegistrar);
123 RegisterControllers(aRegistrar);
135 sbIPDMarshall::BeginMonitoring()
138 nsAutoMonitor mon(mMonitor);
144 ScanForConnectedDevices();
156 sbIPDMarshall::StopMonitoring()
159 nsAutoMonitor mon(mMonitor);
177 sbIPDMarshall::GetId(nsID** aId)
180 NS_ENSURE_ARG_POINTER(aId);
183 nsID* pId =
static_cast<nsID*
>(NS_Alloc(
sizeof(nsID)));
184 NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);
200 sbIPDMarshall::GetName(nsAString&
aName)
219 mEventWindow((HWND) INVALID_HANDLE_VALUE),
220 mEventWindowClass(NULL)
252 sbIPDMarshall::EventInitialize()
256 ZeroMemory(&wndClass,
sizeof(wndClass));
257 wndClass.hInstance = GetModuleHandle(NULL);
258 wndClass.lpfnWndProc = WindowEventHandler;
260 mEventWindowClass = RegisterClass(&wndClass);
261 NS_ENSURE_TRUE(mEventWindowClass, NS_ERROR_UNEXPECTED);
264 mEventWindow = CreateWindow(MAKEINTATOM(mEventWindowClass),
273 GetModuleHandle(NULL),
275 NS_ENSURE_TRUE(mEventWindow != INVALID_HANDLE_VALUE, NS_ERROR_UNEXPECTED);
277 SetWindowLong(mEventWindow, GWL_USERDATA, (
LONG)
this);
278 NS_ENSURE_FALSE(GetLastError(), NS_ERROR_UNEXPECTED);
289 sbIPDMarshall::EventFinalize()
292 if (mEventWindow != INVALID_HANDLE_VALUE) {
293 DestroyWindow(mEventWindow);
294 mEventWindow = (HWND) INVALID_HANDLE_VALUE;
298 if (mEventWindowClass) {
299 UnregisterClass(MAKEINTATOM(mEventWindowClass), GetModuleHandle(NULL));
300 mEventWindowClass = NULL;
320 sbIPDMarshall::WindowEventHandler(HWND hwnd,
326 FIELD_LOG((
"Enter: sbIPDMarshall::WindowEventHandler\n"));
330 NS_ENSURE_TRUE(marshall, 1);
331 marshall->_WindowEventHandler(hwnd, msg, param1, param2);
334 FIELD_LOG((
"Exit: sbIPDMarshall::WindowEventHandler\n"));
340 sbIPDMarshall::_WindowEventHandler(HWND hwnd,
346 if (msg != WM_DEVICECHANGE)
350 PDEV_BROADCAST_HDR pDevBroadcastHdr = (PDEV_BROADCAST_HDR) param2;
351 if (!pDevBroadcastHdr)
353 if (pDevBroadcastHdr->dbch_devicetype != DBT_DEVTYP_VOLUME)
357 PDEV_BROADCAST_VOLUME pDevBroadcastVolume = (PDEV_BROADCAST_VOLUME) param2;
361 int unitmask = pDevBroadcastVolume->dbcv_unitmask;
362 for (driveLetter =
'A'; driveLetter <=
'Z'; driveLetter++) {
371 case DBT_DEVICEARRIVAL :
372 HandleAddedEvent(driveLetter);
375 case DBT_DEVICEREMOVECOMPLETE :
376 HandleRemovedEvent(driveLetter);
391 sbIPDMarshall::HandleAddedEvent(
char aDriveLetter)
393 nsCOMPtr<sbIDevice> device;
397 nsAutoMonitor mon(mMonitor);
400 if (!IsIPod(aDriveLetter))
404 FIELD_LOG((
"Enter: HandleAddedEvent %c\n", aDriveLetter));
407 if (mDeviceList.Get(aDriveLetter, getter_AddRefs(device)))
411 nsCOMPtr<nsIWritablePropertyBag>
412 propBag = do_CreateInstance(
"@mozilla.org/hash-property-bag;1", &rv);
413 NS_ENSURE_SUCCESS(rv, );
414 rv = propBag->SetProperty(NS_LITERAL_STRING(
"DeviceType"),
416 NS_ENSURE_SUCCESS(rv, );
417 rv = propBag->SetProperty(NS_LITERAL_STRING(
"DriveLetter"),
419 NS_ENSURE_SUCCESS(rv, );
427 rv = controller->CreateDevice(propBag, getter_AddRefs(device));
428 NS_ENSURE_SUCCESS(rv, );
431 rv = mDeviceRegistrar->RegisterDevice(device);
432 NS_ENSURE_SUCCESS(rv, );
435 mDeviceList.Put(aDriveLetter, device);
450 sbIPDMarshall::HandleRemovedEvent(
char aDriveLetter)
455 nsAutoMonitor mon(mMonitor);
458 nsCOMPtr<sbIDevice> device;
459 if (!mDeviceList.Get(aDriveLetter, getter_AddRefs(device)))
463 FIELD_LOG((
"Enter: HandleRemovedEvent %c\n", aDriveLetter));
466 nsCOMPtr<sbIDeviceRegistrar> deviceRegistrar =
467 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
468 NS_ENSURE_SUCCESS(rv, );
469 nsCOMPtr<sbIDeviceControllerRegistrar> deviceControllerRegistrar =
470 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
471 NS_ENSURE_SUCCESS(rv, );
474 nsID *controllerID = nsnull;
475 rv = device->GetControllerId(&controllerID);
479 nsCOMPtr<sbIDeviceController> deviceController;
480 if (NS_SUCCEEDED(rv)) {
481 rv = deviceControllerRegistrar->GetController
483 getter_AddRefs(deviceController));
486 NS_WARNING(
"Failed to get device controller.");
487 deviceController = nsnull;
491 if (deviceController) {
492 rv = deviceController->ReleaseDevice(device);
494 NS_WARNING(
"Failed to release device.");
498 rv = deviceRegistrar->UnregisterDevice(device);
500 NS_WARNING(
"Failed to unregister device.");
503 mDeviceList.Remove(aDriveLetter);
523 sbIPDMarshall::Initialize()
529 mMonitor = nsAutoMonitor::NewMonitor(
"sbIPDMarshall.mMonitor");
530 NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
533 mDeviceManager = do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2",
535 NS_ENSURE_SUCCESS(rv, rv);
536 mDeviceRegistrar = do_QueryInterface(mDeviceManager, &rv);
537 NS_ENSURE_SUCCESS(rv, rv);
540 success = mDeviceList.Init();
541 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
552 sbIPDMarshall::Finalize()
557 nsAutoMonitor::DestroyMonitor(mMonitor);
562 mDeviceManager = nsnull;
563 mDeviceRegistrar = nsnull;
572 sbIPDMarshall::ScanForConnectedDevices()
576 for (
char driveLetter =
'A'; driveLetter <=
'Z'; driveLetter++) {
577 HandleAddedEvent(driveLetter);
593 sbIPDMarshall::IsIPod(
char aDriveLetter)
595 PRBool isIPod = PR_FALSE;
600 PR_snprintf(devicePath,
sizeof(devicePath),
"\\\\.\\%c:", aDriveLetter);
603 FIELD_LOG((
"1: IsIPod %s\n", devicePath));
607 HANDLE hDev = CreateFileA(devicePath,
614 if (hDev == INVALID_HANDLE_VALUE)
616 sbAutoHANDLE autoHDev(hDev);
622 STORAGE_PROPERTY_QUERY query;
623 UCHAR queryData[512];
625 query.PropertyId = StorageDeviceProperty;
626 query.QueryType = PropertyStandardQuery;
627 success = DeviceIoControl(hDev,
628 IOCTL_STORAGE_QUERY_PROPERTY,
630 sizeof (STORAGE_PROPERTY_QUERY),
639 PSTORAGE_DEVICE_DESCRIPTOR pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR) queryData;
640 const char* vendorID = (
const char *) &(queryData[pDevDesc->VendorIdOffset]);
641 const char* productID =
642 (
const char *) &(queryData[pDevDesc->ProductIdOffset]);
645 FIELD_LOG((
"3: IsIPod \"%s\" \"%s\"\n", vendorID, productID));
649 if (strncmp(
"Apple", vendorID, strlen(
"Apple")))
651 else if (strncmp(
"iPod", productID, strlen(
"iPod")))
662 sbIPDMarshall::RemoveDevice(
sbIDevice* aDevice)
664 return NS_ERROR_NOT_IMPLEMENTED;
nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType, nsIVariant *aData, nsISupports *aOrigin, PRUint32 aDeviceState, PRBool aAsync)
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEMARSHALL NS_DECL_NSICLASSINFO sbIPDMarshall()
Songbird iPod Device Windows Utility Definitions.
const unsigned long EVENT_DEVICE_ADDED
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
sbIDeviceController * FindCompatibleControllers(nsIPropertyBag *deviceParams)
#define SB_IPDMARSHALL_CLASSNAME
Songbird iPod Device Logging Definitions.
const unsigned long EVENT_DEVICE_REMOVED
[UNIMPLEMENTED UNTIL AFTER 0.3]
#define SB_IPDMARSHALL_CID
#define SB_DEVICE_CONTROLLER_CATEGORY
readonly attribute nsIDPtr id
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(CDatabaseQuery, sbIDatabaseQuery) CDatabaseQuery