forked from DonVla/xbmc-svn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uthings.diff
734 lines (728 loc) · 24.1 KB
/
uthings.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
diff -Naur XBMC.orig//xbmc/linux/ConsoleUPowerSyscall.cpp XBMC/xbmc/linux/ConsoleUPowerSyscall.cpp
--- XBMC.orig//xbmc/linux/ConsoleUPowerSyscall.cpp 1970-01-01 01:00:00.000000000 +0100
+++ XBMC/xbmc/linux/ConsoleUPowerSyscall.cpp 2010-04-21 14:04:21.506684504 +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.orig//xbmc/linux/ConsoleUPowerSyscall.h XBMC/xbmc/linux/ConsoleUPowerSyscall.h
--- XBMC.orig//xbmc/linux/ConsoleUPowerSyscall.h 1970-01-01 01:00:00.000000000 +0100
+++ XBMC/xbmc/linux/ConsoleUPowerSyscall.h 2010-04-21 14:04:21.506684504 +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.orig//xbmc/linux/LinuxStorageProvider.h XBMC/xbmc/linux/LinuxStorageProvider.h
--- XBMC.orig//xbmc/linux/LinuxStorageProvider.h 2010-04-21 13:50:16.780936013 +0200
+++ XBMC/xbmc/linux/LinuxStorageProvider.h 2010-04-21 14:04:21.506684504 +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.orig//xbmc/linux/Makefile.in XBMC/xbmc/linux/Makefile.in
--- XBMC.orig//xbmc/linux/Makefile.in 2010-04-21 13:50:16.780936013 +0200
+++ XBMC/xbmc/linux/Makefile.in 2010-04-21 14:04:21.506684504 +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.orig//xbmc/linux/UDisksProvider.cpp XBMC/xbmc/linux/UDisksProvider.cpp
--- XBMC.orig//xbmc/linux/UDisksProvider.cpp 1970-01-01 01:00:00.000000000 +0100
+++ XBMC/xbmc/linux/UDisksProvider.cpp 2010-04-21 14:05:15.713345822 +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.orig//xbmc/linux/UDisksProvider.h XBMC/xbmc/linux/UDisksProvider.h
--- XBMC.orig//xbmc/linux/UDisksProvider.h 1970-01-01 01:00:00.000000000 +0100
+++ XBMC/xbmc/linux/UDisksProvider.h 2010-04-21 14:06:10.370007022 +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.orig//xbmc/PowerManager.cpp XBMC/xbmc/PowerManager.cpp
--- XBMC.orig//xbmc/PowerManager.cpp 2010-04-21 13:50:19.166768835 +0200
+++ XBMC/xbmc/PowerManager.cpp 2010-04-21 14:04:21.510434515 +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();