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 {
14 public:
15  MythCDROMFreeBSD(QObject* par, const char* 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 
26 MythCDROM *GetMythCDROMFreeBSD(QObject* par, const char* 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
41  return MEDIAERR_UNSUPPORTED;
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)
66  closeDevice();
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 
95  return MythMediaDevice::unlock();
96 }
MythMediaDevice::m_deviceHandle
int m_deviceHandle
A file handle for opening and closing the device, ioctls(), et c.
Definition: mythmedia.h:175
MythMediaDevice::isDeviceOpen
bool isDeviceOpen() const
Definition: mythmedia.cpp:107
mythcdrom.h
MythCDROMFreeBSD::eject
MythMediaError eject(bool open_close=true) override
Definition: mythcdrom-freebsd.cpp:32
MythMediaDevice::openDevice
virtual bool openDevice()
Definition: mythmedia.cpp:83
GetMythCDROMFreeBSD
MythCDROM * GetMythCDROMFreeBSD(QObject *par, const char *devicePath, bool SuperMount, bool AllowEject)
Definition: mythcdrom-freebsd.cpp:26
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythcdrom-freebsd.h
MythMediaDevice::isMounted
bool isMounted(bool bVerify=true)
Tells us if m_devicePath is a mounted device.
Definition: mythmedia.cpp:359
mythlogging.h
MythMediaDevice::unlock
virtual MythMediaError unlock()
Definition: mythmedia.cpp:351
MythCDROM
Definition: mythcdrom.h:7
MythMediaDevice::lock
virtual MythMediaError lock()
Definition: mythmedia.cpp:338
MythCDROMFreeBSD::testMedia
MythMediaError testMedia(void) override
Definition: mythcdrom-freebsd.cpp:45
MythCDROMFreeBSD::unlock
MythMediaError unlock(void) override
Definition: mythcdrom-freebsd.cpp:80
MythCDROMFreeBSD
Definition: mythcdrom-freebsd.cpp:13
MythCDROMFreeBSD::MythCDROMFreeBSD
MythCDROMFreeBSD(QObject *par, const char *DevicePath, bool SuperMount, bool AllowEject)
Definition: mythcdrom-freebsd.cpp:15
MEDIAERR_FAILED
@ MEDIAERR_FAILED
Definition: mythmedia.h:41
MythMediaError
MythMediaError
Definition: mythmedia.h:39
MEDIAERR_OK
@ MEDIAERR_OK
Definition: mythmedia.h:40
MEDIAERR_UNSUPPORTED
@ MEDIAERR_UNSUPPORTED
Definition: mythmedia.h:42
MythMediaDevice::closeDevice
virtual bool closeDevice()
Definition: mythmedia.cpp:95
MythCDROMFreeBSD::lock
MythMediaError lock(void) override
Definition: mythcdrom-freebsd.cpp:71