FSTFirestoreClient.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #include <vector>
  19. #import "Firestore/Source/Core/FSTTypes.h"
  20. #include "Firestore/core/src/firebase/firestore/api/document_reference.h"
  21. #include "Firestore/core/src/firebase/firestore/api/document_snapshot.h"
  22. #include "Firestore/core/src/firebase/firestore/api/query_core.h"
  23. #include "Firestore/core/src/firebase/firestore/api/settings.h"
  24. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  25. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  26. #include "Firestore/core/src/firebase/firestore/core/listen_options.h"
  27. #include "Firestore/core/src/firebase/firestore/core/query_listener.h"
  28. #include "Firestore/core/src/firebase/firestore/core/transaction.h"
  29. #include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
  30. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  31. #include "Firestore/core/src/firebase/firestore/util/async_queue.h"
  32. #include "Firestore/core/src/firebase/firestore/util/executor.h"
  33. #include "Firestore/core/src/firebase/firestore/util/statusor_callback.h"
  34. @class FIRDocumentReference;
  35. @class FIRDocumentSnapshot;
  36. @class FIRQuery;
  37. @class FIRQuerySnapshot;
  38. @class FSTDatabaseID;
  39. @class FSTDatabaseInfo;
  40. @class FSTDocument;
  41. @class FSTMutation;
  42. @class FSTQuery;
  43. @class FSTTransaction;
  44. namespace api = firebase::firestore::api;
  45. namespace auth = firebase::firestore::auth;
  46. namespace core = firebase::firestore::core;
  47. namespace model = firebase::firestore::model;
  48. namespace util = firebase::firestore::util;
  49. NS_ASSUME_NONNULL_BEGIN
  50. /**
  51. * FirestoreClient is a top-level class that constructs and owns all of the pieces of the client
  52. * SDK architecture. It is responsible for creating the worker queue that is shared by all of the
  53. * other components in the system.
  54. */
  55. @interface FSTFirestoreClient : NSObject
  56. /**
  57. * Creates and returns a FSTFirestoreClient with the given parameters.
  58. *
  59. * All callbacks and events will be triggered on the provided userExecutor.
  60. */
  61. + (instancetype)clientWithDatabaseInfo:(const core::DatabaseInfo &)databaseInfo
  62. settings:(const api::Settings &)settings
  63. credentialsProvider:
  64. (auth::CredentialsProvider *)credentialsProvider // no passing ownership
  65. userExecutor:(std::shared_ptr<util::Executor>)userExecutor
  66. workerQueue:(std::shared_ptr<util::AsyncQueue>)workerQueue;
  67. - (instancetype)init NS_UNAVAILABLE;
  68. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  69. - (void)shutdownWithCallback:(util::StatusCallback)callback;
  70. /** Disables the network connection. Pending operations will not complete. */
  71. - (void)disableNetworkWithCallback:(util::StatusCallback)callback;
  72. /** Enables the network connection and requeues all pending operations. */
  73. - (void)enableNetworkWithCallback:(util::StatusCallback)callback;
  74. /** Starts listening to a query. */
  75. - (std::shared_ptr<core::QueryListener>)listenToQuery:(FSTQuery *)query
  76. options:(core::ListenOptions)options
  77. listener:
  78. (core::ViewSnapshot::SharedListener &&)listener;
  79. /** Stops listening to a query previously listened to. */
  80. - (void)removeListener:(const std::shared_ptr<core::QueryListener> &)listener;
  81. /**
  82. * Retrieves a document from the cache via the indicated callback. If the doc
  83. * doesn't exist, an error will be sent to the callback.
  84. */
  85. - (void)getDocumentFromLocalCache:(const api::DocumentReference &)doc
  86. callback:(api::DocumentSnapshot::Listener &&)callback;
  87. /**
  88. * Retrieves a (possibly empty) set of documents from the cache via the
  89. * indicated completion.
  90. */
  91. - (void)getDocumentsFromLocalCache:(const api::Query &)query
  92. callback:(api::QuerySnapshot::Listener &&)callback;
  93. /** Write mutations. callback will be notified when it's written to the backend. */
  94. - (void)writeMutations:(std::vector<FSTMutation *> &&)mutations
  95. callback:(util::StatusCallback)callback;
  96. /** Tries to execute the transaction in updateCallback up to retries times. */
  97. - (void)transactionWithRetries:(int)retries
  98. updateCallback:(core::TransactionUpdateCallback)updateCallback
  99. resultCallback:(core::TransactionResultCallback)resultCallback;
  100. /** The database ID of the databaseInfo this client was initialized with. */
  101. @property(nonatomic, assign, readonly) const model::DatabaseId &databaseID;
  102. /**
  103. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  104. * app but the developer can configure it to a different queue if they so choose.
  105. */
  106. - (const std::shared_ptr<util::Executor> &)userExecutor;
  107. /** For testing only. */
  108. - (const std::shared_ptr<util::AsyncQueue> &)workerQueue;
  109. - (bool)isShutdown;
  110. @end
  111. NS_ASSUME_NONNULL_END