FIRLoadBundleTask.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2021 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * Represents the state of bundle loading tasks.
  20. *
  21. * Both `error` and `inProgress` are final states: the task will be in either an aborted or
  22. * completed state and there will be no more subsequent updates.
  23. */
  24. typedef NS_ENUM(NSInteger, FIRLoadBundleTaskState) {
  25. FIRLoadBundleTaskStateError,
  26. FIRLoadBundleTaskStateInProgress,
  27. FIRLoadBundleTaskStateSuccess,
  28. } NS_SWIFT_NAME(LoadBundleTaskState);
  29. /** Represents a progress update or a final state from loading bundles. */
  30. NS_SWIFT_NAME(LoadBundleTaskProgress)
  31. @interface FIRLoadBundleTaskProgress : NSObject
  32. /** How many documents have been loaded. */
  33. @property(readonly, nonatomic) NSInteger documentsLoaded;
  34. /** The total number of documents in the bundle. 0 if the bundle failed to parse. */
  35. @property(readonly, nonatomic) NSInteger totalDocuments;
  36. /** How many bytes have been loaded. */
  37. @property(readonly, nonatomic) NSInteger bytesLoaded;
  38. /** The total number of bytes in the bundle. 0 if the bundle failed to parse. */
  39. @property(readonly, nonatomic) NSInteger totalBytes;
  40. /** The current state of `LoadBundleTask`. */
  41. @property(readonly, nonatomic) FIRLoadBundleTaskState state;
  42. @end
  43. /** A handle associated with registered observers that can be used to remove them. */
  44. typedef NSInteger FIRLoadBundleObserverHandle NS_SWIFT_NAME(LoadBundleObserverHandle);
  45. /**
  46. * Represents the task of loading a Firestore bundle. Observers can be registered with this task to
  47. * observe the bundle loading progress, as well as task completion and error events.
  48. */
  49. NS_SWIFT_NAME(LoadBundleTask)
  50. @interface FIRLoadBundleTask : NSObject
  51. /**
  52. * Registers an observer to observe the progress updates, completion or error events.
  53. *
  54. * @return A handle to the registered observer which can be used to remove the observer once it is
  55. * no longer needed.
  56. */
  57. - (FIRLoadBundleObserverHandle)addObserver:(void (^)(FIRLoadBundleTaskProgress *progress))observer
  58. NS_SWIFT_NAME(addObserver(_:));
  59. /**
  60. * Removes a registered observer associated with the given handle. If no observer can be found, this
  61. * will be a no-op.
  62. */
  63. - (void)removeObserverWithHandle:(FIRLoadBundleObserverHandle)handle
  64. NS_SWIFT_NAME(removeObserverWith(handle:));
  65. /**
  66. * Removes all registered observers for this task.
  67. */
  68. - (void)removeAllObservers NS_SWIFT_NAME(removeAllObservers());
  69. @end
  70. NS_ASSUME_NONNULL_END