FSTEventManager.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2017 Google
  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. #import "Firestore/Source/Core/FSTViewSnapshot.h"
  18. #include "Firestore/core/src/firebase/firestore/model/types.h"
  19. @class FSTQuery;
  20. @class FSTSyncEngine;
  21. NS_ASSUME_NONNULL_BEGIN
  22. #pragma mark - FSTListenOptions
  23. @interface FSTListenOptions : NSObject
  24. + (instancetype)defaultOptions;
  25. - (instancetype)initWithIncludeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges
  26. includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges
  27. waitForSyncWhenOnline:(BOOL)waitForSyncWhenOnline
  28. NS_DESIGNATED_INITIALIZER;
  29. - (instancetype)init NS_UNAVAILABLE;
  30. @property(nonatomic, assign, readonly) BOOL includeQueryMetadataChanges;
  31. @property(nonatomic, assign, readonly) BOOL includeDocumentMetadataChanges;
  32. @property(nonatomic, assign, readonly) BOOL waitForSyncWhenOnline;
  33. @end
  34. #pragma mark - FSTQueryListener
  35. /**
  36. * FSTQueryListener takes a series of internal view snapshots and determines when to raise
  37. * user-facing events.
  38. */
  39. @interface FSTQueryListener : NSObject
  40. - (instancetype)initWithQuery:(FSTQuery *)query
  41. options:(FSTListenOptions *)options
  42. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler NS_DESIGNATED_INITIALIZER;
  43. - (instancetype)init NS_UNAVAILABLE;
  44. - (void)queryDidChangeViewSnapshot:(FSTViewSnapshot *)snapshot;
  45. - (void)queryDidError:(NSError *)error;
  46. - (void)applyChangedOnlineState:(firebase::firestore::model::OnlineState)onlineState;
  47. @property(nonatomic, strong, readonly) FSTQuery *query;
  48. @end
  49. #pragma mark - FSTEventManager
  50. /**
  51. * EventManager is responsible for mapping queries to query event emitters. It handles "fan-out."
  52. * (Identical queries will re-use the same watch on the backend.)
  53. */
  54. @interface FSTEventManager : NSObject
  55. + (instancetype)eventManagerWithSyncEngine:(FSTSyncEngine *)syncEngine;
  56. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  57. - (firebase::firestore::model::TargetId)addListener:(FSTQueryListener *)listener;
  58. - (void)removeListener:(FSTQueryListener *)listener;
  59. - (void)applyChangedOnlineState:(firebase::firestore::model::OnlineState)onlineState;
  60. @end
  61. NS_ASSUME_NONNULL_END