FSTLevelDB.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <set>
  19. #include <string>
  20. #import "Firestore/Source/Local/FSTPersistence.h"
  21. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  22. #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h"
  23. #include "Firestore/core/src/firebase/firestore/util/path.h"
  24. #include "Firestore/core/src/firebase/firestore/util/status.h"
  25. #include "leveldb/db.h"
  26. @class FSTLocalSerializer;
  27. NS_ASSUME_NONNULL_BEGIN
  28. /** A LevelDB-backed instance of FSTPersistence. */
  29. // TODO(mikelehen): Rename to FSTLevelDBPersistence.
  30. @interface FSTLevelDB : NSObject <FSTPersistence, FSTTransactional>
  31. /**
  32. * Initializes the LevelDB in the given directory. Note that all expensive startup work including
  33. * opening any database files is deferred until -[FSTPersistence start] is called.
  34. */
  35. - (instancetype)initWithDirectory:(firebase::firestore::util::Path)directory
  36. serializer:(FSTLocalSerializer *)serializer NS_DESIGNATED_INITIALIZER;
  37. - (instancetype)init NS_UNAVAILABLE;
  38. /** Finds a suitable directory to serve as the root of all Firestore local storage. */
  39. + (firebase::firestore::util::Path)documentsDirectory;
  40. /**
  41. * Computes a unique storage directory for the given identifying components of local storage.
  42. *
  43. * @param databaseInfo The identifying information for the local storage instance.
  44. * @param documentsDirectory The root document directory relative to which the storage directory
  45. * will be created. Usually just +[FSTLevelDB documentsDir].
  46. * @return A storage directory unique to the instance identified by databaseInfo.
  47. */
  48. + (firebase::firestore::util::Path)
  49. storageDirectoryForDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
  50. documentsDirectory:(const firebase::firestore::util::Path &)documentsDirectory;
  51. /**
  52. * Starts LevelDB-backed persistent storage by opening the database files, creating the DB if it
  53. * does not exist.
  54. *
  55. * The leveldb directory is created relative to the appropriate document storage directory for the
  56. * platform: NSDocumentDirectory on iOS or $HOME/.firestore on macOS.
  57. */
  58. - (firebase::firestore::util::Status)start;
  59. /**
  60. * @return A standard set of read options
  61. */
  62. + (const leveldb::ReadOptions)standardReadOptions;
  63. /** The native db pointer, allocated during start. */
  64. @property(nonatomic, assign, readonly) leveldb::DB *ptr;
  65. @property(nonatomic, readonly) firebase::firestore::local::LevelDbTransaction *currentTransaction;
  66. @property(nonatomic, readonly) const std::set<std::string> &users;
  67. @end
  68. NS_ASSUME_NONNULL_END