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 17 class CUDiskDevice 18 { 19 public: 20 CUDiskDevice(const char *DeviceKitUDI); 21 ~CUDiskDevice() = default; 22 23 void Update(); 24 25 bool Mount(); 26 bool UnMount(); 27 28 bool IsApproved(); 29 30 std::string toString(); 31 32 CMediaSource ToMediaShare(); 33 34 std::string m_UDI, m_DeviceKitUDI, m_MountPath, m_FileSystem, m_Label; 35 bool m_isMounted, m_isMountedByUs, m_isRemovable, m_isPartition, m_isFileSystem, m_isSystemInternal, m_isOptical; 36 int64_t m_PartitionSize; 37 }; 38 39 class CUDisksProvider : public IStorageProvider 40 { 41 public: 42 CUDisksProvider(); 43 ~CUDisksProvider() override; 44 45 void Initialize() override; Stop()46 void Stop() override { } 47 GetLocalDrives(VECSOURCES & localDrives)48 void GetLocalDrives(VECSOURCES &localDrives) override { GetDisks(localDrives, false); } GetRemovableDrives(VECSOURCES & removableDrives)49 void GetRemovableDrives(VECSOURCES &removableDrives) override { GetDisks(removableDrives, true); } 50 51 bool Eject(const std::string& mountpath) override; 52 53 std::vector<std::string> GetDiskUsage() override; 54 55 bool PumpDriveChangeEvents(IStorageEventsCallback *callback) override; 56 57 static bool HasUDisks(); 58 private: 59 typedef std::map<std::string, CUDiskDevice *> DeviceMap; 60 typedef std::pair<std::string, CUDiskDevice *> DevicePair; 61 62 void DeviceAdded(const char *object, IStorageEventsCallback *callback); 63 void DeviceRemoved(const char *object, IStorageEventsCallback *callback); 64 void DeviceChanged(const char *object, IStorageEventsCallback *callback); 65 66 std::vector<std::string> EnumerateDisks(); 67 68 void GetDisks(VECSOURCES& devices, bool EnumerateRemovable); 69 70 int m_DaemonVersion; 71 72 DeviceMap m_AvailableDevices; 73 74 CDBusConnection m_connection; 75 }; 76