Skip to main content

image_capture_core/
device.rs

1use bitflags::bitflags;
2use cocoa::base::{id, BOOL};
3use cocoa::foundation::NSUInteger;
4use core_graphics::image::CGImageRef;
5use libc::{c_int, c_longlong};
6use objc::*;
7
8/// Image Capture Device Types
9bitflags! {
10    pub struct ICDeviceType: NSUInteger {
11        /// Camera device.
12        const ICDeviceTypeCamera = 0x00000001;
13        /// Scanner device.
14        const ICDeviceTypeScanner = 0x00000002;
15    }
16}
17
18/// Image Capture Device Location Types
19bitflags! {
20    pub struct ICDeviceLocationType: NSUInteger {
21        /// Device found directly attached to the Macintosh via its USB or FireWire port.
22        const ICDeviceLocationTypeLocal = 0x00000100;
23        /// Device found over the network by searching for devices shared by other Macintosh hosts.
24        const ICDeviceLocationTypeShared = 0x00000200;
25        /// Device found over the network by searching for Bonjour services supported by Image Capture.
26        const ICDeviceLocationTypeBonjour = 0x00000400;
27        /// Device found as a paired Bluetooth device.
28        const ICDeviceLocationTypeBluetooth = 0x00000800;
29    }
30}
31
32/// Image Capture Device Type Mask
33bitflags! {
34    pub struct ICDeviceTypeMask: NSUInteger {
35        /// Mask to detect a camera device.
36        const ICDeviceTypeMaskCamera = 0x00000001;
37        /// Mask to detect a scanner device.
38        const ICDeviceTypeMaskScanner = 0x00000002;
39    }
40}
41
42/// Image Capture Device Location Type Mask
43bitflags! {
44    pub struct ICDeviceLocationTypeMask: NSUInteger {
45        /// Mask to detect a local (e.g., USB or FireWire) device.
46        const ICDeviceLocationTypeMaskLocal = 0x00000100;
47        /// Mask to detect a device by another Macintosh host.
48        const ICDeviceLocationTypeMaskShared = 0x00000200;
49        /// Mask to detect a network device that publishes a Bonjour service.
50        const ICDeviceLocationTypeMaskBonjour = 0x00000400;
51        /// Mask to detect paired Bluetooth device.
52        const ICDeviceLocationTypeMaskBluetooth = 0x00000800;
53        /// Mask to detect a remote (shared, Bonjour, Bluetooth) device.
54        const ICDeviceLocationTypeMaskRemote = 0x0000FE00;
55    }
56}
57
58pub trait ICDevice: Sized {
59    /// Get the delegate.
60    unsafe fn delegate(self) -> id;
61    /// Set the delegate.
62    unsafe fn setDelegate(self, delegate: id);
63    /// The type of the device as defined by ICDeviceType OR'd with its ICDeviceLocationType.
64    /// The type of this device can be obtained by AND'ing the value retuned by this property with an appropriate ICDeviceTypeMask.
65    /// The location type of this device can be obtained by AND'ing the value retuned by this property with an appropriate ICDeviceLocationTypeMask.
66    unsafe fn type_(self) -> ICDeviceType;
67    /// Name of the device as reported by the device module or by the device transport when a device module is not in control of this device.
68    /// This name may change if the device module overrides the default name of the device reported by the device's transport, or if the name of the filesystem volume mounted by the device is changed by the user.
69    unsafe fn name(self) -> id;
70    /// Icon image for the device.
71    unsafe fn icon(self) -> CGImageRef;
72    /// The capabilities of the device as reported by the device module.
73    unsafe fn capabilities(self) -> id;
74    /// Filesystem path of the device module that is associated with this device.
75    unsafe fn modulePath(self) -> id;
76    ///The bundle version of the device module associated with this device.
77    unsafe fn moduleVersion(self) -> id;
78    /// Indicates whether the device is a remote device published by Image Capture device sharing facility.
79    unsafe fn isRemote(self) -> BOOL;
80    ///  The transport type used by the device.
81    unsafe fn transportType(self) -> id;
82    /// The USB location ID of a USB device in the IOKit registry. This will be 0 for non-USB devices.
83    unsafe fn usbLocationID(self) -> c_int;
84    /// The USB product ID of a USB device in the IOKit registry. This will be 0 for non-USB devices.
85    unsafe fn usbProductID(self) -> c_int;
86    /// The USB vendor ID of a USB device in the IOKit registry. This will be 0 for non-USB devices.
87    unsafe fn usbVendorID(self) -> c_int;
88    /// The FireWire GUID of a FireWire device in the IOKit registry. This will be 0 for non-FireWire devices.
89    unsafe fn fwGUID(self) -> c_longlong;
90    /// The serial number of the device. This will be NULL if the device does not provide a serial number.
91    unsafe fn serialNumberString(self) -> id;
92    /// A non-localized location description string for the device.
93    unsafe fn locationDescription(self) -> id;
94    /// Indicates whether the device has an open session.
95    unsafe fn hasOpenSession(self) -> BOOL;
96    /// A string representation of the Universally Unique ID of the device.
97    unsafe fn UUIDString(self) -> id;
98    /// A string representation of the persistent ID of the device.
99    unsafe fn persistentIDString(self) -> id;
100    /// A string object with one of the ICButtonType values.
101    unsafe fn buttonPressed(self) -> id;
102    /// Filesystem path of an application that is to be automatically launched when this device is added.
103    unsafe fn autolaunchApplicationPath(self) -> id;
104    /// Set the filesystem path of an application that is to be automatically launched when this device is added.
105    unsafe fn setAutolaunchApplicationPath(self, autolaunchApplicationPath: id);
106    /// A mutable dictionary to store arbitrary key-value pairs associated with a device object. This can be used by view objects that bind to this object to store "house-keeping" information.
107    unsafe fn userData(self) -> id;
108    /// This message requests to open a session on the device.
109    unsafe fn requestOpenSession(self);
110    /// This message requests to close a previously opened session on this device.
111    unsafe fn requestCloseSession(self);
112    /// This message requests the device module in control of this device to yield control.
113    unsafe fn requestYield(self);
114    /// This method asynchronously sends an arbitrary message with optional data to a device.
115    unsafe fn requestSendMessage(
116        self,
117        messageCode: u64,
118        outData: id,
119        maxReturnedDataSize: u64,
120        sendMessageDelegate: id,
121        didSendMessageSelector: id,
122        contextInfo: id,
123    );
124    /// Eject the media if permitted by the device, or disconnect from a remote device.
125    unsafe fn requestEjectOrDisconnect(self);
126}
127
128impl ICDevice for id {
129    unsafe fn delegate(self) -> id {
130        msg_send![self, delegate]
131    }
132
133    unsafe fn setDelegate(self, delegate: id) {
134        msg_send![self, setDelegate: delegate]
135    }
136
137    unsafe fn type_(self) -> ICDeviceType {
138        msg_send![self, type]
139    }
140
141    unsafe fn name(self) -> id {
142        msg_send![self, name]
143    }
144
145    unsafe fn icon(self) -> CGImageRef {
146        msg_send![self, icon]
147    }
148
149    unsafe fn capabilities(self) -> id {
150        msg_send![self, capabilities]
151    }
152
153    unsafe fn modulePath(self) -> id {
154        msg_send![self, modulePath]
155    }
156
157    unsafe fn moduleVersion(self) -> id {
158        msg_send![self, moduleVersion]
159    }
160
161    unsafe fn isRemote(self) -> BOOL {
162        msg_send![self, isRemote]
163    }
164
165    unsafe fn transportType(self) -> id {
166        msg_send![self, transportType]
167    }
168
169    unsafe fn usbLocationID(self) -> c_int {
170        msg_send![self, usbLocationID]
171    }
172
173    unsafe fn usbProductID(self) -> c_int {
174        msg_send![self, usbProductID]
175    }
176
177    unsafe fn usbVendorID(self) -> c_int {
178        msg_send![self, usbVendorID]
179    }
180
181    unsafe fn fwGUID(self) -> c_longlong {
182        msg_send![self, fwGUID]
183    }
184
185    unsafe fn serialNumberString(self) -> id {
186        msg_send![self, serialNumberString]
187    }
188
189    unsafe fn locationDescription(self) -> id {
190        msg_send![self, locationDescription]
191    }
192
193    unsafe fn hasOpenSession(self) -> BOOL {
194        msg_send![self, hasOpenSession]
195    }
196
197    unsafe fn UUIDString(self) -> id {
198        msg_send![self, UUIDString]
199    }
200
201    unsafe fn persistentIDString(self) -> id {
202        msg_send![self, persistentIDString]
203    }
204
205    unsafe fn buttonPressed(self) -> id {
206        msg_send![self, buttonPressed]
207    }
208
209    unsafe fn autolaunchApplicationPath(self) -> id {
210        msg_send![self, autolaunchApplicationPath]
211    }
212
213    unsafe fn setAutolaunchApplicationPath(self, autolaunchApplicationPath: id) {
214        msg_send![
215            self,
216            setAutolaunchApplicationPath: autolaunchApplicationPath
217        ]
218    }
219
220    unsafe fn userData(self) -> id {
221        msg_send![self, userData]
222    }
223
224    unsafe fn requestOpenSession(self) {
225        msg_send![self, requestOpenSession]
226    }
227
228    unsafe fn requestCloseSession(self) {
229        msg_send![self, requestCloseSession]
230    }
231
232    unsafe fn requestYield(self) {
233        msg_send![self, requestYield]
234    }
235
236    unsafe fn requestSendMessage(
237        self,
238        messageCode: u64,
239        outData: id,
240        maxReturnedDataSize: u64,
241        sendMessageDelegate: id,
242        didSendMessageSelector: id,
243        contextInfo: id,
244    ) {
245        msg_send![self, requestSendMessage:messageCode outData:outData maxReturnedDataSize:maxReturnedDataSize sendMessageDelegate:sendMessageDelegate didSendMessageSelector:didSendMessageSelector contextInfo:contextInfo]
246    }
247
248    unsafe fn requestEjectOrDisconnect(self) {
249        msg_send![self, requestEjectOrDisconnect]
250    }
251}
252
253#[link(name = "ImageCaptureCore", kind = "framework")]
254extern "C" {
255    // Constants used to identify the transport type used by a device. (NSString *const)
256
257    /// Indicates that the device uses USB transport
258    pub static ICTransportTypeUSB: id;
259    /// Indicates that the device uses FireWire transport.
260    pub static ICTransportTypeFireWire: id;
261    /// Indicates that the device uses Bluetooth transport.
262    pub static ICTransportTypeBluetooth: id;
263    /// Indicates that the device uses TCP/IP transport. These devices are discovered using Bonjour.
264    pub static ICTransportTypeTCPIP: id;
265    /// Indicates that the device use mounts as a mass-storage volume.
266    pub static ICTransportTypeMassStorage: id;
267
268    // Constants used for device location description. (NSString *const)
269
270    /// This description is returned for locationDescription property of a device connected to a USB port.
271    pub static ICDeviceLocationDescriptionUSB: id;
272    /// This description is returned for locationDescription property of a device connected to a FireWire port.
273    pub static ICDeviceLocationDescriptionFireWire: id;
274    /// This description is returned for locationDescription property of a device connected via Bluetooth.
275    pub static ICDeviceLocationDescriptionBluetooth: id;
276    /// This description is returned for locationDescription property of a device that is mounted as a mass-storage volume.
277    pub static ICDeviceLocationDescriptionMassStorage: id;
278
279    // Constants used to identify button-press on a device.
280
281    ///Indicates that the "Scan" button on the device was pressed.
282    pub static ICButtonTypeScan: id;
283    /// Indicates that the "Mail" button on the device was pressed.
284    pub static ICButtonTypeMail: id;
285    /// Indicates that the "Copy" button on the device was pressed.
286    pub static ICButtonTypeCopy: id;
287    /// Indicates that the "Web" button on the device was pressed.
288    pub static ICButtonTypeWeb: id;
289    /// Indicates that the "Print" button on the device was pressed.
290    pub static ICButtonTypePrint: id;
291    /// Indicates that the "Transfer" button on the device was pressed.
292    pub static ICButtonTypeTransfer: id;
293
294    // Constants used for device status notifications.
295
296    ///Key for a non-localized notification string.
297    pub static ICStatusNotificationKey: id;
298    /// One of values defined in ICReturnCode.
299    pub static ICStatusCodeKey: id;
300    /// Key for a localized notification string.
301    pub static ICLocalizedStatusNotificationKey: id;
302
303    // Constants used to describe capabilities of a device
304
305    ///Indicates either the device is mounted as a mass-storage volume and can be ejected or the it is a remote device with an active connection that can be disconnected.
306    pub static ICDeviceCanEjectOrDisconnect: id;
307}