Skip to main content

image_capture_core/
scanner_device.rs

1use cocoa::base::id;
2use objc::*;
3
4/// Transfer mode to be used when transferring scan data from the scanner functional unit.
5#[repr(u64)]
6#[derive(Clone, Copy, Debug, PartialEq)]
7pub enum ICScannerTransferMode {
8    /// Save the scan as a file.
9    ICScannerTransferModeFileBased = 0,
10    /// Transfer the scan as data.
11    ICScannerTransferModeMemoryBased = 1,
12}
13
14pub trait ICScannerDevice: Sized {
15    /// An array of functional unit types available on this scanner device.
16    /// This is an array of NSNumber objects whose values are of type ICScannerFunctionalUnitType.
17    unsafe fn availableFunctionalUnitTypes(self) -> id;
18    /// The currently selected functional unit on the scanner device.
19    unsafe fn selectedFunctionalUnit(self) -> id;
20    /// The transfer mode for scanned document.
21    unsafe fn transferMode(self) -> ICScannerTransferMode;
22    /// Set the transfer mode for scanned document.
23    unsafe fn setTransferMode(self, transferMode: ICScannerTransferMode);
24    /// The total maximum band size requested when performing a ICScannerTransferModeMemoryBased.
25    unsafe fn maxMemoryBandSize(self) -> u32;
26    /// Set the total maximum band size requested when performing a ICScannerTransferModeMemoryBased.
27    unsafe fn setMaxMemoryBandSize(self, maxMemoryBandSize: u32);
28    /// The downloads directory.
29    unsafe fn downloadsDirectory(self) -> id;
30    /// Set the downloads directory.
31    unsafe fn setDownloadsDirectory(self, downloadsDirectory: id);
32    /// The document name.
33    unsafe fn documentName(self) -> id;
34    /// Set the document name.
35    unsafe fn setDocumentName(self, documentName: id);
36    /// The document UTI.
37    /// Currently supported UTIs are: kUTTypeJPEG, kUTTypeJPEG2000, kUTTypeTIFF, kUTTypePNG etc.
38    unsafe fn documentUTI(self) -> id;
39    /// Set the document UTI.
40    unsafe fn setDocumentUTI(self, documentUTI: id);
41    /// If the device is protected, instead of prompting the user for a username, this property can be set to default to a specific username as a convience.
42    /// The value will persist until reset by setting it to nil.
43    unsafe fn defaultUsername(self) -> id;
44    /// Set the default username
45    unsafe fn setDefaultUsername(self, defaultUsername: id);
46    /// This message requests to open a session on the protected device with the authorized username and passcode.
47    /// If the device reports back a failure of credentials, they can be provided here for the launch.
48    /// A client MUST open a session on a device in order to use the device.
49    unsafe fn requestOpenSessionWithCredentials(self, username: id, password: id);
50    /// Requests the scanner device to select a functional unit.
51    unsafe fn requestSelectFunctionalUnit(self, type_: id);
52    /// Starts an overview scan on selectedFunctionalUnit.
53    unsafe fn requestOverviewScan(self);
54    /// Starts a scan on selectedFunctionalUnit.
55    unsafe fn requestScan(self);
56    /// cancelScan
57    unsafe fn cancelScan(self);
58}
59
60impl ICScannerDevice for id {
61    unsafe fn availableFunctionalUnitTypes(self) -> id {
62        msg_send![self, availableFunctionalUnitTypes]
63    }
64
65    unsafe fn selectedFunctionalUnit(self) -> id {
66        msg_send![self, selectedFunctionalUnit]
67    }
68
69    unsafe fn transferMode(self) -> ICScannerTransferMode {
70        msg_send![self, transferMode]
71    }
72
73    unsafe fn setTransferMode(self, transferMode: ICScannerTransferMode) {
74        msg_send![self, setTransferMode: transferMode]
75    }
76
77    unsafe fn maxMemoryBandSize(self) -> u32 {
78        msg_send![self, maxMemoryBandSize]
79    }
80
81    unsafe fn setMaxMemoryBandSize(self, maxMemoryBandSize: u32) {
82        msg_send![self, setMaxMemoryBandSize: maxMemoryBandSize]
83    }
84
85    unsafe fn downloadsDirectory(self) -> id {
86        msg_send![self, downloadsDirectory]
87    }
88
89    unsafe fn setDownloadsDirectory(self, downloadsDirectory: id) {
90        msg_send![self, setDownloadsDirectory: downloadsDirectory]
91    }
92
93    unsafe fn documentName(self) -> id {
94        msg_send![self, documentName]
95    }
96
97    unsafe fn setDocumentName(self, documentName: id) {
98        msg_send![self, setDocumentName: documentName]
99    }
100
101    unsafe fn documentUTI(self) -> id {
102        msg_send![self, documentUTI]
103    }
104
105    unsafe fn setDocumentUTI(self, documentUTI: id) {
106        msg_send![self, setDocumentUTI: documentUTI]
107    }
108
109    unsafe fn defaultUsername(self) -> id {
110        msg_send![self, defaultUsername]
111    }
112
113    unsafe fn setDefaultUsername(self, defaultUsername: id) {
114        msg_send![self, setDefaultUsername: defaultUsername]
115    }
116
117    unsafe fn requestOpenSessionWithCredentials(self, username: id, password: id) {
118        msg_send![self, requestOpenSessionWithCredentials:username password:password]
119    }
120
121    unsafe fn requestSelectFunctionalUnit(self, type_: id) {
122        msg_send![self, requestSelectFunctionalUnit: type_]
123    }
124
125    unsafe fn requestOverviewScan(self) {
126        msg_send![self, requestOverviewScan]
127    }
128
129    unsafe fn requestScan(self) {
130        msg_send![self, requestScan]
131    }
132
133    unsafe fn cancelScan(self) {
134        msg_send![self, cancelScan]
135    }
136}
137
138#[link(name = "ImageCaptureCore", kind = "framework")]
139extern "C" {
140    // Constants used for device status notifications.
141
142    /// A non-localized notification string to indicate that the scanner is warming up.
143    pub static ICScannerStatusWarmingUp: id;
144    /// A non-localized notification string to indicate that the scanner has warmed up.
145    pub static ICScannerStatusWarmUpDone: id;
146    /// A non-localized notification string to indicate that the scanner is requesting an overview scan to be performed.
147    pub static ICScannerStatusRequestsOverviewScan: id;
148}