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>
75 #include <nsComponentManagerUtils.h>
110 NS_ENSURE_ARG_POINTER(aRegistrar);
113 RegisterControllers(aRegistrar);
125 sbIPDMarshall::BeginMonitoring()
128 nsAutoMonitor mon(mMonitor);
134 ScanForConnectedDevices();
146 sbIPDMarshall::StopMonitoring()
149 nsAutoMonitor mon(mMonitor);
167 sbIPDMarshall::GetId(nsID** aId)
170 NS_ENSURE_ARG_POINTER(aId);
173 nsID* pId =
static_cast<nsID*
>(NS_Alloc(
sizeof(nsID)));
174 NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);
190 sbIPDMarshall::GetName(nsAString&
aName)
241 sbIPDMarshall::EventInitialize()
246 FIELD_LOG((
"1: sbIPDMarshall::InitializeHal\n"));
250 NS_ENSURE_TRUE(mSBLibHalCtx, NS_ERROR_OUT_OF_MEMORY);
252 NS_ENSURE_SUCCESS(rv, rv);
258 NS_ENSURE_SUCCESS(rv, rv);
260 NS_ENSURE_SUCCESS(rv, rv);
262 (HandleLibHalDevicePropertyModified);
263 NS_ENSURE_SUCCESS(rv, rv);
265 NS_ENSURE_SUCCESS(rv, rv);
276 sbIPDMarshall::EventFinalize()
281 mSBLibHalCtx = nsnull;
300 sbIPDMarshall::HandleLibHalDevicePropertyModified(LibHalContext* aLibHalCtx,
301 const char* aDeviceUDI,
303 dbus_bool_t aIsRemoved,
304 dbus_bool_t aIsAdded)
307 NS_ENSURE_TRUE(aLibHalCtx, );
308 NS_ENSURE_TRUE(aDeviceUDI, );
309 NS_ENSURE_TRUE(aKey, );
316 nsCAutoString deviceUDI;
317 deviceUDI = aDeviceUDI;
318 marshall->HandleLibHalDevicePropertyModified(deviceUDI,
324 void sbIPDMarshall::HandleLibHalDevicePropertyModified(nsACString& aDeviceUDI,
326 dbus_bool_t aIsRemoved,
327 dbus_bool_t aIsAdded)
330 if (!strcmp(aKey,
"volume.is_mounted")) {
331 ProbeDev(aDeviceUDI);
346 sbIPDMarshall::HandleLibHalDeviceRemoved(LibHalContext* aLibHalCtx,
347 const char* aDeviceUDI)
350 NS_ENSURE_TRUE(aLibHalCtx, );
351 NS_ENSURE_TRUE(aDeviceUDI, );
358 nsCAutoString deviceUDI;
359 deviceUDI = aDeviceUDI;
360 marshall->HandleLibHalDeviceRemoved(deviceUDI);
364 sbIPDMarshall::HandleLibHalDeviceRemoved(nsACString& aDeviceUDI)
367 FIELD_LOG((
"1: sbIPDMarshall::HandleLibHalDeviceRemoved %s\n",
368 aDeviceUDI.BeginReading()));
376 if (!mDeviceMediaPartitionTable.Get(aDeviceUDI, &iPodUDI))
380 FIELD_LOG((
"2: sbIPDMarshall::HandleLibHalDeviceRemoved %s\n",
384 HandleRemovedEvent(*iPodUDI, aDeviceUDI);
397 sbIPDMarshall::HandleAddedEvent(
const nsACString& aDeviceUDI,
398 const nsACString& aMediaPartitionUDI)
403 nsAutoMonitor mon(mMonitor);
406 FIELD_LOG((
"Enter: HandleAddedEvent device=%s media partition=%s\n",
407 aDeviceUDI.BeginReading(),
408 aMediaPartitionUDI.BeginReading()));
411 nsCOMPtr<sbIDevice> device;
412 if (mDeviceList.Get(aDeviceUDI, getter_AddRefs(device)))
416 nsCOMPtr<nsIWritablePropertyBag>
417 propBag = do_CreateInstance(
"@mozilla.org/hash-property-bag;1", &rv);
418 NS_ENSURE_SUCCESS(rv, );
419 rv = propBag->SetProperty(NS_LITERAL_STRING(
"DeviceType"),
421 NS_ENSURE_SUCCESS(rv, );
422 rv = propBag->SetProperty(NS_LITERAL_STRING(
"DeviceUDI"),
424 NS_ENSURE_SUCCESS(rv, );
425 rv = propBag->SetProperty(NS_LITERAL_STRING(
"MediaPartitionUDI"),
427 NS_ENSURE_SUCCESS(rv, );
435 rv = controller->CreateDevice(propBag, getter_AddRefs(device));
436 NS_ENSURE_SUCCESS(rv, );
439 rv = mDeviceRegistrar->RegisterDevice(device);
440 NS_ENSURE_SUCCESS(rv, );
443 mDeviceList.Put(aDeviceUDI, device);
444 mDeviceMediaPartitionTable.Put(aMediaPartitionUDI,
new nsCString(aDeviceUDI));
462 sbIPDMarshall::HandleRemovedEvent(
const nsACString& aDeviceUDI,
463 const nsACString& aMediaPartitionUDI)
468 nsAutoMonitor mon(mMonitor);
471 nsCOMPtr<sbIDevice> device;
472 if (!mDeviceList.Get(aDeviceUDI, getter_AddRefs(device)))
476 FIELD_LOG((
"Enter: HandleRemovedEvent %s\n", nsCString(aDeviceUDI).
get()));
479 nsCOMPtr<sbIDeviceRegistrar> deviceRegistrar =
480 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
481 NS_ENSURE_SUCCESS(rv, );
482 nsCOMPtr<sbIDeviceControllerRegistrar> deviceControllerRegistrar =
483 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
484 NS_ENSURE_SUCCESS(rv, );
487 nsID *controllerID = nsnull;
488 rv = device->GetControllerId(&controllerID);
492 nsCOMPtr<sbIDeviceController> deviceController;
493 if (NS_SUCCEEDED(rv)) {
494 rv = deviceControllerRegistrar->GetController
496 getter_AddRefs(deviceController));
499 NS_WARNING(
"Failed to get device controller.");
500 deviceController = nsnull;
504 if (deviceController) {
505 rv = deviceController->ReleaseDevice(device);
507 NS_WARNING(
"Failed to release device.");
511 rv = deviceRegistrar->UnregisterDevice(device);
513 NS_WARNING(
"Failed to unregister device.");
517 mDeviceList.Remove(aDeviceUDI);
518 mDeviceMediaPartitionTable.Remove(aMediaPartitionUDI);
538 sbIPDMarshall::Initialize()
544 mMonitor = nsAutoMonitor::NewMonitor(
"sbIPDMarshall.mMonitor");
545 NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
548 mDeviceManager = do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2",
550 NS_ENSURE_SUCCESS(rv, rv);
551 mDeviceRegistrar = do_QueryInterface(mDeviceManager, &rv);
552 NS_ENSURE_SUCCESS(rv, rv);
555 success = mDeviceList.Init();
556 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
559 success = mDeviceMediaPartitionTable.Init();
560 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
571 sbIPDMarshall::Finalize()
576 nsAutoMonitor::DestroyMonitor(mMonitor);
581 mDeviceManager = nsnull;
582 mDeviceRegistrar = nsnull;
591 sbIPDMarshall::ScanForConnectedDevices()
593 nsCStringArray deviceList;
601 NS_ENSURE_SUCCESS(rv, rv);
602 for (i = 0; i < deviceList.Count(); i++)
605 deviceUDI = *(deviceList[
i]);
624 sbIPDMarshall::ProbeDev(nsACString &aProbeUDI)
629 FIELD_LOG((
"ProbeDev aProbeUDI=%s\n", aProbeUDI.BeginReading()));
632 nsCAutoString mediaPartitionUDI;
633 if (!IsMediaPartition(aProbeUDI))
635 mediaPartitionUDI = aProbeUDI;
638 nsCAutoString mountPoint;
640 "volume.mount_point",
642 if (NS_FAILED(rv) || mountPoint.IsEmpty()) {
647 nsCAutoString parentUDI;
653 FIELD_LOG((
"ProbeDev parentUDI=%s\n", parentUDI.get()));
656 nsCAutoString iPodUDI;
657 if (!IsIPod(parentUDI))
662 HandleAddedEvent(iPodUDI, mediaPartitionUDI);
678 sbIPDMarshall::IsIPod(nsACString& aDeviceUDI)
683 FIELD_LOG((
"1: sbIPDMarshall::IsIPod %s\n", aDeviceUDI.BeginReading()));
686 nsCAutoString vendor;
687 nsCAutoString product;
698 FIELD_LOG((
"2: sbIPDMarshall::IsIPod vendor=%s product=%s\n",
703 if (!vendor.Equals(
"Apple") || !product.Equals(
"iPod"))
721 sbIPDMarshall::IsMediaPartition(nsACString& aDeviceUDI)
728 "org.freedesktop.Hal.Device.Volume",
730 NS_ENSURE_SUCCESS(rv, rv);
738 sbIPDMarshall::RemoveDevice(
sbIDevice* aDevice)
740 return NS_ERROR_NOT_IMPLEMENTED;
nsresult SetDevicePropertyModified(LibHalDevicePropertyModified aCallback)
nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType, nsIVariant *aData, nsISupports *aOrigin, PRUint32 aDeviceState, PRBool aAsync)
Songbird iPod Device Utility Definitions.
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEMARSHALL NS_DECL_NSICLASSINFO sbIPDMarshall()
nsresult GetAllDevices(nsCStringArray &aDeviceList)
nsresult DeviceHasInterface(const nsACString &aUDI, const char *aInterface, PRBool *aHasInterface)
const unsigned long EVENT_DEVICE_ADDED
nsresult DevicePropertyWatchAll()
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
nsresult SetDeviceRemoved(LibHalDeviceRemoved aCallback)
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
nsresult SetUserData(void *aUserData)
#define SB_DEVICE_CONTROLLER_CATEGORY
readonly attribute nsIDPtr id
_getSelectedPageStyle s i
nsresult DeviceGetPropertyString(const nsACString &aUDI, const char *aKey, nsCString &aProperty)
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(CDatabaseQuery, sbIDatabaseQuery) CDatabaseQuery