MythTV  master
mythcdrom-darwin.cpp
Go to the documentation of this file.
1 #include <cerrno>
2 #include <sys/fcntl.h>
3 #include <unistd.h> // for close definition
4 
5 #include <IOKit/storage/IOCDMediaBSDClient.h>
6 #include <IOKit/storage/IODVDMediaBSDClient.h>
7 
8 #include "mythcdrom.h"
9 #include "mythcdrom-darwin.h"
10 #include "mythlogging.h"
11 
12 #define LOC QString("MythCDROMDarwin:")
13 
15 {
16 public:
17  MythCDROMDarwin(QObject* par, const char* DevicePath,
18  bool SuperMount, bool AllowEject):
19  MythCDROM(par, DevicePath, SuperMount, AllowEject) {};
20 
21  void setDeviceSpeed(const char *device, int speed) override; // MythMediaDevice
22 };
23 
24 MythCDROM *GetMythCDROMDarwin(QObject* par, const char* devicePath,
25  bool SuperMount, bool AllowEject)
26 {
27  return new MythCDROMDarwin(par, devicePath, SuperMount, AllowEject);
28 }
29 
30 void MythCDROMDarwin::setDeviceSpeed(const char *device, int speed)
31 {
32  int fd;
33  QString raw = device;
34  uint16_t spd = speed;
35 
36 
37  fd = open(raw.toLocal8Bit().constData(), O_RDONLY | O_NONBLOCK);
38  if (fd == -1)
39  {
40  LOG(VB_MEDIA, LOG_ERR, LOC +
41  "setDeviceSpeed() can't open drive " + raw);
42  return;
43  }
44 
45  if (ioctl(fd, DKIOCCDSETSPEED, &spd) == -1 &&
46  ioctl(fd, DKIOCDVDSETSPEED, &spd) == -1)
47  {
48  LOG(VB_MEDIA, LOG_ERR, LOC + "setDeviceSpeed() failed: " + ENO);
49  close(fd);
50  return;
51  }
52 
53  LOG(VB_MEDIA, LOG_INFO, LOC + "setDeviceSpeed() - CD/DVD speed now " +
54  QString::number(spd));
55 
56  close(fd);
57 }
#define O_NONBLOCK
Definition: mythmedia.cpp:25
MythCDROM * GetMythCDROMDarwin(QObject *par, const char *devicePath, bool SuperMount, bool AllowEject)
#define LOC
MythCDROMDarwin(QObject *par, const char *DevicePath, bool SuperMount, bool AllowEject)
#define close
Definition: compat.h:16
unsigned short uint16_t
Definition: iso6937tables.h:1
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:99
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void setDeviceSpeed(const char *device, int speed) override