FSTFirestoreClient.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  21. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  22. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  23. @class FSTDispatchQueue;
  24. @class FSTDocument;
  25. @class FSTListenOptions;
  26. @class FSTMutation;
  27. @class FSTQuery;
  28. @class FSTQueryListener;
  29. @class FSTTransaction;
  30. NS_ASSUME_NONNULL_BEGIN
  31. /**
  32. * FirestoreClient is a top-level class that constructs and owns all of the pieces of the client
  33. * SDK architecture. It is responsible for creating the worker queue that is shared by all of the
  34. * other components in the system.
  35. */
  36. @interface FSTFirestoreClient : NSObject <FSTOnlineStateDelegate>
  37. /**
  38. * Creates and returns a FSTFirestoreClient with the given parameters.
  39. *
  40. * All callbacks and events will be triggered on the provided userDispatchQueue.
  41. */
  42. + (instancetype)clientWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
  43. usePersistence:(BOOL)usePersistence
  44. credentialsProvider:(firebase::firestore::auth::CredentialsProvider *)
  45. credentialsProvider // no passing ownership
  46. userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
  47. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue;
  48. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  49. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  50. - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion;
  51. /** Disables the network connection. Pending operations will not complete. */
  52. - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  53. /** Enables the network connection and requeues all pending operations. */
  54. - (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  55. /** Starts listening to a query. */
  56. - (FSTQueryListener *)listenToQuery:(FSTQuery *)query
  57. options:(FSTListenOptions *)options
  58. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler;
  59. /** Stops listening to a query previously listened to. */
  60. - (void)removeListener:(FSTQueryListener *)listener;
  61. /** Write mutations. completion will be notified when it's written to the backend. */
  62. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
  63. completion:(nullable FSTVoidErrorBlock)completion;
  64. /** Tries to execute the transaction in updateBlock up to retries times. */
  65. - (void)transactionWithRetries:(int)retries
  66. updateBlock:(FSTTransactionBlock)updateBlock
  67. completion:(FSTVoidIDErrorBlock)completion;
  68. /** The database ID of the databaseInfo this client was initialized with. */
  69. // Ownes a DatabaseInfo instance, which contains the id here.
  70. @property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
  71. /**
  72. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  73. * app but the developer can configure it to a different queue if they so choose.
  74. */
  75. @property(nonatomic, strong, readonly) FSTDispatchQueue *userDispatchQueue;
  76. @end
  77. NS_ASSUME_NONNULL_END