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 }
MythCDROMFreeBSD(QObject *par, const char *DevicePath, bool SuperMount, bool AllowEject)
virtual bool closeDevice()
Definition: mythmedia.cpp:95
MythMediaError lock(void) override
virtual bool openDevice()
Definition: mythmedia.cpp:83
MythCDROM * GetMythCDROMFreeBSD(QObject *par, const char *devicePath, bool SuperMount, bool AllowEject)
MythMediaError eject(bool open_close=true) override
virtual MythMediaError unlock()
Definition: mythmedia.cpp:355
MythMediaError
Definition: mythmedia.h:39
virtual MythMediaError lock()
Definition: mythmedia.cpp:342
int m_DeviceHandle
A file handle for opening and closing the device, ioctls(), et c.
Definition: mythmedia.h:173
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool isMounted(bool bVerify=true)
Tells us if m_DevicePath is a mounted device.
Definition: mythmedia.cpp:363
MythMediaError testMedia(void) override
MythMediaError unlock(void) override
bool isDeviceOpen() const
Definition: mythmedia.cpp:107