FSTFirestoreClient.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <memory>
  18. #import "Firestore/Source/Core/FSTTypes.h"
  19. #import "Firestore/Source/Core/FSTViewSnapshot.h"
  20. #import "Firestore/Source/Remote/FSTRemoteStore.h"
  21. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  22. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  23. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  24. #include "Firestore/core/src/firebase/firestore/util/async_queue.h"
  25. #include "Firestore/core/src/firebase/firestore/util/executor.h"
  26. @class FIRDocumentReference;
  27. @class FIRDocumentSnapshot;
  28. @class FIRFirestoreSettings;
  29. @class FIRQuery;
  30. @class FIRQuerySnapshot;
  31. @class FSTDatabaseID;
  32. @class FSTDatabaseInfo;
  33. @class FSTDocument;
  34. @class FSTListenOptions;
  35. @class FSTMutation;
  36. @class FSTQuery;
  37. @class FSTQueryListener;
  38. @class FSTTransaction;
  39. NS_ASSUME_NONNULL_BEGIN
  40. /**
  41. * FirestoreClient is a top-level class that constructs and owns all of the pieces of the client
  42. * SDK architecture. It is responsible for creating the worker queue that is shared by all of the
  43. * other components in the system.
  44. */
  45. @interface FSTFirestoreClient : NSObject <FSTOnlineStateDelegate>
  46. /**
  47. * Creates and returns a FSTFirestoreClient with the given parameters.
  48. *
  49. * All callbacks and events will be triggered on the provided userExecutor.
  50. */
  51. + (instancetype)
  52. clientWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
  53. settings:(FIRFirestoreSettings *)settings
  54. credentialsProvider:(firebase::firestore::auth::CredentialsProvider *)
  55. credentialsProvider // no passing ownership
  56. userExecutor:(std::unique_ptr<firebase::firestore::util::Executor>)userExecutor
  57. workerQueue:(std::unique_ptr<firebase::firestore::util::AsyncQueue>)workerQueue;
  58. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  59. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  60. - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion;
  61. /** Disables the network connection. Pending operations will not complete. */
  62. - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  63. /** Enables the network connection and requeues all pending operations. */
  64. - (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  65. /** Starts listening to a query. */
  66. - (FSTQueryListener *)listenToQuery:(FSTQuery *)query
  67. options:(FSTListenOptions *)options
  68. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler;
  69. /** Stops listening to a query previously listened to. */
  70. - (void)removeListener:(FSTQueryListener *)listener;
  71. /**
  72. * Retrieves a document from the cache via the indicated completion. If the doc
  73. * doesn't exist, an error will be sent to the completion.
  74. */
  75. - (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc
  76. completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
  77. NSError *_Nullable error))completion;
  78. /**
  79. * Retrieves a (possibly empty) set of documents from the cache via the
  80. * indicated completion.
  81. */
  82. - (void)getDocumentsFromLocalCache:(FIRQuery *)query
  83. completion:(void (^)(FIRQuerySnapshot *_Nullable query,
  84. NSError *_Nullable error))completion;
  85. /** Write mutations. completion will be notified when it's written to the backend. */
  86. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
  87. completion:(nullable FSTVoidErrorBlock)completion;
  88. /** Tries to execute the transaction in updateBlock up to retries times. */
  89. - (void)transactionWithRetries:(int)retries
  90. updateBlock:(FSTTransactionBlock)updateBlock
  91. completion:(FSTVoidIDErrorBlock)completion;
  92. /** The database ID of the databaseInfo this client was initialized with. */
  93. // Ownes a DatabaseInfo instance, which contains the id here.
  94. @property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
  95. /**
  96. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  97. * app but the developer can configure it to a different queue if they so choose.
  98. */
  99. - (firebase::firestore::util::Executor *)userExecutor;
  100. /** For testing only. */
  101. - (firebase::firestore::util::AsyncQueue *)workerQueue;
  102. @end
  103. NS_ASSUME_NONNULL_END