FSTLevelDB.h 3.6 KB

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