From 729b8d176c75ecc0cbbd137cc6811116a64e310a Mon Sep 17 00:00:00 2001 From: Gil Date: Wed, 31 Jan 2018 11:23:55 -0800 Subject: Move all Firestore Objective-C to Objective-C++ (#734) * Move all Firestore files to Objective-C++ * Update project file references * Don't use module imports from Objective-C++ * Use extern "C" for C-accessible globals * Work around more stringent type checking in Objective-C++ * NSMutableDictionary ivars aren't implicitly casted to NSDictionary * FSTMaybeDocument callback can't be passed a function that accepts FSTDocument * NSComparisonResult can't be multiplied by -1 without casting * Add a #include where needed * Avoid using C++ keywords as variables * Remove #if __cplusplus guards --- Firestore/Source/Local/FSTMemoryPersistence.mm | 107 +++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Firestore/Source/Local/FSTMemoryPersistence.mm (limited to 'Firestore/Source/Local/FSTMemoryPersistence.mm') diff --git a/Firestore/Source/Local/FSTMemoryPersistence.mm b/Firestore/Source/Local/FSTMemoryPersistence.mm new file mode 100644 index 0000000..e301820 --- /dev/null +++ b/Firestore/Source/Local/FSTMemoryPersistence.mm @@ -0,0 +1,107 @@ +/* + * 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/Local/FSTMemoryPersistence.h" + +#import "Firestore/Source/Auth/FSTUser.h" +#import "Firestore/Source/Local/FSTMemoryMutationQueue.h" +#import "Firestore/Source/Local/FSTMemoryQueryCache.h" +#import "Firestore/Source/Local/FSTMemoryRemoteDocumentCache.h" +#import "Firestore/Source/Local/FSTWriteGroup.h" +#import "Firestore/Source/Local/FSTWriteGroupTracker.h" +#import "Firestore/Source/Util/FSTAssert.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FSTMemoryPersistence () +@property(nonatomic, strong, nonnull) FSTWriteGroupTracker *writeGroupTracker; +@property(nonatomic, strong, nonnull) + NSMutableDictionary> *mutationQueues; +@property(nonatomic, assign, getter=isStarted) BOOL started; +@end + +@implementation FSTMemoryPersistence { + /** + * The FSTQueryCache representing the persisted cache of queries. + * + * Note that this is retained here to make it easier to write tests affecting both the in-memory + * and LevelDB-backed persistence layers. Tests can create a new FSTLocalStore wrapping this + * FSTPersistence instance and this will make the in-memory persistence layer behave as if it + * were actually persisting values. + */ + FSTMemoryQueryCache *_queryCache; + + /** The FSTRemoteDocumentCache representing the persisted cache of remote documents. */ + FSTMemoryRemoteDocumentCache *_remoteDocumentCache; +} + ++ (instancetype)persistence { + return [[FSTMemoryPersistence alloc] init]; +} + +- (instancetype)init { + if (self = [super init]) { + _writeGroupTracker = [FSTWriteGroupTracker tracker]; + _queryCache = [[FSTMemoryQueryCache alloc] init]; + _remoteDocumentCache = [[FSTMemoryRemoteDocumentCache alloc] init]; + _mutationQueues = [NSMutableDictionary dictionary]; + } + return self; +} + +- (BOOL)start:(NSError **)error { + // No durable state to read on startup. + FSTAssert(!self.isStarted, @"FSTMemoryPersistence double-started!"); + self.started = YES; + return YES; +} + +- (void)shutdown { + // No durable state to ensure is closed on shutdown. + FSTAssert(self.isStarted, @"FSTMemoryPersistence shutdown without start!"); + self.started = NO; +} + +- (id)mutationQueueForUser:(FSTUser *)user { + id queue = self.mutationQueues[user]; + if (!queue) { + queue = [FSTMemoryMutationQueue mutationQueue]; + self.mutationQueues[user] = queue; + } + return queue; +} + +- (id)queryCache { + return _queryCache; +} + +- (id)remoteDocumentCache { + return _remoteDocumentCache; +} + +- (FSTWriteGroup *)startGroupWithAction:(NSString *)action { + return [self.writeGroupTracker startGroupWithAction:action]; +} + +- (void)commitGroup:(FSTWriteGroup *)group { + [self.writeGroupTracker endGroup:group]; + + FSTAssert(group.isEmpty, @"Memory persistence shouldn't use write groups: %@", group.action); +} + +@end + +NS_ASSUME_NONNULL_END -- cgit v1.2.3