MythTV master
mythcdrom-freebsd.cpp
Go to the documentation of this file.
1#include <cerrno>
2#include <sys/cdio.h>
3#include <sys/ioctl.h>
4
5#include "mythcdrom.h"
6#include "mythcdrom-freebsd.h"
7#include "mythlogging.h"
8
9
10#define ASSUME_WANT_AUDIO 1
11
13{
14public:
15 MythCDROMFreeBSD(QObject* par, const QString& DevicePath, bool SuperMount,
16 bool AllowEject):
17 MythCDROM(par, DevicePath, SuperMount, AllowEject) {
18 }
19
20 MythMediaError testMedia(void) override; // MythMediaDevice
21 MythMediaError eject(bool open_close = true) override; // MythMediaDevice
22 MythMediaError lock(void) override; // MythMediaDevice
23 MythMediaError unlock(void) override; // MythMediaDevice
24};
25
26MythCDROM *GetMythCDROMFreeBSD(QObject* par, const QString& devicePath,
27 bool SuperMount, bool AllowEject)
28{
29 return new MythCDROMFreeBSD(par, devicePath, SuperMount, AllowEject);
30}
31
33{
34 if (!isDeviceOpen())
35 openDevice();
36
37 if (open_close)
38 return (ioctl(m_deviceHandle, CDIOCEJECT) == 0) ? MEDIAERR_OK :
40 else
42}
43
44// Helper function, perform a sanity check on the device
46{
47 bool OpenedHere = false;
48 if (!isDeviceOpen())
49 {
50 if (!openDevice())
51 {
52 if (errno == EBUSY)
53 {
55 }
56 else
57 {
58 return MEDIAERR_FAILED;
59 }
60 }
61 OpenedHere = true;
62 }
63
64 // Be nice and close the device if we opened it, otherwise it might be locked when the user doesn't want it to be.
65 if (OpenedHere)
67
68 return MEDIAERR_OK;
69}
70
72{
74 if (ret == MEDIAERR_OK)
75 ioctl(m_deviceHandle, CDIOCPREVENT);
76
77 return ret;
78}
79
81{
82 if (isDeviceOpen() || openDevice())
83 {
84#if 0
85 LOG(VB_GENERAL, LOG_DEBUG, "Unlocking CDROM door");
86#endif
87 ioctl(m_deviceHandle, CDIOCALLOW);
88 }
89 else
90 {
91 LOG(VB_GENERAL, LOG_INFO, "Failed to open device, CDROM tray will "
92 "remain locked.");
93 }
94
96}
MythMediaError unlock(void) override
MythMediaError testMedia(void) override
MythMediaError lock(void) override
MythCDROMFreeBSD(QObject *par, const QString &DevicePath, bool SuperMount, bool AllowEject)
MythMediaError eject(bool open_close=true) override
virtual bool closeDevice()
Definition: mythmedia.cpp:96
virtual MythMediaError lock()
Definition: mythmedia.cpp:339
virtual MythMediaError unlock()
Definition: mythmedia.cpp:352
int m_deviceHandle
A file handle for opening and closing the device, ioctls(), et c.
Definition: mythmedia.h:175
bool isDeviceOpen() const
Definition: mythmedia.cpp:108
virtual bool openDevice()
Definition: mythmedia.cpp:84
bool isMounted(bool bVerify=true)
Tells us if m_devicePath is a mounted device.
Definition: mythmedia.cpp:360
MythCDROM * GetMythCDROMFreeBSD(QObject *par, const QString &devicePath, bool SuperMount, bool AllowEject)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMediaError
Definition: mythmedia.h:39
@ MEDIAERR_UNSUPPORTED
Definition: mythmedia.h:42
@ MEDIAERR_OK
Definition: mythmedia.h:40
@ MEDIAERR_FAILED
Definition: mythmedia.h:41