MythTV  master
mythmedia.h
Go to the documentation of this file.
1 #ifndef MYTH_MEDIA_H
2 #define MYTH_MEDIA_H
3 
4 #include <QObject>
5 #include <QMap>
6 #include <QString>
7 #include <QEvent>
8 #include <QPointer>
9 
10 #include "mythbaseexp.h"
11 
22 };
23 
26  MEDIATYPE_DATA = 0x0002,
27  MEDIATYPE_MIXED = 0x0004,
28  MEDIATYPE_AUDIO = 0x0008,
29  MEDIATYPE_DVD = 0x0010,
30  MEDIATYPE_VCD = 0x0020,
31  MEDIATYPE_MMUSIC = 0x0040,
32  MEDIATYPE_MVIDEO = 0x0080,
34  MEDIATYPE_BD = 0x0200,
35  MEDIATYPE_END = 0x0400,
36 };
37 // MediaType conflicts with a definition within OSX Quicktime Libraries.
38 
43 };
44 
45 using ext_cnt_t = QMap<QString,uint>;
46 using ext_to_media_t = QMap<QString,uint>;
47 
48 class MBASE_PUBLIC MythMediaDevice : public QObject
49 {
50  Q_OBJECT
51  friend class MediaMonitorDarwin; // So these can call setStatus(),
52  friend class MonitorThreadDarwin; // and trigger posting of MythMediaEvents
53 
54  public:
55  MythMediaDevice(QObject* par, const char* DevicePath, bool SuperMount,
56  bool AllowEject);
57 
58  const QString& getMountPath() const { return m_mountPath; }
59  void setMountPath(const char *path) { m_mountPath = path; }
60 
61  const QString& getDevicePath() const { return m_devicePath; }
62 
63  const QString& getRealDevice() const
64  { return m_realDevice.length() ? m_realDevice : m_devicePath; }
65 
66 
67  const QString& getDeviceModel() const { return m_deviceModel; }
68  void setDeviceModel(const char *model) { m_deviceModel = model; }
69 
70  MythMediaStatus getStatus() const { return m_status; }
71 
72  const QString& getVolumeID() const { return m_volumeID; }
73  void setVolumeID(const char *vol) { m_volumeID = vol; }
74 
75  const QString& getKeyID() const { return m_keyID; }
76 
77  bool getAllowEject() const { return m_allowEject; }
78 
79  bool getLocked() const { return m_locked; }
80 
81  bool isDeviceOpen() const;
82 
84  bool isUsable() const
85  {
86  return m_status == MEDIASTAT_USEABLE
87  || m_status == MEDIASTAT_MOUNTED
88  || m_status == MEDIASTAT_NOTMOUNTED;
89  }
90 
91  MythMediaType getMediaType() const { return m_mediaType; }
92 
93  bool isSuperMount() const { return m_superMount; }
94 
96  virtual bool openDevice();
97  virtual bool closeDevice();
98  virtual bool isSameDevice(const QString &path);
99  virtual void setSpeed(int speed);
100  virtual void setDeviceSpeed(const char * /*devicePath*/, int /*speed*/) { }
101  virtual MythMediaStatus checkMedia() = 0;// Derived classes MUST implement this.
102  virtual MythMediaError eject(bool open_close = true);
103  virtual MythMediaError lock();
104  virtual MythMediaError unlock();
105  virtual bool performMountCmd( bool DoMount );
106 
107  bool mount() { return performMountCmd(true); }
108  bool unmount() { return performMountCmd(false); }
109 
110  bool isMounted(bool bVerify = true);
111  bool findMountPath();
112 
113  static void RegisterMediaExtensions(uint mediatype,
114  const QString& extensions);
115 
116 
117  static const std::array<const QString,9> kMediaStatusStrings;
118  static const std::array<const QString,3> kMediaErrorStrings;
119 
120  void clearData();
121 
122  QString MediaTypeString();
123 
124  static QString MediaTypeString(uint type);
125 
126  signals:
128 
129  protected:
130  ~MythMediaDevice() override = default; // use deleteLater...
131 
133  virtual void onDeviceMounted(void)
134  {
135  MythMediaType type = DetectMediaType();
136  if (type != MEDIATYPE_UNKNOWN)
137  m_mediaType = type;
138  }
139 
141  virtual void onDeviceUnmounted() {};
142 
143  MythMediaType DetectMediaType(void);
144  bool ScanMediaType(const QString &directory, ext_cnt_t &cnt);
145 
146  MythMediaStatus setStatus(MythMediaStatus newStat, bool CloseIt=false);
147 
148  QString m_deviceModel;
149  QString m_devicePath;
150  QString m_keyID;
152  QString m_mountPath;
154  QString m_realDevice;
156  QString m_volumeID;
158 
164 
166  bool m_locked {false};
167 
169 
174 
175  int m_deviceHandle {-1};
176  private:
181 };
182 
183 class MBASE_PUBLIC MythMediaEvent : public QEvent
184 {
185  public:
187  QEvent(kEventType), m_oldStatus(oldStatus), m_device(pDevice) {}
188  ~MythMediaEvent() override;
189 
190  MythMediaStatus getOldStatus(void) const { return m_oldStatus; }
191  MythMediaDevice* getDevice(void) { return m_device; }
192 
193  static Type kEventType;
194 
195  protected:
197  QPointer<MythMediaDevice> m_device;
198 };
199 
200 #endif
MythMediaDevice::isUsable
bool isUsable() const
Is this device "ready", for a plugin to access?
Definition: mythmedia.h:84
MythMediaDevice::getMountPath
const QString & getMountPath() const
Definition: mythmedia.h:58
MythMediaEvent::getOldStatus
MythMediaStatus getOldStatus(void) const
Definition: mythmedia.h:190
MEDIATYPE_MIXED
@ MEDIATYPE_MIXED
Definition: mythmedia.h:27
MEDIATYPE_END
@ MEDIATYPE_END
Definition: mythmedia.h:35
MythMediaDevice::m_superMount
bool m_superMount
Is this a supermount device?.
Definition: mythmedia.h:168
MythMediaDevice::mount
bool mount()
Definition: mythmedia.h:107
MEDIATYPE_DVD
@ MEDIATYPE_DVD
Definition: mythmedia.h:29
MythMediaDevice::getAllowEject
bool getAllowEject() const
Definition: mythmedia.h:77
MEDIATYPE_VCD
@ MEDIATYPE_VCD
Definition: mythmedia.h:30
MEDIATYPE_UNKNOWN
@ MEDIATYPE_UNKNOWN
Definition: mythmedia.h:25
MythMediaDevice::m_deviceModel
QString m_deviceModel
The device Manufacturer/Model. Read/write.
Definition: mythmedia.h:148
MythMediaDevice::setDeviceSpeed
virtual void setDeviceSpeed(const char *, int)
Definition: mythmedia.h:100
MythMediaDevice::setVolumeID
void setVolumeID(const char *vol)
Definition: mythmedia.h:73
MythMediaEvent::getDevice
MythMediaDevice * getDevice(void)
Definition: mythmedia.h:191
MythMediaDevice::~MythMediaDevice
~MythMediaDevice() override=default
MythMediaDevice::testMedia
virtual MythMediaError testMedia()
Definition: mythmedia.h:95
mythburn.mediatype
int mediatype
Definition: mythburn.py:208
mythbaseexp.h
MythMediaEvent::m_device
QPointer< MythMediaDevice > m_device
Definition: mythmedia.h:197
MythMediaEvent::m_oldStatus
MythMediaStatus m_oldStatus
Definition: mythmedia.h:196
ext_to_media_t
QMap< QString, uint > ext_to_media_t
Definition: mythmedia.h:46
MEDIASTAT_ERROR
@ MEDIASTAT_ERROR
Unable to mount, but could be usable.
Definition: mythmedia.h:13
MEDIASTAT_USEABLE
@ MEDIASTAT_USEABLE
Definition: mythmedia.h:19
MythMediaDevice::getDevicePath
const QString & getDevicePath() const
Definition: mythmedia.h:61
MythMediaDevice::getStatus
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
MEDIATYPE_MMUSIC
@ MEDIATYPE_MMUSIC
Definition: mythmedia.h:31
MythMediaDevice::getKeyID
const QString & getKeyID() const
Definition: mythmedia.h:75
MythMediaDevice::onDeviceUnmounted
virtual void onDeviceUnmounted()
Override this to perform any post unmount logic.
Definition: mythmedia.h:141
MEDIASTAT_MOUNTED
@ MEDIASTAT_MOUNTED
Definition: mythmedia.h:21
MythMediaDevice::s_ext_to_media
static ext_to_media_t s_ext_to_media
Map of extension to media type.
Definition: mythmedia.h:180
MythMediaDevice::getDeviceModel
const QString & getDeviceModel() const
Definition: mythmedia.h:67
MythMediaDevice::statusChanged
void statusChanged(MythMediaStatus oldStatus, MythMediaDevice *pMedia)
MythMediaEvent::kEventType
static Type kEventType
Definition: mythmedia.h:193
MEDIASTAT_UNPLUGGED
@ MEDIASTAT_UNPLUGGED
Definition: mythmedia.h:15
MythMediaEvent::MythMediaEvent
MythMediaEvent(MythMediaStatus oldStatus, MythMediaDevice *pDevice)
Definition: mythmedia.h:186
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythMediaDevice::getRealDevice
const QString & getRealDevice() const
Definition: mythmedia.h:63
MythMediaDevice::setDeviceModel
void setDeviceModel(const char *model)
Definition: mythmedia.h:68
MEDIATYPE_BD
@ MEDIATYPE_BD
Definition: mythmedia.h:34
MythMediaEvent
Definition: mythmedia.h:184
MythMediaDevice::unmount
bool unmount()
Definition: mythmedia.h:108
MythMediaDevice::onDeviceMounted
virtual void onDeviceMounted(void)
Override this to perform any post mount logic.
Definition: mythmedia.h:133
MythMediaDevice::isSuperMount
bool isSuperMount() const
Definition: mythmedia.h:93
MythMediaDevice::setMountPath
void setMountPath(const char *path)
Definition: mythmedia.h:59
MEDIATYPE_MVIDEO
@ MEDIATYPE_MVIDEO
Definition: mythmedia.h:32
MEDIATYPE_AUDIO
@ MEDIATYPE_AUDIO
Definition: mythmedia.h:28
MythMediaDevice::kMediaErrorStrings
static const std::array< const QString, 3 > kMediaErrorStrings
Definition: mythmedia.h:118
uint
unsigned int uint
Definition: compat.h:140
MediaMonitorDarwin
Definition: mediamonitor-darwin.h:22
MythMediaType
MythMediaType
Definition: mythmedia.h:24
MEDIASTAT_NODISK
@ MEDIASTAT_NODISK
CD/DVD tray closed but empty, device unusable.
Definition: mythmedia.h:17
MEDIATYPE_MGALLERY
@ MEDIATYPE_MGALLERY
Definition: mythmedia.h:33
MonitorThreadDarwin
Definition: mediamonitor-darwin.h:8
MythMediaDevice::m_devicePath
QString m_devicePath
The path to this media's device.
Definition: mythmedia.h:149
MythMediaDevice::m_allowEject
bool m_allowEject
Allow the user to eject the media?. Read only.
Definition: mythmedia.h:165
MythMediaDevice::kMediaStatusStrings
static const std::array< const QString, 9 > kMediaStatusStrings
Definition: mythmedia.h:117
MythMediaDevice::getLocked
bool getLocked() const
Definition: mythmedia.h:79
MythMediaDevice::checkMedia
virtual MythMediaStatus checkMedia()=0
MythMediaDevice::getMediaType
MythMediaType getMediaType() const
Definition: mythmedia.h:91
MEDIASTAT_OPEN
@ MEDIASTAT_OPEN
CD/DVD tray open (meaningless for non-CDs?)
Definition: mythmedia.h:16
MEDIAERR_FAILED
@ MEDIAERR_FAILED
Definition: mythmedia.h:41
MythMediaError
MythMediaError
Definition: mythmedia.h:39
MythMediaDevice
Definition: mythmedia.h:49
MEDIASTAT_UNFORMATTED
@ MEDIASTAT_UNFORMATTED
For devices/media a plugin might erase/format.
Definition: mythmedia.h:18
MEDIAERR_OK
@ MEDIAERR_OK
Definition: mythmedia.h:40
MEDIASTAT_UNKNOWN
@ MEDIASTAT_UNKNOWN
Definition: mythmedia.h:14
MEDIAERR_UNSUPPORTED
@ MEDIAERR_UNSUPPORTED
Definition: mythmedia.h:42
MythMediaStatus
MythMediaStatus
Definition: mythmedia.h:12
MythMediaDevice::getVolumeID
const QString & getVolumeID() const
Definition: mythmedia.h:72
ext_cnt_t
QMap< QString, uint > ext_cnt_t
Definition: mythmedia.h:45
MEDIATYPE_DATA
@ MEDIATYPE_DATA
Definition: mythmedia.h:26
MEDIASTAT_NOTMOUNTED
@ MEDIASTAT_NOTMOUNTED
Definition: mythmedia.h:20