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