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 QString& 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 QString& 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 }
O_NONBLOCK
#define O_NONBLOCK
Definition: compat.h:341
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:73
mythcdrom.h
MythCDROMDarwin::MythCDROMDarwin
MythCDROMDarwin(QObject *par, const QString &DevicePath, bool SuperMount, bool AllowEject)
Definition: mythcdrom-darwin.cpp:17
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythCDROMDarwin
Definition: mythcdrom-darwin.cpp:14
close
#define close
Definition: compat.h:43
mythlogging.h
MythCDROM
Definition: mythcdrom.h:6
mythcdrom-darwin.h
LOC
#define LOC
Definition: mythcdrom-darwin.cpp:12
MythCDROMDarwin::setDeviceSpeed
void setDeviceSpeed(const char *device, int speed) override
Definition: mythcdrom-darwin.cpp:30
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
GetMythCDROMDarwin
MythCDROM * GetMythCDROMDarwin(QObject *par, const QString &devicePath, bool SuperMount, bool AllowEject)
Definition: mythcdrom-darwin.cpp:24