1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
use cocoa::base::{id, BOOL};
use cocoa::foundation::{NSTimeInterval, NSUInteger};
use libc::off_t;
use objc::*;
pub trait ICCameraDevice: Sized {
/// Indicates if the device has reported battery charge level.
unsafe fn batteryLevelAvailable(self) -> BOOL;
/// Indicates the battery charge level. Its value ranges from 0 to 100.
unsafe fn batteryLevel(self) -> NSUInteger;
/// Indicates the percentage of content cataloging completed on the device. Its value ranges from 0 to 100.
unsafe fn contentCatalogPercentCompleted(self) -> NSUInteger;
/// Contents of the camera. The structure of the elements in this array will reflect the folder structure of the storage reported by the camera.
/// Each item in this array will correspond to a storage on the camera.
unsafe fn contents(self) -> id;
/// The property mediaFiles represents all image, movie and audio files on the camera.
/// These files are returned as a single array without regard to the folder hierarchy used to store these files on the camera.
unsafe fn mediaFiles(self) -> id;
/// Indicates the time offset, in seconds, between the camera's clock and the computer's clock.
/// This value is positive if the camera's clock is ahead of the computer's clock.
/// This property should be ignored if the camera's capabilities property does not contain ICCameraDeviceCanSyncClock.
unsafe fn timeOffset(self) -> NSTimeInterval;
/// Set to YES if the device is made by Apple and is pass-coded locked and connected to an untrusted host.
unsafe fn isAccessRestrictedAppleDevice(self) -> BOOL;
/// Filesystem mount point for a device with transportType of ICTransportTypeMassStorage.
/// This will be NULL for all other devices.
unsafe fn mountPoint(self) -> id;
/// This property is set to YES when tethered capture is enabled on the device.
unsafe fn tetheredCaptureEnabled(self) -> BOOL;
/// This method returns an array of files on the camera of type fileType.
unsafe fn filesOfType(self, fileUTType: id) -> id;
/// Synchronize camera's clock with the computer's clock.
/// You should send this request only if the camera has the 'ICCameraDeviceCanSyncClock' capability.
unsafe fn requestSyncClock(self);
/// Send this message to enable tethered capture on the camera device if the camera has the 'ICCameraDeviceCanTakePicture' capability.
unsafe fn requestEnableTethering(self);
/// Send this message to disable tethered capture on the camera device if the camera has the 'ICCameraDeviceCanTakePicture' capability and if your process has already sent a 'requestEnableTethering' to it.
unsafe fn requestDisableTethering(self);
/// Capture a new image using the camera, the camera capabilities include 'ICCameraDeviceCanTakePicture'.
unsafe fn requestTakePicture(self);
/// Deletes files.
unsafe fn requestDeleteFiles(self, files: id);
/// Cancels the current delete operation started by sending a 'requestDeleteFiles:'.
unsafe fn cancelDelete(self);
/// Download a file from the camera. Please refer to the top of this header for information about the options.
unsafe fn requestDownloadFile(
self,
file: id,
options: id,
downloadDelegate: id,
didDownloadSelector: id,
contextInfo: id,
);
/// Cancels the current download operation.
unsafe fn cancelDownload(self);
/// Upload a file at fileURL to the camera. The options dictionary is not used in this version.
unsafe fn requestUploadFile(
self,
fileURL: id,
options: id,
uploadDelegate: id,
didUploadSelector: id,
contextInfo: id,
);
/// This method asynchronously reads data of a specified length from a specified offset.
unsafe fn requestReadDataFromFile(
self,
file: id,
atOffset: off_t,
length: off_t,
readDelegate: id,
didReadDataSelector: id,
contextInfo: id,
);
/// This method asynchronously sends a PTP command to a camera.
unsafe fn requestSendPTPCommand(
self,
command: id,
outData: id,
sendCommandDelegate: id,
didSendCommandSelector: id,
contextInfo: id,
);
}
impl ICCameraDevice for id {
unsafe fn batteryLevelAvailable(self) -> BOOL {
msg_send![self, batteryLevelAvailable]
}
unsafe fn batteryLevel(self) -> NSUInteger {
msg_send![self, batteryLevel]
}
unsafe fn contentCatalogPercentCompleted(self) -> NSUInteger {
msg_send![self, contentCatalogPercentCompleted]
}
unsafe fn contents(self) -> id {
msg_send![self, contents]
}
unsafe fn mediaFiles(self) -> id {
msg_send![self, mediaFiles]
}
unsafe fn timeOffset(self) -> NSTimeInterval {
msg_send![self, timeOffset]
}
unsafe fn isAccessRestrictedAppleDevice(self) -> BOOL {
msg_send![self, isAccessRestrictedAppleDevice]
}
unsafe fn mountPoint(self) -> id {
msg_send![self, mountPoint]
}
unsafe fn tetheredCaptureEnabled(self) -> BOOL {
msg_send![self, tetheredCaptureEnabled]
}
unsafe fn filesOfType(self, fileUTType: id) -> id {
msg_send![self, filesOfType: fileUTType]
}
unsafe fn requestSyncClock(self) {
msg_send![self, requestSyncClock]
}
unsafe fn requestEnableTethering(self) {
msg_send![self, requestEnableTethering]
}
unsafe fn requestDisableTethering(self) {
msg_send![self, requestDisableTethering]
}
unsafe fn requestTakePicture(self) {
msg_send![self, requestTakePicture]
}
unsafe fn requestDeleteFiles(self, files: id) {
msg_send![self, requestDeleteFiles: files]
}
unsafe fn cancelDelete(self) {
msg_send![self, cancelDelete]
}
unsafe fn requestDownloadFile(
self,
file: id,
options: id,
downloadDelegate: id,
didDownloadSelector: id,
contextInfo: id,
) {
msg_send![self, requestDownloadFile:file options:options downloadDelegate:downloadDelegate didDownloadSelector:didDownloadSelector contextInfo:contextInfo]
}
unsafe fn cancelDownload(self) {
msg_send![self, cancelDownload]
}
unsafe fn requestUploadFile(
self,
fileURL: id,
options: id,
uploadDelegate: id,
didUploadSelector: id,
contextInfo: id,
) {
msg_send![self, requestUploadFile:fileURL options:options uploadDelegate:uploadDelegate didUploadSelector:didUploadSelector contextInfo:contextInfo]
}
unsafe fn requestReadDataFromFile(
self,
file: id,
atOffset: off_t,
length: off_t,
readDelegate: id,
didReadDataSelector: id,
contextInfo: id,
) {
msg_send![self, requestReadDataFromFile:file atOffset:atOffset length:length readDelegate:readDelegate didReadDataSelector:didReadDataSelector contextInfo:contextInfo]
}
unsafe fn requestSendPTPCommand(
self,
command: id,
outData: id,
sendCommandDelegate: id,
didSendCommandSelector: id,
contextInfo: id,
) {
msg_send![self, requestSendPTPCommand:command outData:outData sendCommandDelegate:sendCommandDelegate didSendCommandSelector:didSendCommandSelector contextInfo:contextInfo]
}
}
#[link(name = "ImageCaptureCore", kind = "framework")]
extern "C" {
// Constants used to describe capabilities of a camera. (NSString *const)
/// Indicates that the device uses USB transport
pub static ICTransportTypeUSB: id;
/// Indicates that the camera can capture a picture while it is connected, if the client sends a 'requestTakePicture' message to it.
pub static ICCameraDeviceCanTakePicture: id;
/// Indicates that the camera can capture a picture while it is connected, if the user presses the shutter release on the camera.
pub static ICCameraDeviceCanTakePictureUsingShutterReleaseOnCamera: id;
/// Indicates that the camera can delete a file at a time while it is connected.
pub static ICCameraDeviceCanDeleteOneFile: id;
/// Indicates that the camera can delete all files in a single operation while it is connected.
pub static ICCameraDeviceCanDeleteAllFiles: id;
/// Indicates that the camera can synchronize its date and time with that of the host computer.
pub static ICCameraDeviceCanSyncClock: id;
/// Indicates that the host can upload files to the camera.
pub static ICCameraDeviceCanReceiveFile: id;
/// Indicates that the camera can accept PTP commands.
pub static ICCameraDeviceCanAcceptPTPCommands: id;
// Allowed keys in the options dictionary used when downloading a file from the camera
/// The value for this key should be an NSURL object referencing a writable directory. The downloaded files will be saved in that directory.
pub static ICDownloadsDirectoryURL: id;
/// The value for this key should be an NSString object containing the name to be used for the downloaded file.
pub static ICSaveAsFilename: id;
/// The value for this key will be an NSString object containing the actual name of the saved file. The options dictionary returned in didDownloadFile:error:options:contextInfo: will have this key.
pub static ICSavedFilename: id;
/// The value for this key will be an NSArray object containing names of files associated with the primary file that is downloaded. The options dictionary returned in didDownloadFile:error:options:contextInfo: may have this key.
pub static ICSavedAncillaryFiles: id;
/// The value for this key should be an NSNumber object representing a boolean value. If this value is YES, the downloaded file will overwrite an existing file with the same name and extension.
pub static ICOverwrite: id;
/// The value for this key should be an NSNumber object representing a boolean value. If this value is YES, the file will be deleted from the device after it is succcessfully downloaded.
pub static ICDeleteAfterSuccessfulDownload: id;
/// The value for this key should be an NSNumber object representing a boolean value. If this value is YES, all sidecar files will be downloaded along with the media file.
pub static ICDownloadSidecarFiles: id;
}