FSTEventManager.h 2.7 KB

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