1 | #include "mythcdrom.h" |
---|
2 | #include <errno.h> |
---|
3 | #include <fcntl.h> |
---|
4 | #include "mythcontext.h" |
---|
5 | #include "mythmediamonitor-darwin.h" |
---|
6 | |
---|
7 | #define ASSUME_WANT_AUDIO 1 |
---|
8 | |
---|
9 | bool MythCDROMDarwin::openDevice() |
---|
10 | { |
---|
11 | // Sanity check |
---|
12 | if (isDeviceOpen()) |
---|
13 | return true; |
---|
14 | |
---|
15 | m_DeviceHandle = open(QString("/dev/r").append(m_DevicePath), O_RDONLY | O_NONBLOCK); |
---|
16 | |
---|
17 | return isDeviceOpen(); |
---|
18 | } |
---|
19 | |
---|
20 | MediaError MythCDROMDarwin::eject(bool open_close) |
---|
21 | { |
---|
22 | if (open_close) |
---|
23 | { |
---|
24 | VERBOSE(VB_IMPORTANT, "MythCDROMDarwin::eject - not yet implemented"); |
---|
25 | return MEDIAERR_UNSUPPORTED; |
---|
26 | } |
---|
27 | else |
---|
28 | return MEDIAERR_UNSUPPORTED; |
---|
29 | } |
---|
30 | |
---|
31 | bool MythCDROMDarwin::mediaChanged() |
---|
32 | { |
---|
33 | // Not implemented |
---|
34 | return false; |
---|
35 | } |
---|
36 | |
---|
37 | bool MythCDROMDarwin::checkOK() |
---|
38 | { |
---|
39 | // Not implemented |
---|
40 | return true; |
---|
41 | } |
---|
42 | |
---|
43 | // Helper function, perform a sanity check on the device |
---|
44 | MediaError MythCDROMDarwin::testMedia() |
---|
45 | { |
---|
46 | // cout << "MythCDROMDarwin::testMedia - "; |
---|
47 | bool OpenedHere = false; |
---|
48 | if (!isDeviceOpen()) |
---|
49 | { |
---|
50 | // cout << "Device is not open - "; |
---|
51 | if (!openDevice()) |
---|
52 | { |
---|
53 | // cout << "failed to open device - "; |
---|
54 | if (errno == EBUSY) |
---|
55 | { |
---|
56 | // cout << "errno == EBUSY" << endl; |
---|
57 | return isMounted(true) ? MEDIAERR_OK : MEDIAERR_FAILED; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | return MEDIAERR_FAILED; |
---|
62 | } |
---|
63 | } |
---|
64 | // cout << "Opened it - "; |
---|
65 | OpenedHere = true; |
---|
66 | } |
---|
67 | |
---|
68 | // Be nice and close the device if we opened it, otherwise it might be locked when the user doesn't want it to be. |
---|
69 | if (OpenedHere) |
---|
70 | closeDevice(); |
---|
71 | |
---|
72 | return MEDIAERR_OK; |
---|
73 | } |
---|
74 | |
---|
75 | MediaStatus MythCDROMDarwin::checkMedia() |
---|
76 | { |
---|
77 | if (m_Status == MEDIASTAT_UNKNOWN) |
---|
78 | { |
---|
79 | // Set our media type |
---|
80 | m_MediaType = MediaTypeForBSDName(m_DevicePath); |
---|
81 | // Update the DVD device path setting (used by the DVD Player app) - only update for the session, |
---|
82 | // on Mac OS X device paths are very changeable. |
---|
83 | if (m_MediaType == MEDIATYPE_DVD) |
---|
84 | { |
---|
85 | gContext->OverrideSettingForSession("DVDDeviceLocation", QString("/dev/r").append(m_DevicePath)); |
---|
86 | } |
---|
87 | // Pretend we're not mounted to setStatus emits the signal |
---|
88 | m_Status = MEDIASTAT_NOTMOUNTED; |
---|
89 | return setStatus(MEDIASTAT_USEABLE, false); |
---|
90 | } |
---|
91 | else |
---|
92 | return m_Status; |
---|
93 | } |
---|
94 | |
---|
95 | MediaError MythCDROMDarwin::lock() |
---|
96 | { |
---|
97 | MediaError ret = MythMediaDevice::lock(); |
---|
98 | // if (ret == MEDIAERR_OK) |
---|
99 | // ioctl(m_DeviceHandle, CDIOCPREVENT); |
---|
100 | |
---|
101 | return ret; |
---|
102 | } |
---|
103 | |
---|
104 | MediaError MythCDROMDarwin::unlock() |
---|
105 | { |
---|
106 | if (isDeviceOpen() || openDevice()) |
---|
107 | { |
---|
108 | //cout << "Unlocking CDROM door" << endl; |
---|
109 | // ioctl(m_DeviceHandle, CDIOCALLOW); |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | VERBOSE(VB_GENERAL, "Failed to open device, CDROM try will remain " |
---|
114 | "locked."); |
---|
115 | } |
---|
116 | |
---|
117 | return MythMediaDevice::unlock(); |
---|
118 | } |
---|