-
Notifications
You must be signed in to change notification settings - Fork 341
/
mythmediamonitor.h
131 lines (104 loc) · 4.37 KB
/
mythmediamonitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef MYTH_MEDIA_MONITOR_H
#define MYTH_MEDIA_MONITOR_H
#include <QStringList>
#include <QPointer>
#include <QMutex>
#include <QList>
#include "mthread.h"
#include "mythexp.h"
#include "mythmedia.h"
/// Stores details of media handlers
struct MHData
{
void (*callback)(MythMediaDevice *mediadevice);
int MythMediaType;
QString destination;
QString description;
};
class MediaMonitor;
class MonitorThread : public MThread
{
public:
MonitorThread(MediaMonitor* pMon, unsigned long interval);
~MonitorThread() { wait(); m_Monitor = NULL; }
void setMonitor(MediaMonitor* pMon) { m_Monitor = pMon; }
virtual void run(void);
protected:
QPointer<MediaMonitor> m_Monitor;
unsigned long m_Interval;
};
class MPUBLIC MediaMonitor : public QObject
{
Q_OBJECT
friend class MonitorThread;
friend class MonitorThreadDarwin;
public:
virtual void deleteLater(void);
bool IsActive(void) const { return m_Active; }
virtual void StartMonitoring(void);
void StopMonitoring(void);
void ChooseAndEjectMedia(void);
static MediaMonitor *GetMediaMonitor(void);
static QString GetMountPath(const QString& devPath);
static void SetCDSpeed(const char *device, int speed);
bool ValidateAndLock(MythMediaDevice *pMedia);
void Unlock(MythMediaDevice *pMedia);
// To safely dereference the pointers returned by this function
// first validate the pointer with ValidateAndLock(), if true is returned
// it is safe to dereference the pointer. When finished call Unlock()
QList<MythMediaDevice*> GetRemovable(bool showMounted = false,
bool showUsable = false);
QList<MythMediaDevice*> GetMedias(MythMediaType mediatype);
MythMediaDevice* GetMedia(const QString &path);
void MonitorRegisterExtensions(uint mediaType, const QString &extensions);
void RegisterMediaHandler(const QString &destination,
const QString &description,
const QString &key,
void (*callback) (MythMediaDevice*),
int mediaType,
const QString &extensions);
void JumpToMediaHandler(MythMediaDevice* pMedia);
// Plugins should use these if they need to access optical disks:
static QString defaultCDdevice();
static QString defaultVCDdevice();
static QString defaultDVDdevice();
static QString defaultCDWriter();
static QString defaultDVDWriter();
static void ejectOpticalDisc(void);
virtual QStringList GetCDROMBlockDevices(void) = 0;
public slots:
void mediaStatusChanged(MythMediaStatus oldStatus, MythMediaDevice* pMedia);
protected:
MediaMonitor(QObject *par, unsigned long interval, bool allowEject);
virtual ~MediaMonitor() {}
void AttemptEject(MythMediaDevice *device);
void CheckDevices(void);
virtual void CheckDeviceNotifications(void) {};
virtual bool AddDevice(MythMediaDevice* pDevice) = 0;
bool RemoveDevice(const QString &dev);
bool shouldIgnore(const MythMediaDevice *device);
bool eventFilter(QObject *obj, QEvent *event);
const QString listDevices(void);
static QString defaultDevice(const QString setting,
const QString label,
const char *hardCodedDefault);
MythMediaDevice *selectDrivePopup(const QString label,
bool showMounted = false,
bool showUsable = false);
protected:
QMutex m_DevicesLock;
QList<MythMediaDevice*> m_Devices;
QList<MythMediaDevice*> m_RemovedDevices;
QMap<MythMediaDevice*, int> m_UseCount;
// List of devices/mountpoints that the user doesn't want to monitor:
QStringList m_IgnoreList;
bool m_Active; ///< Was MonitorThread started?
MonitorThread *m_Thread;
unsigned long m_MonitorPollingInterval;
bool m_AllowEject;
QMap<QString, MHData> m_handlerMap; ///< Registered Media Handlers
static MediaMonitor *c_monitor;
};
#define REG_MEDIA_HANDLER(a, b, c, d, e, f) \
MediaMonitor::GetMediaMonitor()->RegisterMediaHandler(a, b, c, d, e, f)
#endif // MYTH_MEDIA_MONITOR_H