xbmc
UDisksProvider.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "DBusUtil.h"
12 #include "storage/IStorageProvider.h"
13 
14 #include <string>
15 #include <vector>
16 
18 {
19 public:
20  CUDiskDevice(const char *DeviceKitUDI);
21  ~CUDiskDevice() = default;
22 
23  void Update();
24 
25  bool Mount();
26  bool UnMount();
27 
31  bool IsApproved() const;
32 
37  MEDIA_DETECT::STORAGE::Type GetStorageType() const;
38 
42  bool IsOptical() const;
43 
47  bool IsMounted() const;
48 
52  bool IsSystemInternal() const;
53 
57  std::string GetDisplayName() const;
58 
62  std::string GetMountPoint() const;
63 
67  std::string ToString() const;
68 
72  CMediaSource ToMediaShare() const;
73 
78 
79 private:
80  std::string m_UDI;
81  std::string m_DeviceKitUDI;
82  std::string m_MountPath;
83  std::string m_FileSystem;
84  std::string m_Label;
85  bool m_isMounted;
86  bool m_isMountedByUs;
87  bool m_isRemovable;
88  bool m_isPartition;
89  bool m_isFileSystem;
90  bool m_isSystemInternal;
91  bool m_isOptical;
92  int64_t m_PartitionSize;
93 };
94 
96 {
97 public:
99  ~CUDisksProvider() override;
100 
101  void Initialize() override;
102  void Stop() override { }
103 
104  void GetLocalDrives(VECSOURCES &localDrives) override { GetDisks(localDrives, false); }
105  void GetRemovableDrives(VECSOURCES &removableDrives) override { GetDisks(removableDrives, true); }
106 
107  bool Eject(const std::string& mountpath) override;
108 
109  std::vector<std::string> GetDiskUsage() override;
110 
111  bool PumpDriveChangeEvents(IStorageEventsCallback *callback) override;
112 
113  static bool HasUDisks();
114 private:
115  typedef std::map<std::string, CUDiskDevice *> DeviceMap;
116  typedef std::pair<std::string, CUDiskDevice *> DevicePair;
117 
118  void DeviceAdded(const char *object, IStorageEventsCallback *callback);
119  void DeviceRemoved(const char *object, IStorageEventsCallback *callback);
120  void DeviceChanged(const char *object, IStorageEventsCallback *callback);
121 
122  std::vector<std::string> EnumerateDisks();
123 
124  void GetDisks(VECSOURCES& devices, bool EnumerateRemovable);
125 
126  int m_DaemonVersion;
127 
128  DeviceMap m_AvailableDevices;
129 
130  CDBusConnection m_connection;
131 };
std::string GetMountPoint() const
Get the device mount point.
Definition: UDisksProvider.cpp:176
Definition: DBusUtil.h:38
MEDIA_DETECT::STORAGE::Type GetStorageType() const
Get the storage type of this device.
Definition: UDisksProvider.cpp:158
Definition: UDisksProvider.h:95
bool IsMounted() const
Check if the device is mounted.
Definition: UDisksProvider.cpp:166
bool IsOptical() const
Check if the device is optical.
Definition: UDisksProvider.cpp:153
Represents a share.
Definition: MediaSource.h:22
CMediaSource ToMediaShare() const
Get a representation of the device as a media share.
Definition: UDisksProvider.cpp:126
Abstracts a generic storage device.
Definition: IStorageProvider.h:32
Definition: IStorageProvider.h:65
std::string GetDisplayName() const
Get the device display name/label.
Definition: UDisksProvider.cpp:171
bool IsApproved() const
Check if the device is approved/whitelisted.
Definition: UDisksProvider.cpp:147
Definition: UDisksProvider.h:17
MEDIA_DETECT::STORAGE::StorageDevice ToStorageDevice() const
Get a representation of the device as a storage device abstraction.
Definition: UDisksProvider.cpp:186
std::string ToString() const
Get a representation of the device as a readable string.
Definition: UDisksProvider.cpp:197
bool IsSystemInternal() const
Check if the device is internal to the system.
Definition: UDisksProvider.cpp:181
Definition: IStorageProvider.h:44