[podsleuth] Account for DeviceKit to UDisks rename
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [podsleuth] Account for DeviceKit to UDisks rename
- Date: Mon, 10 May 2010 19:46:53 +0000 (UTC)
commit 685125fdf0d2e349b9848bcc29134f008bca88f4
Author: Gabriel Burt <gabriel burt gmail com>
Date: Mon May 10 12:13:25 2010 -0700
Account for DeviceKit to UDisks rename
Fall back to DeviceKit if UDisks doesn't exist - is runtime compatible
with both setups.
src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs | 102 +++++++++++++++-----
1 files changed, 76 insertions(+), 26 deletions(-)
---
diff --git a/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs b/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs
index df09f60..9452dc3 100644
--- a/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs
+++ b/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs
@@ -39,13 +39,17 @@ namespace PodSleuth.HalFrontend
if (device_path == null)
return null;
- if (disks == null)
+ if (udisks_finder == null && dk_finder == null)
return null;
string disk_path = null;
try {
- disk_path = disks.FindDeviceByDeviceFile (device_path);
+ if (udisks_finder != null) {
+ disk_path = udisks_finder.FindDeviceByDeviceFile (device_path);
+ } else {
+ disk_path = dk_finder.FindDeviceByDeviceFile (device_path);
+ }
} catch {}
if (disk_path == null)
@@ -58,71 +62,117 @@ namespace PodSleuth.HalFrontend
return null;
}
- private IDkDisk disk;
+ private UDisksDisk udisks_disk;
+ private IDkDisk dk_disk;
private org.freedesktop.DBus.Properties props;
+ const string dk_bus_name = "org.freedesktop.DeviceKit.Disks";
+ const string udisks_bus_name = "org.freedesktop.UDisks";
+
private DkDisk (string obj_path)
{
- disk = Bus.System.GetObject<IDkDisk>("org.freedesktop.DeviceKit.Disks",
- new ObjectPath(obj_path));
-
- props = Bus.System.GetObject<org.freedesktop.DBus.Properties>("org.freedesktop.DeviceKit.Disks",
- new ObjectPath(obj_path));
+ if (udisks_finder != null) {
+ udisks_disk = Bus.System.GetObject<UDisksDisk> (udisks_bus_name, new ObjectPath (obj_path));
+ props = Bus.System.GetObject<org.freedesktop.DBus.Properties> (udisks_bus_name, new ObjectPath (obj_path));
+ } else {
+ dk_disk = Bus.System.GetObject<IDkDisk> (dk_bus_name, new ObjectPath(obj_path));
+ props = Bus.System.GetObject<org.freedesktop.DBus.Properties> (dk_bus_name, new ObjectPath(obj_path));
+ }
}
public bool IsMounted {
get {
- return (bool) props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceIsMounted");
+ return (bool) props.Get (props_iface, "DeviceIsMounted");
}
}
public bool IsReadOnly {
get {
- return (bool) props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceIsReadOnly");
+ return (bool) props.Get (props_iface, "DeviceIsReadOnly");
}
}
public string MountPoint {
get {
- var ary = (string[])props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceMountPaths");
+ var ary = (string[])props.Get (props_iface, "DeviceMountPaths");
return ary != null && ary.Length > 0 ? ary[0] : null;
}
}
public void Eject ()
{
- disk.DriveEject (new string [0]);
+ if (udisks_disk != null) {
+ udisks_disk.DriveEject (new string [0]);
+ } else {
+ dk_disk.DriveEject (new string [0]);
+ }
}
public void Unmount ()
{
- disk.FilesystemUnmount (new string [0]);
+ if (udisks_disk != null) {
+ udisks_disk.FilesystemUnmount (new string [0]);
+ } else {
+ dk_disk.FilesystemUnmount (new string [0]);
+ }
}
- private static IDkDisks disks;
+ private static UDisksFinder udisks_finder;
+ private static DkFinder dk_finder;
+ private static string props_iface;
static DkDisk ()
{
try {
- disks = Bus.System.GetObject<IDkDisks>("org.freedesktop.DeviceKit.Disks",
- new ObjectPath("/org/freedesktop/DeviceKit/Disks"));
- } catch {}
+ if (Bus.System.NameHasOwner (udisks_bus_name)) {
+ udisks_finder = Bus.System.GetObject<UDisksFinder>(udisks_bus_name, new ObjectPath("/org/freedesktop/UDisks"));
+ props_iface = "org.freedesktop.UDisks.Device";
+ }
+ } catch {
+ udisks_finder = null;
+ }
+
+ if (udisks_finder == null) {
+ try {
+ if (Bus.System.NameHasOwner (dk_bus_name)) {
+ dk_finder = Bus.System.GetObject<DkFinder>(dk_bus_name,
+ new ObjectPath("/org/freedesktop/DeviceKit/Disks"));
+ props_iface = "org.freedesktop.DeviceKit.Disks.Device";
+ }
+ } catch {
+ dk_finder = null;
+ }
+ }
+ }
+
+ [Interface("org.freedesktop.UDisks")]
+ internal interface UDisksFinder
+ {
+ string FindDeviceByDeviceFile (string deviceFile);
}
[Interface("org.freedesktop.DeviceKit.Disks")]
- internal interface IDkDisks
+ internal interface DkFinder
{
string FindDeviceByDeviceFile (string deviceFile);
}
- }
+ [Interface("org.freedesktop.UDisks.Device")]
+ internal interface UDisksDisk
+ {
+ bool DeviceIsMounted { get; }
+ string [] DeviceMountPaths { get; }
+ void DriveEject (string [] options);
+ void FilesystemUnmount (string [] options);
+ }
- [Interface("org.freedesktop.DeviceKit.Disks.Device")]
- public interface IDkDisk
- {
- bool DeviceIsMounted { get; }
- string [] DeviceMountPaths { get; }
- void DriveEject (string [] options);
- void FilesystemUnmount (string [] options);
+ [Interface("org.freedesktop.DeviceKit.Disks.Device")]
+ internal interface IDkDisk
+ {
+ bool DeviceIsMounted { get; }
+ string [] DeviceMountPaths { get; }
+ void DriveEject (string [] options);
+ void FilesystemUnmount (string [] options);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]