FSTLevelDB.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "Firestore/core/src/firebase/firestore/util/statusor.h"
  27. #include "leveldb/db.h"
  28. @class FSTLocalSerializer;
  29. namespace core = firebase::firestore::core;
  30. namespace local = firebase::firestore::local;
  31. namespace util = firebase::firestore::util;
  32. NS_ASSUME_NONNULL_BEGIN
  33. @interface FSTLevelDBLRUDelegate : NSObject <FSTReferenceDelegate, FSTLRUDelegate>
  34. @end
  35. /** A LevelDB-backed instance of FSTPersistence. */
  36. // TODO(mikelehen): Rename to FSTLevelDBPersistence.
  37. @interface FSTLevelDB : NSObject <FSTPersistence, FSTTransactional>
  38. /**
  39. * Creates a LevelDB in the given directory and sets `ptr` to point to it. Return value indicates
  40. * success in creating the leveldb instance and must be checked before accessing `ptr`. C++ note:
  41. * Once FSTLevelDB is ported to C++, this factory method should return StatusOr<>. It cannot
  42. * currently do that because ObjC references are not allowed in StatusOr.
  43. */
  44. + (util::Status)dbWithDirectory:(util::Path)directory
  45. serializer:(FSTLocalSerializer *)serializer
  46. lruParams:(local::LruParams)lruParams
  47. ptr:(FSTLevelDB *_Nullable *_Nonnull)ptr;
  48. - (instancetype)init NS_UNAVAILABLE;
  49. /** Finds a suitable directory to serve as the root of all Firestore local storage. */
  50. + (util::Path)documentsDirectory;
  51. /**
  52. * Computes a unique storage directory for the given identifying components of local storage.
  53. *
  54. * @param databaseInfo The identifying information for the local storage instance.
  55. * @param documentsDirectory The root document directory relative to which the storage directory
  56. * will be created. Usually just +[FSTLevelDB documentsDir].
  57. * @return A storage directory unique to the instance identified by databaseInfo.
  58. */
  59. + (util::Path)storageDirectoryForDatabaseInfo:(const core::DatabaseInfo &)databaseInfo
  60. documentsDirectory:(const util::Path &)documentsDirectory;
  61. /**
  62. * @return A standard set of read options
  63. */
  64. + (const leveldb::ReadOptions)standardReadOptions;
  65. + (util::Status)clearPersistence:(const core::DatabaseInfo &)databaseInfo;
  66. /** The native db pointer, allocated during start. */
  67. @property(nonatomic, assign, readonly) leveldb::DB *ptr;
  68. @property(nonatomic, readonly) local::LevelDbTransaction *currentTransaction;
  69. @property(nonatomic, readonly) const std::set<std::string> &users;
  70. @property(nonatomic, readonly, strong) FSTLevelDBLRUDelegate *referenceDelegate;
  71. @property(nonatomic, readonly, strong) FSTLocalSerializer *serializer;
  72. @end
  73. NS_ASSUME_NONNULL_END