Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / storage / MediaManager.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "MediaSource.h" // for VECSOURCES
23 #include <map>
24 #include "utils/Job.h"
25 #include "IStorageProvider.h"
26 #include "threads/CriticalSection.h"
27
28 #ifdef HAS_DVD_DRIVE
29 using namespace MEDIA_DETECT;
30 #endif
31
32 #define TRAY_OPEN     16
33 #define TRAY_CLOSED_NO_MEDIA  64
34 #define TRAY_CLOSED_MEDIA_PRESENT 96
35
36 #define DRIVE_OPEN      0 // Open...
37 #define DRIVE_NOT_READY     1 // Opening.. Closing...
38 #define DRIVE_READY      2
39 #define DRIVE_CLOSED_NO_MEDIA   3 // CLOSED...but no media in drive
40 #define DRIVE_CLOSED_MEDIA_PRESENT  4 // Will be send once when the drive just have closed
41 #define DRIVE_NONE  5 // system doesn't have an optical drive
42
43 class CNetworkLocation
44 {
45 public:
46   CNetworkLocation() { id = 0; };
47   int id;
48   CStdString path;
49 };
50
51 class CMediaManager : public IStorageEventsCallback, public IJobCallback
52 {
53 public:
54   CMediaManager();
55
56   void Initialize();
57   void Stop();
58
59   bool LoadSources();
60   bool SaveSources();
61
62   void GetLocalDrives(VECSOURCES &localDrives, bool includeQ = true);
63   void GetRemovableDrives(VECSOURCES &removableDrives);
64   void GetNetworkLocations(VECSOURCES &locations, bool autolocations = true);
65
66   bool AddNetworkLocation(const CStdString &path);
67   bool HasLocation(const CStdString& path) const;
68   bool RemoveLocation(const CStdString& path);
69   bool SetLocationPath(const CStdString& oldPath, const CStdString& newPath);
70
71   void AddAutoSource(const CMediaSource &share, bool bAutorun=false);
72   void RemoveAutoSource(const CMediaSource &share);
73   bool IsDiscInDrive(const CStdString& devicePath="");
74   bool IsAudio(const CStdString& devicePath="");
75   bool HasOpticalDrive();
76   CStdString TranslateDevicePath(const CStdString& devicePath, bool bReturnAsDevice=false);
77   DWORD GetDriveStatus(const CStdString& devicePath="");
78 #ifdef HAS_DVD_DRIVE
79   CCdInfo* GetCdInfo(const CStdString& devicePath="");
80   bool RemoveCdInfo(const CStdString& devicePath="");
81   CStdString GetDiskLabel(const CStdString& devicePath="");
82   CStdString GetDiskUniqueId(const CStdString& devicePath="");
83 #endif
84   CStdString GetDiscPath();
85   void SetHasOpticalDrive(bool bstatus);
86
87   bool Eject(CStdString mountpath);
88   void EjectTray( const bool bEject=true, const char cDriveLetter='\0' );
89   void CloseTray(const char cDriveLetter='\0');
90   void ToggleTray(const char cDriveLetter='\0');
91
92   void ProcessEvents();
93
94   std::vector<CStdString> GetDiskUsage();
95
96   virtual void OnStorageAdded(const CStdString &label, const CStdString &path);
97   virtual void OnStorageSafelyRemoved(const CStdString &label);
98   virtual void OnStorageUnsafelyRemoved(const CStdString &label);
99
100   virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job) { }
101 protected:
102   std::vector<CNetworkLocation> m_locations;
103
104   CCriticalSection m_muAutoSource, m_CritSecStorageProvider;
105 #ifdef HAS_DVD_DRIVE
106   std::map<CStdString,CCdInfo*> m_mapCdInfo;
107 #endif
108   bool m_bhasoptical;
109   CStdString m_strFirstAvailDrive;
110
111 private:
112   IStorageProvider *m_platformStorage;
113 };
114
115 extern class CMediaManager g_mediaManager;
116