Merge pull request #26032 from sundermann/android-make-packaging
[xbmc.git] / xbmc / storage / MediaManager.h
blob8c53771de3d7f2d1a5528afbbd4639ca92c0d0b4
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "IStorageProvider.h"
12 #include "MediaSource.h" // for std::vector<CMediaSource>
13 #include "storage/discs/IDiscDriveHandler.h"
14 #include "threads/CriticalSection.h"
15 #include "utils/DiscsUtils.h"
16 #include "utils/Job.h"
18 #include <map>
19 #include <memory>
20 #include <vector>
22 #include "PlatformDefs.h"
24 class CFileItem;
26 class CNetworkLocation
28 public:
29 CNetworkLocation() { id = 0; }
30 int id;
31 std::string path;
34 class CMediaManager : public IStorageEventsCallback, public IJobCallback
36 public:
37 CMediaManager();
39 void Initialize();
40 void Stop();
42 bool LoadSources();
43 bool SaveSources();
45 void GetLocalDrives(std::vector<CMediaSource>& localDrives, bool includeQ = true);
46 void GetRemovableDrives(std::vector<CMediaSource>& removableDrives);
47 void GetNetworkLocations(std::vector<CMediaSource>& locations, bool autolocations = true);
49 bool AddNetworkLocation(const std::string &path);
50 bool HasLocation(const std::string& path) const;
51 bool RemoveLocation(const std::string& path);
52 bool SetLocationPath(const std::string& oldPath, const std::string& newPath);
54 void AddAutoSource(const CMediaSource &share, bool bAutorun=false);
55 void RemoveAutoSource(const CMediaSource &share);
56 bool IsDiscInDrive(const std::string& devicePath="");
57 bool IsAudio(const std::string& devicePath="");
58 bool HasOpticalDrive();
59 std::string TranslateDevicePath(const std::string& devicePath, bool bReturnAsDevice=false);
60 DriveState GetDriveStatus(const std::string& devicePath = "");
61 #ifdef HAS_OPTICAL_DRIVE
62 MEDIA_DETECT::CCdInfo* GetCdInfo(const std::string& devicePath="");
63 bool RemoveCdInfo(const std::string& devicePath="");
64 std::string GetDiskLabel(const std::string& devicePath="");
65 std::string GetDiskUniqueId(const std::string& devicePath="");
67 /*! \brief Gets the platform disc drive handler
68 * @todo this likely doesn't belong here but in some discsupport component owned by media manager
69 * let's keep it here for now
70 * \return The platform disc drive handler
72 std::shared_ptr<IDiscDriveHandler> GetDiscDriveHandler();
73 #endif
74 std::string GetDiscPath();
75 void SetHasOpticalDrive(bool bstatus);
77 bool Eject(const std::string& mountpath);
78 void EjectTray( const bool bEject=true, const char cDriveLetter='\0' );
79 void CloseTray(const char cDriveLetter='\0');
80 void ToggleTray(const char cDriveLetter='\0');
82 void ProcessEvents();
84 std::vector<std::string> GetDiskUsage();
86 /*! \brief Callback executed when a new storage device is added
87 * \sa IStorageEventsCallback
88 * @param device the storage device
90 void OnStorageAdded(const MEDIA_DETECT::STORAGE::StorageDevice& device) override;
92 /*! \brief Callback executed when a new storage device is safely removed
93 * \sa IStorageEventsCallback
94 * @param device the storage device
96 void OnStorageSafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) override;
98 /*! \brief Callback executed when a new storage device is unsafely removed
99 * \sa IStorageEventsCallback
100 * @param device the storage device
102 void OnStorageUnsafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) override;
104 void OnJobComplete(unsigned int jobID, bool success, CJob *job) override { }
106 bool playStubFile(const CFileItem& item);
108 protected:
109 std::vector<CNetworkLocation> m_locations;
111 CCriticalSection m_muAutoSource, m_CritSecStorageProvider;
112 #ifdef HAS_OPTICAL_DRIVE
113 std::map<std::string,MEDIA_DETECT::CCdInfo*> m_mapCdInfo;
114 #endif
115 bool m_bhasoptical;
116 std::string m_strFirstAvailDrive;
118 private:
119 /*! \brief Loads the addon sources for the different supported browsable addon types
121 void LoadAddonSources() const;
123 /*! \brief Get the addons root source for the given content type
124 \param type the type of addon content desired
125 \return the given CMediaSource for the addon root directory
127 CMediaSource GetRootAddonTypeSource(const std::string& type) const;
129 /*! \brief Generate the addons source for the given content type
130 \param type the type of addon content desired
131 \param label the name of the addons source
132 \param thumb image to use as the icon
133 \return the given CMediaSource for the addon root directory
135 CMediaSource ComputeRootAddonTypeSource(const std::string& type,
136 const std::string& label,
137 const std::string& thumb) const;
139 std::unique_ptr<IStorageProvider> m_platformStorage;
140 #ifdef HAS_OPTICAL_DRIVE
141 std::shared_ptr<IDiscDriveHandler> m_platformDiscDriveHander;
142 #endif
144 UTILS::DISCS::DiscInfo GetDiscInfo(const std::string& mediaPath);
145 void RemoveDiscInfo(const std::string& devicePath);
146 std::map<std::string, UTILS::DISCS::DiscInfo> m_mapDiscInfo;