FSTFirestoreClient.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 FSTDatabaseID;
  21. @class FSTDatabaseInfo;
  22. @class FSTDispatchQueue;
  23. @class FSTDocument;
  24. @class FSTListenOptions;
  25. @class FSTMutation;
  26. @class FSTQuery;
  27. @class FSTQueryListener;
  28. @class FSTTransaction;
  29. @protocol FSTCredentialsProvider;
  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
  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:(FSTDatabaseInfo *)databaseInfo
  43. usePersistence:(BOOL)usePersistence
  44. credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
  45. userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
  46. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue;
  47. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  48. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  49. - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion;
  50. /** Disables the network connection. Pending operations will not complete. */
  51. - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  52. /** Enables the network connection and requeues all pending operations. */
  53. - (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  54. /** Starts listening to a query. */
  55. - (FSTQueryListener *)listenToQuery:(FSTQuery *)query
  56. options:(FSTListenOptions *)options
  57. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler;
  58. /** Stops listening to a query previously listened to. */
  59. - (void)removeListener:(FSTQueryListener *)listener;
  60. /** Write mutations. completion will be notified when it's written to the backend. */
  61. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
  62. completion:(nullable FSTVoidErrorBlock)completion;
  63. /** Tries to execute the transaction in updateBlock up to retries times. */
  64. - (void)transactionWithRetries:(int)retries
  65. updateBlock:(FSTTransactionBlock)updateBlock
  66. completion:(FSTVoidIDErrorBlock)completion;
  67. /** The database ID of the databaseInfo this client was initialized with. */
  68. @property(nonatomic, strong, readonly) FSTDatabaseID *databaseID;
  69. /**
  70. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  71. * app but the developer can configure it to a different queue if they so choose.
  72. */
  73. @property(nonatomic, strong, readonly) FSTDispatchQueue *userDispatchQueue;
  74. @end
  75. NS_ASSUME_NONNULL_END