FSTLevelDB.h 3.6 KB

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