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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
use bitflags::bitflags;
use cocoa::base::{id, BOOL};
use cocoa::foundation::NSUInteger;
use core_graphics::image::CGImageRef;
use libc::{c_int, c_longlong};
use objc::*;
/// Image Capture Device Types
bitflags! {
pub struct ICDeviceType: NSUInteger {
/// Camera device.
const ICDeviceTypeCamera = 0x00000001;
/// Scanner device.
const ICDeviceTypeScanner = 0x00000002;
}
}
/// Image Capture Device Location Types
bitflags! {
pub struct ICDeviceLocationType: NSUInteger {
/// Device found directly attached to the Macintosh via its USB or FireWire port.
const ICDeviceLocationTypeLocal = 0x00000100;
/// Device found over the network by searching for devices shared by other Macintosh hosts.
const ICDeviceLocationTypeShared = 0x00000200;
/// Device found over the network by searching for Bonjour services supported by Image Capture.
const ICDeviceLocationTypeBonjour = 0x00000400;
/// Device found as a paired Bluetooth device.
const ICDeviceLocationTypeBluetooth = 0x00000800;
}
}
/// Image Capture Device Type Mask
bitflags! {
pub struct ICDeviceTypeMask: NSUInteger {
/// Mask to detect a camera device.
const ICDeviceTypeMaskCamera = 0x00000001;
/// Mask to detect a scanner device.
const ICDeviceTypeMaskScanner = 0x00000002;
}
}
/// Image Capture Device Location Type Mask
bitflags! {
pub struct ICDeviceLocationTypeMask: NSUInteger {
/// Mask to detect a local (e.g., USB or FireWire) device.
const ICDeviceLocationTypeMaskLocal = 0x00000100;
/// Mask to detect a device by another Macintosh host.
const ICDeviceLocationTypeMaskShared = 0x00000200;
/// Mask to detect a network device that publishes a Bonjour service.
const ICDeviceLocationTypeMaskBonjour = 0x00000400;
/// Mask to detect paired Bluetooth device.
const ICDeviceLocationTypeMaskBluetooth = 0x00000800;
/// Mask to detect a remote (shared, Bonjour, Bluetooth) device.
const ICDeviceLocationTypeMaskRemote = 0x0000FE00;
}
}
pub trait ICDevice: Sized {
/// Get the delegate.
unsafe fn delegate(self) -> id;
/// Set the delegate.
unsafe fn setDelegate(self, delegate: id);
/// The type of the device as defined by ICDeviceType OR'd with its ICDeviceLocationType.
/// The type of this device can be obtained by AND'ing the value retuned by this property with an appropriate ICDeviceTypeMask.
/// The location type of this device can be obtained by AND'ing the value retuned by this property with an appropriate ICDeviceLocationTypeMask.
unsafe fn type_(self) -> ICDeviceType;
/// 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.
/// 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.
unsafe fn name(self) -> id;
/// Icon image for the device.
unsafe fn icon(self) -> CGImageRef;
/// The capabilities of the device as reported by the device module.
unsafe fn capabilities(self) -> id;
/// Filesystem path of the device module that is associated with this device.
unsafe fn modulePath(self) -> id;
///The bundle version of the device module associated with this device.
unsafe fn moduleVersion(self) -> id;
/// Indicates whether the device is a remote device published by Image Capture device sharing facility.
unsafe fn isRemote(self) -> BOOL;
/// The transport type used by the device.
unsafe fn transportType(self) -> id;
/// The USB location ID of a USB device in the IOKit registry. This will be 0 for non-USB devices.
unsafe fn usbLocationID(self) -> c_int;
/// The USB product ID of a USB device in the IOKit registry. This will be 0 for non-USB devices.
unsafe fn usbProductID(self) -> c_int;
/// The USB vendor ID of a USB device in the IOKit registry. This will be 0 for non-USB devices.
unsafe fn usbVendorID(self) -> c_int;
/// The FireWire GUID of a FireWire device in the IOKit registry. This will be 0 for non-FireWire devices.
unsafe fn fwGUID(self) -> c_longlong;
/// The serial number of the device. This will be NULL if the device does not provide a serial number.
unsafe fn serialNumberString(self) -> id;
/// A non-localized location description string for the device.
unsafe fn locationDescription(self) -> id;
/// Indicates whether the device has an open session.
unsafe fn hasOpenSession(self) -> BOOL;
/// A string representation of the Universally Unique ID of the device.
unsafe fn UUIDString(self) -> id;
/// A string representation of the persistent ID of the device.
unsafe fn persistentIDString(self) -> id;
/// A string object with one of the ICButtonType values.
unsafe fn buttonPressed(self) -> id;
/// Filesystem path of an application that is to be automatically launched when this device is added.
unsafe fn autolaunchApplicationPath(self) -> id;
/// Set the filesystem path of an application that is to be automatically launched when this device is added.
unsafe fn setAutolaunchApplicationPath(self, autolaunchApplicationPath: id);
/// 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.
unsafe fn userData(self) -> id;
/// This message requests to open a session on the device.
unsafe fn requestOpenSession(self);
/// This message requests to close a previously opened session on this device.
unsafe fn requestCloseSession(self);
/// This message requests the device module in control of this device to yield control.
unsafe fn requestYield(self);
/// This method asynchronously sends an arbitrary message with optional data to a device.
unsafe fn requestSendMessage(
self,
messageCode: u64,
outData: id,
maxReturnedDataSize: u64,
sendMessageDelegate: id,
didSendMessageSelector: id,
contextInfo: id,
);
/// Eject the media if permitted by the device, or disconnect from a remote device.
unsafe fn requestEjectOrDisconnect(self);
}
impl ICDevice for id {
unsafe fn delegate(self) -> id {
msg_send![self, delegate]
}
unsafe fn setDelegate(self, delegate: id) {
msg_send![self, setDelegate: delegate]
}
unsafe fn type_(self) -> ICDeviceType {
msg_send![self, type]
}
unsafe fn name(self) -> id {
msg_send![self, name]
}
unsafe fn icon(self) -> CGImageRef {
msg_send![self, icon]
}
unsafe fn capabilities(self) -> id {
msg_send![self, capabilities]
}
unsafe fn modulePath(self) -> id {
msg_send![self, modulePath]
}
unsafe fn moduleVersion(self) -> id {
msg_send![self, moduleVersion]
}
unsafe fn isRemote(self) -> BOOL {
msg_send![self, isRemote]
}
unsafe fn transportType(self) -> id {
msg_send![self, transportType]
}
unsafe fn usbLocationID(self) -> c_int {
msg_send![self, usbLocationID]
}
unsafe fn usbProductID(self) -> c_int {
msg_send![self, usbProductID]
}
unsafe fn usbVendorID(self) -> c_int {
msg_send![self, usbVendorID]
}
unsafe fn fwGUID(self) -> c_longlong {
msg_send![self, fwGUID]
}
unsafe fn serialNumberString(self) -> id {
msg_send![self, serialNumberString]
}
unsafe fn locationDescription(self) -> id {
msg_send![self, locationDescription]
}
unsafe fn hasOpenSession(self) -> BOOL {
msg_send![self, hasOpenSession]
}
unsafe fn UUIDString(self) -> id {
msg_send![self, UUIDString]
}
unsafe fn persistentIDString(self) -> id {
msg_send![self, persistentIDString]
}
unsafe fn buttonPressed(self) -> id {
msg_send![self, buttonPressed]
}
unsafe fn autolaunchApplicationPath(self) -> id {
msg_send![self, autolaunchApplicationPath]
}
unsafe fn setAutolaunchApplicationPath(self, autolaunchApplicationPath: id) {
msg_send![
self,
setAutolaunchApplicationPath: autolaunchApplicationPath
]
}
unsafe fn userData(self) -> id {
msg_send![self, userData]
}
unsafe fn requestOpenSession(self) {
msg_send![self, requestOpenSession]
}
unsafe fn requestCloseSession(self) {
msg_send![self, requestCloseSession]
}
unsafe fn requestYield(self) {
msg_send![self, requestYield]
}
unsafe fn requestSendMessage(
self,
messageCode: u64,
outData: id,
maxReturnedDataSize: u64,
sendMessageDelegate: id,
didSendMessageSelector: id,
contextInfo: id,
) {
msg_send![self, requestSendMessage:messageCode outData:outData maxReturnedDataSize:maxReturnedDataSize sendMessageDelegate:sendMessageDelegate didSendMessageSelector:didSendMessageSelector contextInfo:contextInfo]
}
unsafe fn requestEjectOrDisconnect(self) {
msg_send![self, requestEjectOrDisconnect]
}
}
#[link(name = "ImageCaptureCore", kind = "framework")]
extern "C" {
// Constants used to identify the transport type used by a device. (NSString *const)
/// Indicates that the device uses USB transport
pub static ICTransportTypeUSB: id;
/// Indicates that the device uses FireWire transport.
pub static ICTransportTypeFireWire: id;
/// Indicates that the device uses Bluetooth transport.
pub static ICTransportTypeBluetooth: id;
/// Indicates that the device uses TCP/IP transport. These devices are discovered using Bonjour.
pub static ICTransportTypeTCPIP: id;
/// Indicates that the device use mounts as a mass-storage volume.
pub static ICTransportTypeMassStorage: id;
// Constants used for device location description. (NSString *const)
/// This description is returned for locationDescription property of a device connected to a USB port.
pub static ICDeviceLocationDescriptionUSB: id;
/// This description is returned for locationDescription property of a device connected to a FireWire port.
pub static ICDeviceLocationDescriptionFireWire: id;
/// This description is returned for locationDescription property of a device connected via Bluetooth.
pub static ICDeviceLocationDescriptionBluetooth: id;
/// This description is returned for locationDescription property of a device that is mounted as a mass-storage volume.
pub static ICDeviceLocationDescriptionMassStorage: id;
// Constants used to identify button-press on a device.
///Indicates that the "Scan" button on the device was pressed.
pub static ICButtonTypeScan: id;
/// Indicates that the "Mail" button on the device was pressed.
pub static ICButtonTypeMail: id;
/// Indicates that the "Copy" button on the device was pressed.
pub static ICButtonTypeCopy: id;
/// Indicates that the "Web" button on the device was pressed.
pub static ICButtonTypeWeb: id;
/// Indicates that the "Print" button on the device was pressed.
pub static ICButtonTypePrint: id;
/// Indicates that the "Transfer" button on the device was pressed.
pub static ICButtonTypeTransfer: id;
// Constants used for device status notifications.
///Key for a non-localized notification string.
pub static ICStatusNotificationKey: id;
/// One of values defined in ICReturnCode.
pub static ICStatusCodeKey: id;
/// Key for a localized notification string.
pub static ICLocalizedStatusNotificationKey: id;
// Constants used to describe capabilities of a device
///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.
pub static ICDeviceCanEjectOrDisconnect: id;
}