FIRLoadBundleTask.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 `FIRLoadBundleTaskStateError` and `FIRLoadBundleTaskStateSuccess` are final states: task
  22. * will be in either aborted or completed state and there will be no more updates after they are
  23. * reported.
  24. */
  25. typedef NS_ENUM(NSInteger, FIRLoadBundleTaskState) {
  26. FIRLoadBundleTaskStateError,
  27. FIRLoadBundleTaskStateInProgress,
  28. FIRLoadBundleTaskStateSuccess,
  29. } NS_SWIFT_NAME(LoadBundleTaskState);
  30. /** Represents a progress update or a final state from loading bundles. */
  31. NS_SWIFT_NAME(LoadBundleTaskProgress)
  32. @interface FIRLoadBundleTaskProgress : NSObject
  33. /** How many documents have been loaded. */
  34. @property(readonly, nonatomic) NSInteger documentsLoaded;
  35. /** The total number of documents in the bundle. 0 if the bundle failed to parse. */
  36. @property(readonly, nonatomic) NSInteger totalDocuments;
  37. /** How many bytes have been loaded. */
  38. @property(readonly, nonatomic) NSInteger bytesLoaded;
  39. /** The total number of bytes in the bundle. 0 if the bundle failed to parse. */
  40. @property(readonly, nonatomic) NSInteger totalBytes;
  41. /** The current state of `FIRLoadBundleTask` (`LoadBundleTask` in Swift). */
  42. @property(readonly, nonatomic) FIRLoadBundleTaskState state;
  43. @end
  44. /** A handle associated with registered observers that can be used to remove them. */
  45. typedef NSInteger FIRLoadBundleObserverHandle NS_SWIFT_NAME(LoadBundleObserverHandle);
  46. /**
  47. * Represents the task of loading a Firestore bundle. Observers can be registered with this task to
  48. * observe the bundle loading progress, as well as task completion and error events.
  49. */
  50. NS_SWIFT_NAME(LoadBundleTask)
  51. @interface FIRLoadBundleTask : NSObject
  52. /**
  53. * Registers an observer to observe the progress updates, completion or error events.
  54. *
  55. * @return A handle to the registered observer which can be used to remove the observer once it is
  56. * no longer needed.
  57. */
  58. - (FIRLoadBundleObserverHandle)addObserver:(void (^)(FIRLoadBundleTaskProgress *progress))observer
  59. NS_SWIFT_NAME(addObserver(_:));
  60. /**
  61. * Removes a registered observer associated with the given handle. If no observer can be found, this
  62. * will be a no-op.
  63. */
  64. - (void)removeObserverWithHandle:(FIRLoadBundleObserverHandle)handle
  65. NS_SWIFT_NAME(removeObserverWith(handle:));
  66. /**
  67. * Removes all registered observers for this task.
  68. */
  69. - (void)removeAllObservers NS_SWIFT_NAME(removeAllObservers());
  70. @end
  71. NS_ASSUME_NONNULL_END