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 
12 typedef enum {
23 
24 typedef enum {
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,
37 // MediaType conflicts with a definition within OSX Quicktime Libraries.
38 
39 typedef enum {
44 
45 typedef QMap<QString,uint> ext_cnt_t;
46 typedef QMap<QString,uint> ext_to_media_t;
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 char* MediaStatusStrings[];
118  static const char* MediaErrorStrings[];
119 
120  void clearData();
121 
122  QString MediaTypeString();
123 
124  static QString MediaTypeString(uint type);
125 
126  signals:
127  void statusChanged(MythMediaStatus oldStatus, MythMediaDevice* pMedia);
128 
129  protected:
130  virtual ~MythMediaDevice() = 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 
189  MythMediaStatus getOldStatus(void) const { return m_OldStatus; }
190  MythMediaDevice* getDevice(void) { return m_Device; }
191 
192  static Type kEventType;
193 
194  protected:
196  QPointer<MythMediaDevice> m_Device;
197 };
198 
199 #endif
MythMediaType getMediaType() const
Definition: mythmedia.h:91
MythMediaEvent(MythMediaStatus oldStatus, MythMediaDevice *pDevice)
Definition: mythmedia.h:186
int mediatype
Definition: mythburn.py:179
const QString & getDevicePath() const
Definition: mythmedia.h:61
CD/DVD tray open (meaningless for non-CDs?)
Definition: mythmedia.h:16
void setDeviceModel(const char *model)
Definition: mythmedia.h:68
MythMediaType
Definition: mythmedia.h:24
QMap< QString, uint > ext_to_media_t
Definition: mythmedia.h:46
static ext_to_media_t s_ext_to_media
Map of extension to media type.
Definition: mythmedia.h:180
bool m_AllowEject
Allow the user to eject the media?. Read only.
Definition: mythmedia.h:165
virtual void setDeviceSpeed(const char *, int)
Definition: mythmedia.h:100
Unable to mount, but could be usable.
Definition: mythmedia.h:13
const QString & getKeyID() const
Definition: mythmedia.h:75
QString m_DevicePath
The path to this media's device.
Definition: mythmedia.h:149
QPointer< MythMediaDevice > m_Device
Definition: mythmedia.h:196
unsigned int uint
Definition: compat.h:140
bool m_SuperMount
Is this a supermount device?.
Definition: mythmedia.h:168
bool isSuperMount() const
Definition: mythmedia.h:93
QMap< QString, uint > ext_cnt_t
Definition: mythmedia.h:45
virtual MythMediaError testMedia()
Definition: mythmedia.h:95
MythMediaStatus getOldStatus(void) const
Definition: mythmedia.h:189
void setVolumeID(const char *vol)
Definition: mythmedia.h:73
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
const QString & getVolumeID() const
Definition: mythmedia.h:72
MythMediaError
Definition: mythmedia.h:39
For devices/media a plugin might erase/format.
Definition: mythmedia.h:18
bool getLocked() const
Definition: mythmedia.h:79
const QString & getDeviceModel() const
Definition: mythmedia.h:67
QString m_DeviceModel
The device Manufacturer/Model. Read/write.
Definition: mythmedia.h:148
const QString & getRealDevice() const
Definition: mythmedia.h:63
MythMediaDevice * getDevice(void)
Definition: mythmedia.h:190
virtual void onDeviceUnmounted()
Override this to perform any post unmount logic.
Definition: mythmedia.h:141
static Type kEventType
Definition: mythmedia.h:192
This currently depends on Apple's DiskArbitration framework.
const QString & getMountPath() const
Definition: mythmedia.h:58
virtual void onDeviceMounted(void)
Override this to perform any post mount logic.
Definition: mythmedia.h:133
bool isUsable() const
Is this device "ready", for a plugin to access?
Definition: mythmedia.h:84
CD/DVD tray closed but empty, device unusable.
Definition: mythmedia.h:17
bool getAllowEject() const
Definition: mythmedia.h:77
MythMediaStatus
Definition: mythmedia.h:12
void setMountPath(const char *path)
Definition: mythmedia.h:59
bool unmount()
Definition: mythmedia.h:108
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
MythMediaStatus m_OldStatus
Definition: mythmedia.h:195