objc2_file_provider/generated/NSFileProviderEnumerating.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// A user-defined chunk of data that defines a starting point to enumerate changes
11/// from.
12///
13/// The size of a sync anchor should not exceed a combined 500 bytes.
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileprovidersyncanchor?language=objc)
16// NS_TYPED_EXTENSIBLE_ENUM
17pub type NSFileProviderSyncAnchor = NSData;
18
19/// A user- or system-defined chunk of data that defines a page to continue the
20/// enumeration from. Initial enumeration is started from one of the below
21/// system-defined pages.
22///
23/// The size of a page should not exceed 500 bytes.
24///
25/// See also [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderpage?language=objc)
26// NS_TYPED_EXTENSIBLE_ENUM
27pub type NSFileProviderPage = NSData;
28
29extern "C" {
30 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderinitialpagesortedbydate?language=objc)
31 pub static NSFileProviderInitialPageSortedByDate: &'static NSFileProviderPage;
32}
33
34extern "C" {
35 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderinitialpagesortedbyname?language=objc)
36 pub static NSFileProviderInitialPageSortedByName: &'static NSFileProviderPage;
37}
38
39extern_protocol!(
40 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderenumerationobserver?language=objc)
41 pub unsafe trait NSFileProviderEnumerationObserver: NSObjectProtocol {
42 #[cfg(feature = "NSFileProviderItem")]
43 #[unsafe(method(didEnumerateItems:))]
44 #[unsafe(method_family = none)]
45 unsafe fn didEnumerateItems(
46 &self,
47 updated_items: &NSArray<ProtocolObject<dyn NSFileProviderItemProtocol>>,
48 );
49
50 /// Call this method after enumerating a full page of items. If you set a non-nil
51 /// nextPage, -[NSFileProviderEnumerator enumerateItemsToObserver:startingAtPage:]
52 /// might be called with nextPage to enumerate more items. This is typically
53 /// driven by the user scrolling a UIDocumentBrowserViewController presenting a
54 /// directory containing more child items that would fit in the view.
55 ///
56 /// Page data is limited to 500 bytes. Setting a larger nextPage interrupts the
57 /// enumeration.
58 #[unsafe(method(finishEnumeratingUpToPage:))]
59 #[unsafe(method_family = none)]
60 unsafe fn finishEnumeratingUpToPage(&self, next_page: Option<&NSFileProviderPage>);
61
62 #[unsafe(method(finishEnumeratingWithError:))]
63 #[unsafe(method_family = none)]
64 unsafe fn finishEnumeratingWithError(&self, error: &NSError);
65
66 /// Size of the page suggested by the system for better performance.
67 ///
68 /// The system will set that property to the value it considers is best suited for the current enumeration. The
69 /// system can enumerate a container in various cases (container presenter in the UI, file opened in an application,
70 /// materialization of the folder by the system, ...). Each case has its own performance profile.
71 ///
72 /// By taking into account the suggested size, the enumeration will guarantee the best user experience possible. The
73 /// system enforces a maximum of 100 times the suggested size.
74 #[optional]
75 #[unsafe(method(suggestedPageSize))]
76 #[unsafe(method_family = none)]
77 unsafe fn suggestedPageSize(&self) -> NSInteger;
78 }
79);
80
81extern_protocol!(
82 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderchangeobserver?language=objc)
83 pub unsafe trait NSFileProviderChangeObserver: NSObjectProtocol {
84 #[cfg(feature = "NSFileProviderItem")]
85 /// Send updates to existing items, or insert new items.
86 #[unsafe(method(didUpdateItems:))]
87 #[unsafe(method_family = none)]
88 unsafe fn didUpdateItems(
89 &self,
90 updated_items: &NSArray<ProtocolObject<dyn NSFileProviderItemProtocol>>,
91 );
92
93 #[cfg(feature = "NSFileProviderItem")]
94 /// Delete existing items. No-op if the item was unknown.
95 #[unsafe(method(didDeleteItemsWithIdentifiers:))]
96 #[unsafe(method_family = none)]
97 unsafe fn didDeleteItemsWithIdentifiers(
98 &self,
99 deleted_item_identifiers: &NSArray<NSFileProviderItemIdentifier>,
100 );
101
102 /// This method is used to complete a batch of changes. Follow the advice
103 /// in -[NSFileProviderChangeObserver suggestedBatchSize] to determine when to
104 /// call this method.
105 ///
106 /// It is expected that the sync anchor passed here be different than the sync
107 /// anchor that the enumeration started at, unless the client was already up to
108 /// date on all the changes on the server, and didn't have any pending updates or
109 /// deletions.
110 ///
111 /// Additionally, if the client is up to date on all the changes on the server it
112 /// should set moreComing to NO.
113 ///
114 /// Sync anchor data is limited to 500 bytes. Setting a larger anchor has the
115 /// same effect as calling finishEnumeratingWithError with an expired sync anchor
116 /// error.
117 #[unsafe(method(finishEnumeratingChangesUpToSyncAnchor:moreComing:))]
118 #[unsafe(method_family = none)]
119 unsafe fn finishEnumeratingChangesUpToSyncAnchor_moreComing(
120 &self,
121 anchor: &NSFileProviderSyncAnchor,
122 more_coming: bool,
123 );
124
125 /// If the enumeration fails with NSFileProviderErrorSyncAnchorExpired, we will
126 /// drop all cached data and start the enumeration over starting with sync anchor
127 /// nil.
128 #[unsafe(method(finishEnumeratingWithError:))]
129 #[unsafe(method_family = none)]
130 unsafe fn finishEnumeratingWithError(&self, error: &NSError);
131
132 /// Size of the batch suggested by the system for better performance.
133 ///
134 /// The system will set that property to the value it considers is best suited for the current enumeration. The
135 /// system can enumerate changes on a container in various cases (container presenter in the UI, file opened in an
136 /// application, ...). Each case has its own performance profile.
137 ///
138 /// In case the enumerator has already more than suggestedBatchSize pending changes ready to enumerate, it is suggested
139 /// it split the list of changes into several batches. If the enumerator does not have suggestedBatchSize ready to
140 /// enumerator, the enumerator should finish immediately and not wait for more incoming changes to enumerate.
141 ///
142 /// By taking into account the suggested size, the enumeration will guarantee the best user experience possible. Large
143 /// batches can cause performance issues. And when the device reboots, enumerations will resume from the latest
144 /// known sync anchor. Telling the system about the latest sync anchor more frequently will reduce the number
145 /// of re-enumerations on system reboot.
146 ///
147 /// The system enforces a maximum of 100 times the suggested size.
148 #[optional]
149 #[unsafe(method(suggestedBatchSize))]
150 #[unsafe(method_family = none)]
151 unsafe fn suggestedBatchSize(&self) -> NSInteger;
152 }
153);
154
155extern_protocol!(
156 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderenumerator?language=objc)
157 pub unsafe trait NSFileProviderEnumerator: NSObjectProtocol {
158 #[unsafe(method(invalidate))]
159 #[unsafe(method_family = none)]
160 unsafe fn invalidate(&self);
161
162 /// Enumerate items starting from the specified page, typically
163 /// NSFileProviderInitialPageSortedByDate or NSFileProviderInitialPageSortedByName.
164 ///
165 /// Pagination allows large collections to be enumerated in multiple batches. The
166 /// sort order specified in the initial page is important even if the enumeration
167 /// results will actually be sorted again before display. If results are sorted
168 /// correctly across pages, then the new results will be appended at the bottom of
169 /// the list, probably not on screen, which is the best user experience. Otherwise
170 /// results from the second page might be inserted in the results from the first
171 /// page, causing bizarre animations.
172 ///
173 /// The page data should contain whatever information is needed to resume the
174 /// enumeration after the previous page. If a file provider sends batches of 200
175 /// items to -[NSFileProviderEnumerationObserver didEnumerateItems:] for example,
176 /// then successive pages might contain offsets in increments of 200.
177 ///
178 /// Execution time:
179 /// ---------------
180 /// This method is not expected to take more than a few seconds to complete the
181 /// enumeration of a page of items. If the enumeration may not complete in a reasonable
182 /// amount of time because, for instance, of bad network conditions, it is recommended
183 /// to either report an error (for instance NSFileProviderErrorServerUnreachable) or
184 /// return everything that is readily available and wait for the enumeration of the
185 /// next page.
186 #[unsafe(method(enumerateItemsForObserver:startingAtPage:))]
187 #[unsafe(method_family = none)]
188 unsafe fn enumerateItemsForObserver_startingAtPage(
189 &self,
190 observer: &ProtocolObject<dyn NSFileProviderEnumerationObserver>,
191 page: &NSFileProviderPage,
192 );
193
194 /// Enumerate changes starting from a sync anchor. This should enumerate /all/
195 /// changes (not restricted to a specific page) since the given sync anchor.
196 ///
197 /// Until the enumeration update is invalidated, a call to -[NSFileProviderManager
198 /// signalEnumeratorForContainerItemIdentifier:completionHandler:] will trigger a
199 /// call to enumerateFromSyncAnchor with the latest known sync anchor, giving the
200 /// file provider (app or extension) a chance to notify about changes.
201 ///
202 /// The anchor data should contain whatever information is needed to resume
203 /// enumerating changes from the previous synchronization point. A naive sync
204 /// anchor might for example be the date of the last change that was sent from the
205 /// server to the client, meaning that at that date, the client was in sync with
206 /// all the server changes. A request to enumerate changes from that sync anchor
207 /// would only return the changes that happened after that date, which are
208 /// therefore changes that the client doesn't yet know about.
209 ///
210 /// NOTE that the change-based observation methods are marked optional for historical
211 /// reasons, but are really required. System performance will be severely degraded if
212 /// they are not implemented.
213 ///
214 /// Execution time:
215 /// ---------------
216 /// This method is not expected to take more than a few seconds to complete the
217 /// enumeration of a batch of items. If the enumeration may not complete in a reasonable
218 /// amount of time because, for instance, of bad network conditions, it is recommended
219 /// to either report an error (for instance NSFileProviderErrorServerUnreachable) or
220 /// return everything that is readily available and wait for the enumeration of the
221 /// next batch.
222 #[optional]
223 #[unsafe(method(enumerateChangesForObserver:fromSyncAnchor:))]
224 #[unsafe(method_family = none)]
225 unsafe fn enumerateChangesForObserver_fromSyncAnchor(
226 &self,
227 observer: &ProtocolObject<dyn NSFileProviderChangeObserver>,
228 sync_anchor: &NSFileProviderSyncAnchor,
229 );
230
231 #[cfg(feature = "block2")]
232 /// Request the current sync anchor.
233 ///
234 /// To keep an enumeration updated, the system will typically
235 /// - request the current sync anchor (1)
236 /// - enumerate items starting with an initial page
237 /// - continue enumerating pages, each time from the page returned in the previous
238 /// enumeration, until finishEnumeratingUpToPage: is called with nextPage set to
239 /// nil
240 /// - enumerate changes starting from the sync anchor returned in (1), until
241 /// finishEnumeratingChangesUpToSyncAnchor: is called with the latest sync anchor.
242 /// If moreComing is YES, continue enumerating changes, using the latest sync anchor returned.
243 /// If moreComing is NO, stop enumerating.
244 /// - When the extension calls -[NSFileProviderManager signalEnumeratorForContainerItemIdentifier:
245 /// completionHandler:] to signal more changes, the system will again enumerate changes,
246 /// starting at the latest known sync anchor from finishEnumeratingChangesUpToSyncAnchor.
247 ///
248 /// NOTE that the change-based observation methods are marked optional for historical
249 /// reasons, but are really required. System performance will be severely degraded if
250 /// they are not implemented.
251 #[optional]
252 #[unsafe(method(currentSyncAnchorWithCompletionHandler:))]
253 #[unsafe(method_family = none)]
254 unsafe fn currentSyncAnchorWithCompletionHandler(
255 &self,
256 completion_handler: &block2::DynBlock<dyn Fn(*mut NSFileProviderSyncAnchor)>,
257 );
258 }
259);
260
261/// NSFileProviderEnumeration.
262#[cfg(feature = "Extension")]
263impl NSFileProviderExtension {
264 extern_methods!(
265 #[cfg(feature = "NSFileProviderItem")]
266 /// Create an enumerator for an item.
267 ///
268 /// When the user opens the browse tab of the UIDocumentsBrowserViewController and
269 /// selects a file provider, this is called with
270 /// NSFileProviderRootContainerItemIdentifier, and -[NSFileProviderEnumerator
271 /// enumerateItemsForObserver:startingAtPage:] is immediately called to list the
272 /// first items available under at the root level of the file provider.
273 ///
274 /// As the user navigates down into directories, new enumerators are created with
275 /// this method, passing in the itemIdentifier of those directories. Past
276 /// enumerators are then invalidated.
277 ///
278 /// This method is also called with
279 /// NSFileProviderWorkingSetContainerItemIdentifier, which is enumerated with
280 /// -[NSFileProviderEnumerator enumerateChangesForObserver:fromSyncAnchor:]. That
281 /// enumeration is special in that it isn't driven by the
282 /// UIDocumentsBrowserViewController. It happens in the background to sync the
283 /// working set down to the device.
284 ///
285 /// This is also used to subscribe to live updates for a single document. In that
286 /// case, -[NSFileProviderEnumerator enumerateChangesToObserver:fromSyncAnchor:]
287 /// will be called and the enumeration results shouldn't include items other than
288 /// the very item that the enumeration was started on.
289 ///
290 /// If returning nil, you must set the error out parameter.
291 #[unsafe(method(enumeratorForContainerItemIdentifier:error:_))]
292 #[unsafe(method_family = none)]
293 pub unsafe fn enumeratorForContainerItemIdentifier_error(
294 &self,
295 container_item_identifier: &NSFileProviderItemIdentifier,
296 ) -> Result<Retained<ProtocolObject<dyn NSFileProviderEnumerator>>, Retained<NSError>>;
297 );
298}