| 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 |
|
| 26 |
class CNetworkLocation |
| 27 |
{ |
| 28 |
public: |
| 29 |
CNetworkLocation() { id = 0; } |
| 30 |
int id; |
| 31 |
std::string path; |
| 32 |
}; |
| 33 |
|
| 34 |
class CMediaManager : public IStorageEventsCallback, public IJobCallback |
| 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 |
|
| 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 |
| 71 |
*/ |
| 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 |
|
| 86 |
/*! \brief Callback executed when a new storage device is added |
| 87 |
* \sa IStorageEventsCallback |
| 88 |
* @param device the storage device |
| 89 |
*/ |
| 90 |
void OnStorageAdded(const MEDIA_DETECT::STORAGE::StorageDevice& device) override; |
| 91 |
|
| 92 |
/*! \brief Callback executed when a new storage device is safely removed |
| 93 |
* \sa IStorageEventsCallback |
| 94 |
* @param device the storage device |
| 95 |
*/ |
| 96 |
void OnStorageSafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) override; |
| 97 |
|
| 98 |
/*! \brief Callback executed when a new storage device is unsafely removed |
| 99 |
* \sa IStorageEventsCallback |
| 100 |
* @param device the storage device |
| 101 |
*/ |
| 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: |
| 119 |
/*! \brief Loads the addon sources for the different supported browsable addon types |
| 120 |
*/ |
| 121 |
void LoadAddonSources() const; |
| 122 |
|
| 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 |
| 126 |
*/ |
| 127 |
CMediaSource GetRootAddonTypeSource(const std::string& type) const; |
| 128 |
|
| 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 |
| 134 |
*/ |
| 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 |
}; |