Skip to main content

image_capture_core/
camera_device.rs

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