xbmc
MediaManager.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 "IStorageProvider.h"
12 #include "MediaSource.h" // for VECSOURCES
13 #include "storage/discs/IDiscDriveHandler.h"
14 #include "threads/CriticalSection.h"
15 #include "utils/DiscsUtils.h"
16 #include "utils/Job.h"
17 
18 #include <map>
19 #include <memory>
20 #include <vector>
21 
22 #include "PlatformDefs.h"
23 
24 class CFileItem;
25 
27 {
28 public:
29  CNetworkLocation() { id = 0; }
30  int id;
31  std::string path;
32 };
33 
35 {
36 public:
37  CMediaManager();
38 
39  void Initialize();
40  void Stop();
41 
42  bool LoadSources();
43  bool SaveSources();
44 
45  void GetLocalDrives(VECSOURCES &localDrives, bool includeQ = true);
46  void GetRemovableDrives(VECSOURCES &removableDrives);
47  void GetNetworkLocations(VECSOURCES &locations, bool autolocations = true);
48 
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);
53 
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="");
66 
72  std::shared_ptr<IDiscDriveHandler> GetDiscDriveHandler();
73 #endif
74  std::string GetDiscPath();
75  void SetHasOpticalDrive(bool bstatus);
76 
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');
81 
82  void ProcessEvents();
83 
84  std::vector<std::string> GetDiskUsage();
85 
90  void OnStorageAdded(const MEDIA_DETECT::STORAGE::StorageDevice& device) override;
91 
96  void OnStorageSafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) override;
97 
102  void OnStorageUnsafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) override;
103 
104  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override { }
105 
106  bool playStubFile(const CFileItem& item);
107 
108 protected:
109  std::vector<CNetworkLocation> m_locations;
110 
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;
117 
118 private:
121  void LoadAddonSources() const;
122 
127  CMediaSource GetRootAddonTypeSource(const std::string& type) const;
128 
135  CMediaSource ComputeRootAddonTypeSource(const std::string& type,
136  const std::string& label,
137  const std::string& thumb) const;
138 
139  std::unique_ptr<IStorageProvider> m_platformStorage;
140 #ifdef HAS_OPTICAL_DRIVE
141  std::shared_ptr<IDiscDriveHandler> m_platformDiscDriveHander;
142 #endif
143 
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;
147 };
Definition: cdioSupport.h:114
Abstracts the info the app knows about a disc (type, name, serial)
Definition: DiscsUtils.h:29
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
void OnJobComplete(unsigned int jobID, bool success, CJob *job) override
The callback used when a job completes.
Definition: MediaManager.h:104
Represents a share.
Definition: MediaSource.h:22
Definition: MediaManager.h:34
Definition: MediaManager.h:26
Abstracts a generic storage device.
Definition: IStorageProvider.h:32
Callback interface for asynchronous jobs.
Definition: Job.h:31
Represents a file on a share.
Definition: FileItem.h:102
Definition: IStorageProvider.h:44