- add patch for udisks and upower support (goes to upstream)
This commit is contained in:
Stephan Raue 2010-04-26 00:08:33 +02:00
parent 7eb68d8382
commit 9c373610a6

View File

@ -0,0 +1,734 @@
diff -Naur xbmc-29490/xbmc/linux/ConsoleUPowerSyscall.cpp xbmc-29490.patch/xbmc/linux/ConsoleUPowerSyscall.cpp
--- xbmc-29490/xbmc/linux/ConsoleUPowerSyscall.cpp 1970-01-01 01:00:00.000000000 +0100
+++ xbmc-29490.patch/xbmc/linux/ConsoleUPowerSyscall.cpp 2010-04-25 23:12:52.124485047 +0200
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "system.h"
+#include "ConsoleUPowerSyscall.h"
+#include "utils/log.h"
+
+#ifdef HAS_DBUS
+#include "Application.h"
+#include "LocalizeStrings.h"
+#include "DBusUtil.h"
+
+CConsoleUPowerSyscall::CConsoleUPowerSyscall()
+{
+ m_CanPowerdown = ConsoleKitMethodCall("CanStop");
+
+ // If "the name org.freedesktop.UPower was not provided by any .service files",
+ // GetVariant() would return NULL, and asBoolean() would crash.
+ CVariant canSuspend = CDBusUtil::GetVariant("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "can_suspend");
+
+ if ( !canSuspend.isNull() )
+ m_CanSuspend = canSuspend.asBoolean();
+ else
+ m_CanSuspend = false;
+
+ CVariant canHibernate = CDBusUtil::GetVariant("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "can_hibernate");
+
+ if ( !canHibernate.isNull() )
+ m_CanHibernate = canHibernate.asBoolean();
+ else
+ m_CanHibernate = false;
+
+ m_CanReboot = ConsoleKitMethodCall("CanRestart");
+}
+
+bool CConsoleUPowerSyscall::Powerdown()
+{
+ CDBusMessage message("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "Stop");
+ return message.SendSystem() != NULL;
+}
+
+bool CConsoleUPowerSyscall::Suspend()
+{
+ CDBusMessage message("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "Suspend");
+ return message.SendSystem() != NULL;
+}
+
+bool CConsoleUPowerSyscall::Hibernate()
+{
+ CDBusMessage message("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "Hibernate");
+ return message.SendSystem() != NULL;
+}
+
+bool CConsoleUPowerSyscall::Reboot()
+{
+ CDBusMessage message("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "Restart");
+ return message.SendSystem() != NULL;
+}
+
+bool CConsoleUPowerSyscall::CanPowerdown()
+{
+ return m_CanPowerdown;
+}
+bool CConsoleUPowerSyscall::CanSuspend()
+{
+ return m_CanSuspend;
+}
+bool CConsoleUPowerSyscall::CanHibernate()
+{
+ return m_CanHibernate;
+}
+bool CConsoleUPowerSyscall::CanReboot()
+{
+ return m_CanReboot;
+}
+
+bool CConsoleUPowerSyscall::HasDeviceConsoleKit()
+{
+ bool hasConsoleKitManager = false;
+ CDBusMessage consoleKitMessage("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "CanStop");
+
+ DBusError error;
+ dbus_error_init (&error);
+ DBusConnection *con = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+
+ consoleKitMessage.Send(con, &error);
+
+ if (!dbus_error_is_set(&error))
+ hasConsoleKitManager = true;
+ else
+ CLog::Log(LOGDEBUG, "ConsoleKit.Manager: %s - %s", error.name, error.message);
+
+ dbus_error_free (&error);
+
+ bool hasUPower = false;
+ CDBusMessage deviceKitMessage("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices");
+
+ deviceKitMessage.Send(con, &error);
+
+ if (!dbus_error_is_set(&error))
+ hasUPower = true;
+ else
+ CLog::Log(LOGDEBUG, "UPower: %s - %s", error.name, error.message);
+
+ dbus_error_free (&error);
+ dbus_connection_unref(con);
+
+ return hasUPower && hasConsoleKitManager;
+}
+
+bool CConsoleUPowerSyscall::ConsoleKitMethodCall(const char *method)
+{
+ CDBusMessage message("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", method);
+ DBusMessage *reply = message.SendSystem();
+ if (reply)
+ {
+ dbus_bool_t boolean = FALSE;
+
+ if (dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &boolean, DBUS_TYPE_INVALID))
+ return boolean;
+ }
+
+ return false;
+}
+#endif
diff -Naur xbmc-29490/xbmc/linux/ConsoleUPowerSyscall.h xbmc-29490.patch/xbmc/linux/ConsoleUPowerSyscall.h
--- xbmc-29490/xbmc/linux/ConsoleUPowerSyscall.h 1970-01-01 01:00:00.000000000 +0100
+++ xbmc-29490.patch/xbmc/linux/ConsoleUPowerSyscall.h 2010-04-25 23:12:52.125484748 +0200
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifdef HAS_DBUS
+#include "IPowerSyscall.h"
+
+class CConsoleUPowerSyscall : public IPowerSyscall
+{
+public:
+ CConsoleUPowerSyscall();
+ virtual ~CConsoleUPowerSyscall() { }
+
+ virtual bool Powerdown();
+ virtual bool Suspend();
+ virtual bool Hibernate();
+ virtual bool Reboot();
+
+ virtual bool CanPowerdown();
+ virtual bool CanSuspend();
+ virtual bool CanHibernate();
+ virtual bool CanReboot();
+
+ static bool HasDeviceConsoleKit();
+private:
+ static bool ConsoleKitMethodCall(const char *method);
+
+ bool m_CanPowerdown;
+ bool m_CanSuspend;
+ bool m_CanHibernate;
+ bool m_CanReboot;
+};
+#endif
diff -Naur xbmc-29490/xbmc/linux/LinuxStorageProvider.h xbmc-29490.patch/xbmc/linux/LinuxStorageProvider.h
--- xbmc-29490/xbmc/linux/LinuxStorageProvider.h 2010-04-24 22:43:12.000000000 +0200
+++ xbmc-29490.patch/xbmc/linux/LinuxStorageProvider.h 2010-04-25 23:12:52.126484868 +0200
@@ -22,6 +22,7 @@
#include "IStorageProvider.h"
#include "HALProvider.h"
#include "DeviceKitDisksProvider.h"
+#include "UDisksProvider.h"
#include "PosixMountProvider.h"
class CLinuxStorageProvider : public IStorageProvider
@@ -32,7 +33,9 @@
m_instance = NULL;
#ifdef HAS_DBUS
- if (CDeviceKitDisksProvider::HasDeviceKitDisks())
+ if (CUDisksProvider::HasUDisks() ) {
+ m_instance = new CUDisksProvider();
+ } else if (CDeviceKitDisksProvider::HasDeviceKitDisks())
m_instance = new CDeviceKitDisksProvider();
#endif
#ifdef HAS_HAL
diff -Naur xbmc-29490/xbmc/linux/Makefile.in xbmc-29490.patch/xbmc/linux/Makefile.in
--- xbmc-29490/xbmc/linux/Makefile.in 2010-04-24 22:43:12.000000000 +0200
+++ xbmc-29490.patch/xbmc/linux/Makefile.in 2010-04-25 23:12:52.127484639 +0200
@@ -7,7 +7,7 @@
CXXFLAGS+=-fPIC #-DHAS_SDL
-SRCS=ConvUtils.cpp XEventUtils.cpp XFileUtils.cpp XHandle.cpp XSyncUtils.cpp XTimeUtils.cpp XMemUtils.cpp XThreadUtils.cpp NetworkLinux.cpp LinuxResourceCounter.cpp LinuxTimezone.cpp XRandR.cpp XCriticalSection.cpp XLCDproc.cpp HALManager.cpp HALPowerSyscall.cpp ConsoleDeviceKitPowerSyscall.cpp DBusUtil.cpp DBusMessage.cpp ZeroconfAvahi.cpp ZeroconfBrowserAvahi.cpp HALProvider.cpp PosixMountProvider.cpp DeviceKitDisksProvider.cpp
+SRCS=ConvUtils.cpp XEventUtils.cpp XFileUtils.cpp XHandle.cpp XSyncUtils.cpp XTimeUtils.cpp XMemUtils.cpp XThreadUtils.cpp NetworkLinux.cpp LinuxResourceCounter.cpp LinuxTimezone.cpp XRandR.cpp XCriticalSection.cpp XLCDproc.cpp HALManager.cpp HALPowerSyscall.cpp ConsoleDeviceKitPowerSyscall.cpp DBusUtil.cpp DBusMessage.cpp ZeroconfAvahi.cpp ZeroconfBrowserAvahi.cpp HALProvider.cpp PosixMountProvider.cpp DeviceKitDisksProvider.cpp UDisksProvider.cpp ConsoleUPowerSyscall.cpp
LIB=linux.a
diff -Naur xbmc-29490/xbmc/linux/UDisksProvider.cpp xbmc-29490.patch/xbmc/linux/UDisksProvider.cpp
--- xbmc-29490/xbmc/linux/UDisksProvider.cpp 1970-01-01 01:00:00.000000000 +0100
+++ xbmc-29490.patch/xbmc/linux/UDisksProvider.cpp 2010-04-25 23:12:52.129484321 +0200
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+#include "UDisksProvider.h"
+#ifdef HAS_DBUS
+#include "Util.h"
+#include "AdvancedSettings.h"
+#include "LocalizeStrings.h"
+#include "log.h"
+
+CUDiskDevice::CUDiskDevice(const char *DeviceKitUDI)
+{
+ m_DeviceKitUDI = DeviceKitUDI;
+ m_UDI = "";
+ m_MountPath = "";
+ m_FileSystem = "";
+ m_isMounted = false;
+ m_isMountedByUs = false;
+ m_isRemovable = false;
+ m_isPartition = false;
+ m_isFileSystem = false;
+ m_isSystemInternal = false;
+ m_PartitionSizeGiB = 0.0f;
+ Update();
+}
+
+void CUDiskDevice::Update()
+{
+ CStdString str = CDBusUtil::GetVariant("org.freedesktop.UDisks", m_DeviceKitUDI.c_str(), "org.freedesktop.UDisks.Device", "IdUsage").asString();
+ m_isFileSystem = str.Equals("filesystem");
+ if (m_isFileSystem)
+ {
+ CVariant properties = CDBusUtil::GetAll("org.freedesktop.UDisks", m_DeviceKitUDI.c_str(), "org.freedesktop.UDisks.Device");
+
+ m_UDI = properties["IdUuid"].asString();
+ m_Label = properties["IdLabel"].asString();
+ m_FileSystem = properties["IdType"].asString();
+ if (properties["DeviceMountPaths"].size() > 0)
+ m_MountPath = properties["DeviceMountPaths"][0].asString();
+ m_isMounted = properties["DeviceIsMounted"].asBoolean();
+
+ m_PartitionSizeGiB = properties["PartitionSize"].asUnsignedInteger() / 1024.0 / 1024.0 / 1024.0;
+ m_isPartition = properties["DeviceIsPartition"].asBoolean();
+ m_isSystemInternal = properties["DeviceIsSystemInternal"].asBoolean();
+ if (m_isPartition)
+ {
+ CVariant isRemovable = CDBusUtil::GetVariant("org.freedesktop.UDisks", properties["PartitionSlave"].asString(), "org.freedesktop.UDisks.Device", "DeviceIsRemovable");
+
+ if ( !isRemovable.isNull() )
+ m_isRemovable = isRemovable.asBoolean();
+ else
+ m_isRemovable = false;
+ }
+ else
+ m_isRemovable = properties["DeviceIsRemovable"].asBoolean();
+ }
+}
+
+bool CUDiskDevice::Mount()
+{
+ if (!m_isMounted && !m_isSystemInternal && m_isFileSystem)
+ {
+ CLog::Log(LOGDEBUG, "UDisks: Mounting %s", m_DeviceKitUDI.c_str());
+ CDBusMessage message("org.freedesktop.UDisks", m_DeviceKitUDI.c_str(), "org.freedesktop.UDisks.Device", "FilesystemMount");
+ message.AppendArgument("");
+ const char *array[] = {};
+ message.AppendArgument(array, 0);
+
+ DBusMessage *reply = message.SendSystem();
+ if (reply)
+ {
+ char *mountPoint;
+ if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &mountPoint, DBUS_TYPE_INVALID))
+ {
+ m_MountPath = mountPoint;
+ CLog::Log(LOGDEBUG, "UDisks: Sucessfully mounted %s on %s", m_DeviceKitUDI.c_str(), mountPoint);
+ m_isMountedByUs = m_isMounted = true;
+ }
+ }
+
+ return m_isMounted;
+ }
+ else
+ CLog::Log(LOGDEBUG, "UDisks: Is not able to mount %s", toString().c_str());
+
+ return false;
+}
+
+bool CUDiskDevice::UnMount()
+{
+ if (m_isMounted && !m_isSystemInternal && m_isFileSystem)
+ {
+ CDBusMessage message("org.freedesktop.UDisks", m_DeviceKitUDI.c_str(), "org.freedesktop.UDisks.Device", "FilesystemUnmount");
+
+ const char *array[1];
+ message.AppendArgument(array, 0);
+
+ DBusMessage *reply = message.SendSystem();
+ if (reply)
+ m_isMountedByUs = m_isMounted = false;
+
+ return !m_isMounted;
+ }
+ else
+ CLog::Log(LOGDEBUG, "UDisks: Is not able to unmount %s", toString().c_str());
+
+ return false;
+}
+
+CMediaSource CUDiskDevice::ToMediaShare()
+{
+ CMediaSource source;
+ source.strPath = m_MountPath;
+ if (m_Label.empty())
+ source.strName.Format("%.1f GB %s", m_PartitionSizeGiB, g_localizeStrings.Get(155).c_str());
+ else
+ source.strName = m_Label;
+ source.m_iDriveType = !m_isSystemInternal ? CMediaSource::SOURCE_TYPE_REMOVABLE : CMediaSource::SOURCE_TYPE_LOCAL;
+ source.m_ignore = true;
+ return source;
+}
+
+bool CUDiskDevice::IsApproved()
+{
+ return (m_isFileSystem && m_isMounted && m_UDI.length() > 0 && (m_FileSystem.length() > 0 && !m_FileSystem.Equals("swap")) && !m_MountPath.Equals("/"));
+}
+
+#define BOOL2SZ(b) ((b) ? "true" : "false")
+
+CStdString CUDiskDevice::toString()
+{
+ CStdString str;
+ str.Format("DeviceUDI %s: IsFileSystem %s HasFileSystem %s "
+ "IsSystemInternal %s IsMounted %s IsRemovable %s IsPartition %s",
+ m_DeviceKitUDI.c_str(), BOOL2SZ(m_isFileSystem), m_FileSystem,
+ BOOL2SZ(m_isSystemInternal), BOOL2SZ(m_isMounted),
+ BOOL2SZ(m_isRemovable), BOOL2SZ(m_isPartition));
+
+ return str;
+}
+
+CUDisksProvider::CUDisksProvider()
+{
+ dbus_error_init (&m_error);
+ m_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &m_error);
+
+ dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.UDisks'", &m_error);
+ dbus_connection_flush(m_connection);
+ if (dbus_error_is_set(&m_error))
+ {
+ CLog::Log(LOGERROR, "UDisks: Failed to attach to signal %s", m_error.message);
+ dbus_connection_unref(m_connection);
+ m_connection = NULL;
+ }
+}
+
+CUDisksProvider::~CUDisksProvider()
+{
+ DeviceMap::iterator itr;
+
+ for (itr = m_AvailableDevices.begin(); itr != m_AvailableDevices.end(); ++itr)
+ delete m_AvailableDevices[itr->first];
+
+ m_AvailableDevices.clear();
+
+ if (m_connection)
+ {
+ dbus_connection_unref(m_connection);
+ m_connection = NULL;
+ }
+
+ dbus_error_free (&m_error);
+}
+
+void CUDisksProvider::Initialize()
+{
+ CLog::Log(LOGDEBUG, "Selected UDisks as storage provider");
+ m_DaemonVersion = atoi(CDBusUtil::GetVariant("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DaemonVersion").asString());
+ CLog::Log(LOGDEBUG, "UDisks: DaemonVersion %i", m_DaemonVersion);
+
+ CLog::Log(LOGDEBUG, "UDisks: Querying available devices");
+ std::vector<CStdString> devices = EnumerateDisks();
+ for (unsigned int i = 0; i < devices.size(); i++)
+ DeviceAdded(devices[i].c_str(), NULL);
+}
+
+bool CUDisksProvider::Eject(CStdString mountpath)
+{
+ DeviceMap::iterator itr;
+ CStdString path(mountpath);
+ CUtil::RemoveSlashAtEnd(path);
+
+ for (itr = m_AvailableDevices.begin(); itr != m_AvailableDevices.end(); ++itr)
+ {
+ CUDiskDevice *device = itr->second;
+ if (device->m_MountPath.Equals(path))
+ return device->UnMount();
+ }
+
+ return false;
+}
+
+std::vector<CStdString> CUDisksProvider::GetDiskUsage()
+{
+ std::vector<CStdString> devices;
+ DeviceMap::iterator itr;
+
+ for(itr = m_AvailableDevices.begin(); itr != m_AvailableDevices.end(); ++itr)
+ {
+ CUDiskDevice *device = itr->second;
+ if (device->IsApproved())
+ {
+ CStdString str;
+ str.Format("%s %.1f GiB", device->m_MountPath.c_str(), device->m_PartitionSizeGiB);
+ devices.push_back(str);
+ }
+ }
+
+ return devices;
+}
+
+bool CUDisksProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
+{
+ bool result = false;
+ if (m_connection)
+ {
+ dbus_connection_read_write(m_connection, 0);
+ DBusMessage *msg = dbus_connection_pop_message(m_connection);
+
+ if (msg)
+ {
+ char *object;
+ if (dbus_message_get_args (msg, NULL, DBUS_TYPE_OBJECT_PATH, &object, DBUS_TYPE_INVALID))
+ {
+ result = true;
+ if (dbus_message_is_signal(msg, "org.freedesktop.UDisks", "DeviceAdded"))
+ DeviceAdded(object, callback);
+ else if (dbus_message_is_signal(msg, "org.freedesktop.UDisks", "DeviceRemoved"))
+ DeviceRemoved(object, callback);
+ else if (dbus_message_is_signal(msg, "org.freedesktop.UDisks", "DeviceChanged"))
+ DeviceChanged(object, callback);
+ }
+ dbus_message_unref(msg);
+ }
+ }
+ return result;
+}
+
+bool CUDisksProvider::HasUDisks()
+{
+ bool hasUDisks = false;
+ CDBusMessage message("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices");
+
+ DBusError error;
+ dbus_error_init (&error);
+ DBusConnection *con = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+
+ message.Send(con, &error);
+
+ if (!dbus_error_is_set(&error))
+ hasUDisks = true;
+ else
+ CLog::Log(LOGDEBUG, "UDisks: %s - %s", error.name, error.message);
+
+ dbus_error_free (&error);
+ dbus_connection_unref(con);
+
+ return hasUDisks;
+}
+
+void CUDisksProvider::DeviceAdded(const char *object, IStorageEventsCallback *callback)
+{
+ CLog::Log(LOGDEBUG, "UDisks: DeviceAdded (%s)", object);
+
+ if (m_AvailableDevices[object])
+ {
+ CLog::Log(LOGWARNING, "UDisks: Inconsistency found! DeviceAdded on an indexed disk");
+ delete m_AvailableDevices[object];
+ }
+
+ CUDiskDevice *device = NULL;
+ device = new CUDiskDevice(object);
+ m_AvailableDevices[object] = device;
+
+ if (g_advancedSettings.m_handleMounting)
+ device->Mount();
+
+ CLog::Log(LOGDEBUG, "UDisks: DeviceAdded - %s", device->toString().c_str());
+ if (device->m_isMounted && device->IsApproved())
+ {
+ CLog::Log(LOGNOTICE, "UDisks: Added %s", device->m_MountPath.c_str());
+ if (callback)
+ callback->OnStorageAdded(device->m_Label, device->m_MountPath);
+ }
+}
+
+void CUDisksProvider::DeviceRemoved(const char *object, IStorageEventsCallback *callback)
+{
+ CLog::Log(LOGDEBUG, "UDisks: DeviceRemoved (%s)", object);
+
+ CUDiskDevice *device = m_AvailableDevices[object];
+ if (device)
+ {
+ if (device->m_isMounted && callback)
+ callback->OnStorageUnsafelyRemoved(device->m_Label);
+
+ delete m_AvailableDevices[object];
+ m_AvailableDevices.erase(object);
+ }
+}
+
+void CUDisksProvider::DeviceChanged(const char *object, IStorageEventsCallback *callback)
+{
+ CLog::Log(LOGDEBUG, "UDisks: DeviceChanged (%s)", object);
+
+ CUDiskDevice *device = m_AvailableDevices[object];
+ if (device == NULL)
+ {
+ CLog::Log(LOGWARNING, "UDisks: Inconsistency found! DeviceChanged on an unindexed disk");
+ DeviceAdded(object, callback);
+ }
+ else
+ {
+ bool mounted = device->m_isMounted;
+ device->Update();
+ if (!mounted && device->m_isMounted && callback)
+ callback->OnStorageAdded(device->m_MountPath, device->m_Label);
+ else if (mounted && !device->m_isMounted && callback)
+ callback->OnStorageSafelyRemoved(device->m_Label);
+
+ CLog::Log(LOGDEBUG, "UDisks: DeviceChanged - %s", device->toString().c_str());
+ }
+}
+
+std::vector<CStdString> CUDisksProvider::EnumerateDisks()
+{
+ std::vector<CStdString> devices;
+ CDBusMessage message("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices");
+ DBusMessage *reply = message.SendSystem();
+ if (reply)
+ {
+ char** disks = NULL;
+ int length = 0;
+
+ if (dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &disks, &length, DBUS_TYPE_INVALID))
+ {
+ for (int i = 0; i < length; i++)
+ devices.push_back(disks[i]);
+
+ dbus_free_string_array(disks);
+ }
+ }
+
+ return devices;
+}
+
+void CUDisksProvider::GetDisks(VECSOURCES& devices, bool EnumerateRemovable)
+{
+ DeviceMap::iterator itr;
+
+ for (itr = m_AvailableDevices.begin(); itr != m_AvailableDevices.end(); ++itr)
+ {
+ CUDiskDevice *device = itr->second;
+ if (device && device->IsApproved() && device->m_isSystemInternal != EnumerateRemovable)
+ devices.push_back(device->ToMediaShare());
+ }
+}
+#endif
diff -Naur xbmc-29490/xbmc/linux/UDisksProvider.h xbmc-29490.patch/xbmc/linux/UDisksProvider.h
--- xbmc-29490/xbmc/linux/UDisksProvider.h 1970-01-01 01:00:00.000000000 +0100
+++ xbmc-29490.patch/xbmc/linux/UDisksProvider.h 2010-04-25 23:12:52.130485628 +0200
@@ -0,0 +1,86 @@
+#pragma once
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+#include "IStorageProvider.h"
+#ifdef HAS_DBUS
+#include "DBusUtil.h"
+
+class CUDiskDevice
+{
+public:
+ CUDiskDevice(const char *DeviceKitUDI);
+ ~CUDiskDevice() { }
+
+ void Update();
+
+ bool Mount();
+ bool UnMount();
+
+ bool IsApproved();
+
+ CStdString toString();
+
+ CMediaSource ToMediaShare();
+
+ CStdString m_UDI, m_DeviceKitUDI, m_MountPath, m_FileSystem, m_Label;
+ bool m_isMounted, m_isMountedByUs, m_isRemovable, m_isPartition, m_isFileSystem, m_isSystemInternal;
+ float m_PartitionSizeGiB;
+};
+
+class CUDisksProvider : public IStorageProvider
+{
+public:
+ CUDisksProvider();
+ virtual ~CUDisksProvider();
+
+ virtual void Initialize();
+ virtual void Stop() { }
+
+ virtual void GetLocalDrives(VECSOURCES &localDrives) { GetDisks(localDrives, false); }
+ virtual void GetRemovableDrives(VECSOURCES &removableDrives) { GetDisks(removableDrives, true); }
+
+ virtual bool Eject(CStdString mountpath);
+
+ virtual std::vector<CStdString> GetDiskUsage();
+
+ virtual bool PumpDriveChangeEvents(IStorageEventsCallback *callback);
+
+ static bool HasUDisks();
+private:
+ typedef std::map<CStdString, CUDiskDevice *> DeviceMap;
+ typedef std::pair<CStdString, CUDiskDevice *> DevicePair;
+
+ void DeviceAdded(const char *object, IStorageEventsCallback *callback);
+ void DeviceRemoved(const char *object, IStorageEventsCallback *callback);
+ void DeviceChanged(const char *object, IStorageEventsCallback *callback);
+
+ std::vector<CStdString> EnumerateDisks();
+
+ void GetDisks(VECSOURCES& devices, bool EnumerateRemovable);
+
+ int m_DaemonVersion;
+
+ DeviceMap m_AvailableDevices;
+
+ DBusConnection *m_connection;
+ DBusError m_error;
+};
+#endif
diff -Naur xbmc-29490/xbmc/PowerManager.cpp xbmc-29490.patch/xbmc/PowerManager.cpp
--- xbmc-29490/xbmc/PowerManager.cpp 2010-04-24 22:43:14.000000000 +0200
+++ xbmc-29490.patch/xbmc/PowerManager.cpp 2010-04-25 23:12:52.132484681 +0200
@@ -35,6 +35,7 @@
#ifdef __APPLE__
#include "osx/CocoaPowerSyscall.h"
#elif defined(_LINUX) && defined(HAS_DBUS)
+#include "linux/ConsoleUPowerSyscall.h"
#include "linux/ConsoleDeviceKitPowerSyscall.h"
#ifdef HAS_HAL
#include "linux/HALPowerSyscall.h"
@@ -74,6 +75,8 @@
#elif defined(_LINUX) && defined(HAS_DBUS)
if (CConsoleDeviceKitPowerSyscall::HasDeviceConsoleKit())
m_instance = new CConsoleDeviceKitPowerSyscall();
+ else if (CConsoleUPowerSyscall::HasDeviceConsoleKit())
+ m_instance = new CConsoleUPowerSyscall();
#ifdef HAS_HAL
else
m_instance = new CHALPowerSyscall();