aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Core
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-02-06 13:51:11 -0500
committerGravatar GitHub <noreply@github.com>2018-02-06 13:51:11 -0500
commita441190635d494f128cf02e07566ae2003af4e08 (patch)
tree618e6b0ecdb5d243f6e97f319f98f09dc9ca0a7e /Firestore/Source/Core
parent7cac9dc47a8c6b7321ebf5fc13fa7140e784c8ca (diff)
Implement Firestore DatabaseInfo and port both Database{Id,Info} C++ to the iOS code (#738)
* implement Firestore DatabaseInfo in C++ * temporary stash changes; blocking on the massive renaming of .m to .mm * add database_info_test to project * finish port DatabaseId and fix style, modular fixing DatabaseInfo * port DatabaseInfo * remove FSTDatabase{ID,Info} and their tests from project * fix unit test * use namespace alias * use namespace alias, leftover * address more changes * refactoring to use raw pointer instead of value for property * address changes * remove self-> * fix style * remove the name suffix Alloc * fix a bug
Diffstat (limited to 'Firestore/Source/Core')
-rw-r--r--Firestore/Source/Core/FSTDatabaseInfo.h55
-rw-r--r--Firestore/Source/Core/FSTDatabaseInfo.mm70
-rw-r--r--Firestore/Source/Core/FSTFirestoreClient.h10
-rw-r--r--Firestore/Source/Core/FSTFirestoreClient.mm33
-rw-r--r--Firestore/Source/Core/FSTSyncEngine.mm7
5 files changed, 33 insertions, 142 deletions
diff --git a/Firestore/Source/Core/FSTDatabaseInfo.h b/Firestore/Source/Core/FSTDatabaseInfo.h
deleted file mode 100644
index fae884f..0000000
--- a/Firestore/Source/Core/FSTDatabaseInfo.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import <Foundation/Foundation.h>
-
-@class FSTDatabaseID;
-
-NS_ASSUME_NONNULL_BEGIN
-
-/** FSTDatabaseInfo contains data about the database. */
-@interface FSTDatabaseInfo : NSObject
-
-/**
- * Creates and returns a new FSTDatabaseInfo.
- *
- * @param databaseID The project/database to use.
- * @param persistenceKey A unique identifier for this Firestore's local storage. Usually derived
- * from -[FIRApp appName].
- * @param host The hostname of the datastore backend.
- * @param sslEnabled Whether to use SSL when connecting.
- * @return A new instance of FSTDatabaseInfo.
- */
-+ (instancetype)databaseInfoWithDatabaseID:(FSTDatabaseID *)databaseID
- persistenceKey:(NSString *)persistenceKey
- host:(NSString *)host
- sslEnabled:(BOOL)sslEnabled;
-
-/** The database info. */
-@property(nonatomic, strong, readonly) FSTDatabaseID *databaseID;
-
-/** The application name, taken from FIRApp. */
-@property(nonatomic, copy, readonly) NSString *persistenceKey;
-
-/** The hostname of the backend. */
-@property(nonatomic, copy, readonly) NSString *host;
-
-/** Whether to use SSL when connecting. */
-@property(nonatomic, readonly, getter=isSSLEnabled) BOOL sslEnabled;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Core/FSTDatabaseInfo.mm b/Firestore/Source/Core/FSTDatabaseInfo.mm
deleted file mode 100644
index 2dbe61a..0000000
--- a/Firestore/Source/Core/FSTDatabaseInfo.mm
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import "Firestore/Source/Core/FSTDatabaseInfo.h"
-
-#import "Firestore/Source/Model/FSTDatabaseID.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-#pragma mark - FSTDatabaseInfo
-
-@implementation FSTDatabaseInfo
-
-#pragma mark - Constructors
-
-+ (instancetype)databaseInfoWithDatabaseID:(FSTDatabaseID *)databaseID
- persistenceKey:(NSString *)persistenceKey
- host:(NSString *)host
- sslEnabled:(BOOL)sslEnabled {
- return [[FSTDatabaseInfo alloc] initWithDatabaseID:databaseID
- persistenceKey:persistenceKey
- host:host
- sslEnabled:sslEnabled];
-}
-
-/**
- * Designated initializer.
- *
- * @param databaseID The database in the datastore.
- * @param persistenceKey A unique identifier for this Firestore's local storage. Usually derived
- * from -[FIRApp appName].
- * @param host The Firestore server hostname.
- * @param sslEnabled Whether to use SSL when connecting.
- */
-- (instancetype)initWithDatabaseID:(FSTDatabaseID *)databaseID
- persistenceKey:(NSString *)persistenceKey
- host:(NSString *)host
- sslEnabled:(BOOL)sslEnabled {
- if (self = [super init]) {
- _databaseID = databaseID;
- _persistenceKey = [persistenceKey copy];
- _host = [host copy];
- _sslEnabled = sslEnabled;
- }
- return self;
-}
-
-#pragma mark - NSObject methods
-
-- (NSString *)description {
- return [NSString
- stringWithFormat:@"<FSTDatabaseInfo: databaseID:%@ host:%@>", self.databaseID, self.host];
-}
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Core/FSTFirestoreClient.h b/Firestore/Source/Core/FSTFirestoreClient.h
index 0ecf2f6..56101ab 100644
--- a/Firestore/Source/Core/FSTFirestoreClient.h
+++ b/Firestore/Source/Core/FSTFirestoreClient.h
@@ -20,8 +20,9 @@
#import "Firestore/Source/Core/FSTViewSnapshot.h"
#import "Firestore/Source/Remote/FSTRemoteStore.h"
-@class FSTDatabaseID;
-@class FSTDatabaseInfo;
+#include "Firestore/core/src/firebase/firestore/core/database_info.h"
+#include "Firestore/core/src/firebase/firestore/model/database_id.h"
+
@class FSTDispatchQueue;
@class FSTDocument;
@class FSTListenOptions;
@@ -45,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* All callbacks and events will be triggered on the provided userDispatchQueue.
*/
-+ (instancetype)clientWithDatabaseInfo:(FSTDatabaseInfo *)databaseInfo
++ (instancetype)clientWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
usePersistence:(BOOL)usePersistence
credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
@@ -80,7 +81,8 @@ NS_ASSUME_NONNULL_BEGIN
completion:(FSTVoidIDErrorBlock)completion;
/** The database ID of the databaseInfo this client was initialized with. */
-@property(nonatomic, strong, readonly) FSTDatabaseID *databaseID;
+// Ownes a DatabaseInfo instance, which contains the id here.
+@property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
/**
* Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
diff --git a/Firestore/Source/Core/FSTFirestoreClient.mm b/Firestore/Source/Core/FSTFirestoreClient.mm
index 5986b5b..1961460 100644
--- a/Firestore/Source/Core/FSTFirestoreClient.mm
+++ b/Firestore/Source/Core/FSTFirestoreClient.mm
@@ -17,7 +17,6 @@
#import "Firestore/Source/Core/FSTFirestoreClient.h"
#import "Firestore/Source/Auth/FSTCredentialsProvider.h"
-#import "Firestore/Source/Core/FSTDatabaseInfo.h"
#import "Firestore/Source/Core/FSTEventManager.h"
#import "Firestore/Source/Core/FSTSyncEngine.h"
#import "Firestore/Source/Core/FSTTransaction.h"
@@ -35,16 +34,26 @@
#import "Firestore/Source/Util/FSTDispatchQueue.h"
#import "Firestore/Source/Util/FSTLogger.h"
+#include "Firestore/core/src/firebase/firestore/core/database_info.h"
+#include "Firestore/core/src/firebase/firestore/model/database_id.h"
+#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+
+using firebase::firestore::core::DatabaseInfo;
+using firebase::firestore::model::DatabaseId;
+
NS_ASSUME_NONNULL_BEGIN
-@interface FSTFirestoreClient ()
-- (instancetype)initWithDatabaseInfo:(FSTDatabaseInfo *)databaseInfo
+@interface FSTFirestoreClient () {
+ DatabaseInfo _databaseInfo;
+}
+
+- (instancetype)initWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
usePersistence:(BOOL)usePersistence
credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
workerDispatchQueue:(FSTDispatchQueue *)queue NS_DESIGNATED_INITIALIZER;
-@property(nonatomic, strong, readonly) FSTDatabaseInfo *databaseInfo;
+@property(nonatomic, assign, readonly) const DatabaseInfo *databaseInfo;
@property(nonatomic, strong, readonly) FSTEventManager *eventManager;
@property(nonatomic, strong, readonly) id<FSTPersistence> persistence;
@property(nonatomic, strong, readonly) FSTSyncEngine *syncEngine;
@@ -65,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation FSTFirestoreClient
-+ (instancetype)clientWithDatabaseInfo:(FSTDatabaseInfo *)databaseInfo
++ (instancetype)clientWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
usePersistence:(BOOL)usePersistence
credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
@@ -77,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
workerDispatchQueue:workerDispatchQueue];
}
-- (instancetype)initWithDatabaseInfo:(FSTDatabaseInfo *)databaseInfo
+- (instancetype)initWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
usePersistence:(BOOL)usePersistence
credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
@@ -130,11 +139,11 @@ NS_ASSUME_NONNULL_BEGIN
// enabled.
garbageCollector = [[FSTNoOpGarbageCollector alloc] init];
- NSString *dir = [FSTLevelDB storageDirectoryForDatabaseInfo:self.databaseInfo
+ NSString *dir = [FSTLevelDB storageDirectoryForDatabaseInfo:*self.databaseInfo
documentsDirectory:[FSTLevelDB documentsDirectory]];
FSTSerializerBeta *remoteSerializer =
- [[FSTSerializerBeta alloc] initWithDatabaseID:self.databaseInfo.databaseID];
+ [[FSTSerializerBeta alloc] initWithDatabaseID:&self.databaseInfo->database_id()];
FSTLocalSerializer *serializer =
[[FSTLocalSerializer alloc] initWithRemoteSerializer:remoteSerializer];
@@ -291,8 +300,12 @@ NS_ASSUME_NONNULL_BEGIN
}];
}
-- (FSTDatabaseID *)databaseID {
- return self.databaseInfo.databaseID;
+- (const DatabaseInfo *)databaseInfo {
+ return &_databaseInfo;
+}
+
+- (const DatabaseId *)databaseID {
+ return &_databaseInfo.database_id();
}
@end
diff --git a/Firestore/Source/Core/FSTSyncEngine.mm b/Firestore/Source/Core/FSTSyncEngine.mm
index d82cc99..d6ee956 100644
--- a/Firestore/Source/Core/FSTSyncEngine.mm
+++ b/Firestore/Source/Core/FSTSyncEngine.mm
@@ -42,6 +42,8 @@
#include "Firestore/core/src/firebase/firestore/core/target_id_generator.h"
+using firebase::firestore::core::TargetIdGenerator;
+
NS_ASSUME_NONNULL_BEGIN
// Limbo documents don't use persistence, and are eagerly GC'd. So, listens for them don't need
@@ -148,7 +150,7 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1;
@implementation FSTSyncEngine {
/** Used for creating the FSTTargetIDs for the listens used to resolve limbo documents. */
- firebase::firestore::core::TargetIdGenerator _targetIdGenerator;
+ TargetIdGenerator _targetIdGenerator;
}
- (instancetype)initWithLocalStore:(FSTLocalStore *)localStore
@@ -168,8 +170,7 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1;
[_limboCollector addGarbageSource:_limboDocumentRefs];
_mutationCompletionBlocks = [NSMutableDictionary dictionary];
- _targetIdGenerator =
- firebase::firestore::core::TargetIdGenerator::SyncEngineTargetIdGenerator(0);
+ _targetIdGenerator = TargetIdGenerator::SyncEngineTargetIdGenerator(0);
_currentUser = initialUser;
}
return self;