Skip to content

Commit

Permalink
Merge pull request #441 from Simperium/develop
Browse files Browse the repository at this point in the history
Simperum Mark 0.7.7
  • Loading branch information
jleandroperez committed Jan 28, 2015
2 parents 7dafa22 + e6f6d81 commit 30663dc
Show file tree
Hide file tree
Showing 26 changed files with 808 additions and 526 deletions.
43 changes: 27 additions & 16 deletions External/SocketRocket/SRWebSocket.m
Expand Up @@ -116,8 +116,11 @@ @interface _SRRunLoopThread : NSThread
if ([data respondsToSelector:@selector(base64EncodedStringWithOptions:)]) {
return [data base64EncodedStringWithOptions:0];
}


#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return [data base64Encoding];
#pragma clang diagnostic pop
}

@implementation NSData (SRWebSocket)
Expand Down Expand Up @@ -512,7 +515,10 @@ - (void)didConnect
if ([keyBytes respondsToSelector:@selector(base64EncodedStringWithOptions:)]) {
_secKey = [keyBytes base64EncodedStringWithOptions:0];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_secKey = [keyBytes base64Encoding];
#pragma clang diagnostic pop
}

assert([_secKey length] == 24);
Expand Down Expand Up @@ -648,6 +654,7 @@ - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
NSUInteger usedLength = 0;

BOOL success = [reason getBytes:(char *)mutablePayload.mutableBytes + sizeof(uint16_t) maxLength:payload.length - sizeof(uint16_t) usedLength:&usedLength encoding:NSUTF8StringEncoding options:NSStringEncodingConversionExternalRepresentation range:NSMakeRange(0, reason.length) remainingRange:&remainingRange];
#pragma unused (success)

assert(success);
assert(remainingRange.length == 0);
Expand Down Expand Up @@ -685,11 +692,11 @@ - (void)_failWithError:(NSError *)error;
}];

self.readyState = SR_CLOSED;
[self _scheduleCleanup];

SRFastLog(@"Failing with error %@", error.localizedDescription);

[self _disconnect];
[self _scheduleCleanup];
}
});
}
Expand Down Expand Up @@ -1029,6 +1036,7 @@ - (void)_readFrameContinue;
} else {
[self _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *self, NSData *data) {
size_t mapped_size = data.length;
#pragma unused (mapped_size)
const void *mapped_buffer = data.bytes;
size_t offset = 0;

Expand All @@ -1045,7 +1053,6 @@ - (void)_readFrameContinue;
assert(header.payload_length < 126 && header.payload_length >= 0);
}


if (header.masked) {
assert(mapped_size >= sizeof(_currentReadMaskOffset) + offset);
memcpy(self->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(self->_currentReadMaskKey));
Expand Down Expand Up @@ -1097,13 +1104,15 @@ - (void)_pumpWriting;
_inputStream.streamStatus != NSStreamStatusClosed) &&
!_sentClose) {
_sentClose = YES;

[_outputStream close];
[_inputStream close];


for (NSArray *runLoop in [_scheduledRunloops copy]) {
[self unscheduleFromRunLoop:[runLoop objectAtIndex:0] forMode:[runLoop objectAtIndex:1]];
@synchronized(self) {
[_outputStream close];
[_inputStream close];


for (NSArray *runLoop in [_scheduledRunloops copy]) {
[self unscheduleFromRunLoop:[runLoop objectAtIndex:0] forMode:[runLoop objectAtIndex:1]];
}
}

if (!_failed) {
Expand Down Expand Up @@ -1159,13 +1168,15 @@ - (void)_scheduleCleanup

- (void)_cleanupSelfReference:(NSTimer *)timer
{
// Nuke NSStream delegate's
_inputStream.delegate = nil;
_outputStream.delegate = nil;

// Remove the streams, right now, from the networkRunLoop
[_inputStream close];
[_outputStream close];
@synchronized(self) {
// Nuke NSStream delegate's
_inputStream.delegate = nil;
_outputStream.delegate = nil;

// Remove the streams, right now, from the networkRunLoop
[_inputStream close];
[_outputStream close];
}

// Cleanup selfRetain in the same GCD queue as usual
dispatch_async(_workQueue, ^{
Expand Down
8 changes: 8 additions & 0 deletions Simperium-OSX/Simperium-OSX.xcodeproj/project.pbxproj
Expand Up @@ -138,6 +138,8 @@
B525F1F318842757003E4AA0 /* SPWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = B525F1F118842757003E4AA0 /* SPWebSocket.m */; };
B53E4888182AAC58000AA4C8 /* NSURLResponse+Simperium.h in Headers */ = {isa = PBXBuildFile; fileRef = B53E4886182AAC58000AA4C8 /* NSURLResponse+Simperium.h */; };
B53E4889182AAC58000AA4C8 /* NSURLResponse+Simperium.m in Sources */ = {isa = PBXBuildFile; fileRef = B53E4887182AAC58000AA4C8 /* NSURLResponse+Simperium.m */; };
B56091591A7276A800A4E64A /* NSConditionLock+Simperium.h in Headers */ = {isa = PBXBuildFile; fileRef = B56091571A7276A800A4E64A /* NSConditionLock+Simperium.h */; };
B560915A1A7276A800A4E64A /* NSConditionLock+Simperium.m in Sources */ = {isa = PBXBuildFile; fileRef = B56091581A7276A800A4E64A /* NSConditionLock+Simperium.m */; };
B56612891A1E1E280064A625 /* Simperium+Internals.h in Headers */ = {isa = PBXBuildFile; fileRef = B56612881A1E1E280064A625 /* Simperium+Internals.h */; };
B566128C1A1E1E610064A625 /* SPStorageObserverAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = B566128B1A1E1E610064A625 /* SPStorageObserverAdapter.m */; };
B56819C2194F7A6000E0DC65 /* DiffMatchPatch+Simperium.h in Headers */ = {isa = PBXBuildFile; fileRef = B56819C0194F7A6000E0DC65 /* DiffMatchPatch+Simperium.h */; };
Expand Down Expand Up @@ -343,6 +345,8 @@
B525F1F118842757003E4AA0 /* SPWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPWebSocket.m; path = ../../Simperium/SPWebSocket.m; sourceTree = "<group>"; };
B53E4886182AAC58000AA4C8 /* NSURLResponse+Simperium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSURLResponse+Simperium.h"; path = "../../Simperium/NSURLResponse+Simperium.h"; sourceTree = "<group>"; };
B53E4887182AAC58000AA4C8 /* NSURLResponse+Simperium.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSURLResponse+Simperium.m"; path = "../../Simperium/NSURLResponse+Simperium.m"; sourceTree = "<group>"; };
B56091571A7276A800A4E64A /* NSConditionLock+Simperium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSConditionLock+Simperium.h"; path = "../../Simperium/NSConditionLock+Simperium.h"; sourceTree = "<group>"; };
B56091581A7276A800A4E64A /* NSConditionLock+Simperium.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSConditionLock+Simperium.m"; path = "../../Simperium/NSConditionLock+Simperium.m"; sourceTree = "<group>"; };
B56612881A1E1E280064A625 /* Simperium+Internals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Simperium+Internals.h"; path = "../../Simperium/Simperium+Internals.h"; sourceTree = "<group>"; };
B566128A1A1E1E610064A625 /* SPStorageObserverAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPStorageObserverAdapter.h; path = ../../SimperiumTests/SPStorageObserverAdapter.h; sourceTree = "<group>"; };
B566128B1A1E1E610064A625 /* SPStorageObserverAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPStorageObserverAdapter.m; path = ../../SimperiumTests/SPStorageObserverAdapter.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -791,6 +795,8 @@
B56819C1194F7A6000E0DC65 /* DiffMatchPatch+Simperium.m */,
B5E03DA3182C236200412572 /* JSONKit+Simperium.h */,
B5E03DA4182C236200412572 /* JSONKit+Simperium.m */,
B56091571A7276A800A4E64A /* NSConditionLock+Simperium.h */,
B56091581A7276A800A4E64A /* NSConditionLock+Simperium.m */,
B56B1641183566DA00E45C98 /* NSArray+Simperium.h */,
B56B1642183566DA00E45C98 /* NSArray+Simperium.m */,
2698BE3715C908C60020565F /* NSMutableDictionary+Simperium.h */,
Expand Down Expand Up @@ -882,6 +888,7 @@
B58EC3181885B6C400ED37E5 /* SPPersistentMutableSet.h in Headers */,
B53E4888182AAC58000AA4C8 /* NSURLResponse+Simperium.h in Headers */,
463774E9171FC6D500E2E333 /* SocketRocket-Prefix.pch in Headers */,
B56091591A7276A800A4E64A /* NSConditionLock+Simperium.h in Headers */,
463774EA171FC6D500E2E333 /* SRWebSocket.h in Headers */,
46D5BC41174C2A9B0027DBAF /* SPRelationshipResolver.h in Headers */,
B59C7525186DAB70003A1C8D /* SPBucket+Internals.h in Headers */,
Expand Down Expand Up @@ -1046,6 +1053,7 @@
2698BE5115C908C80020565F /* SPSchema.m in Sources */,
2698BE5715C9097A0020565F /* JRSwizzle.m in Sources */,
26C3E1541666FE7500620306 /* SPWebSocketChannel.m in Sources */,
B560915A1A7276A800A4E64A /* NSConditionLock+Simperium.m in Sources */,
463774EB171FC6D500E2E333 /* SRWebSocket.m in Sources */,
B59AAC96185B90F000B557D3 /* SPThreadsafeMutableSet.m in Sources */,
46D5BC42174C2A9B0027DBAF /* SPRelationshipResolver.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Simperium.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Simperium"
s.version = "0.7.6"
s.version = "0.7.7"
s.summary = "Simperium libraries."
s.description = "Simperium is a simple way for developers to move data as it changes, instantly and automatically."
s.homepage = "https://github.com/Simperium/simperium-ios"
Expand Down
8 changes: 8 additions & 0 deletions Simperium.xcodeproj/project.pbxproj
Expand Up @@ -173,6 +173,8 @@
B5549FE318457F72007EA226 /* SPThreadsafeMutableSet.h in Headers */ = {isa = PBXBuildFile; fileRef = B5549FE118457F72007EA226 /* SPThreadsafeMutableSet.h */; };
B5549FE418457F72007EA226 /* SPThreadsafeMutableSet.m in Sources */ = {isa = PBXBuildFile; fileRef = B5549FE218457F72007EA226 /* SPThreadsafeMutableSet.m */; };
B5549FE6184581BF007EA226 /* SPThreadsafeMutableSetTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B5549FE5184581BF007EA226 /* SPThreadsafeMutableSetTests.m */; };
B56091551A717EE700A4E64A /* NSConditionLock+Simperium.h in Headers */ = {isa = PBXBuildFile; fileRef = B56091531A717EE700A4E64A /* NSConditionLock+Simperium.h */; };
B56091561A717EE700A4E64A /* NSConditionLock+Simperium.m in Sources */ = {isa = PBXBuildFile; fileRef = B56091541A717EE700A4E64A /* NSConditionLock+Simperium.m */; };
B565ECA2183261A600D162FF /* Test1.xcdatamodeld in Resources */ = {isa = PBXBuildFile; fileRef = 26ED4412146CF03A00C3D7D6 /* Test1.xcdatamodeld */; };
B565ECA31832643000D162FF /* TestObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 2673D727147A3BEB00B7B6B3 /* TestObject.m */; };
B565ECA41832643000D162FF /* PostComment.m in Sources */ = {isa = PBXBuildFile; fileRef = 2673D724147A018000B7B6B3 /* PostComment.m */; };
Expand Down Expand Up @@ -420,6 +422,8 @@
B5549FE118457F72007EA226 /* SPThreadsafeMutableSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = SPThreadsafeMutableSet.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
B5549FE218457F72007EA226 /* SPThreadsafeMutableSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = SPThreadsafeMutableSet.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
B5549FE5184581BF007EA226 /* SPThreadsafeMutableSetTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = SPThreadsafeMutableSetTests.m; sourceTree = "<group>"; };
B56091531A717EE700A4E64A /* NSConditionLock+Simperium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSConditionLock+Simperium.h"; sourceTree = "<group>"; };
B56091541A717EE700A4E64A /* NSConditionLock+Simperium.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSConditionLock+Simperium.m"; sourceTree = "<group>"; };
B565ECA71832940B00D162FF /* XCTestCase+Simperium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCTestCase+Simperium.h"; sourceTree = "<group>"; };
B565ECA81832940B00D162FF /* XCTestCase+Simperium.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCTestCase+Simperium.m"; sourceTree = "<group>"; };
B56819BC194F793400E0DC65 /* DiffMatchPatch+Simperium.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DiffMatchPatch+Simperium.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -796,6 +800,8 @@
26E83DA91399D05E00195758 /* NSDate+Simperium.m */,
26B16EFD13B1B78C00BEB3E5 /* NSData+Simperium.h */,
26B16EFE13B1B78F00BEB3E5 /* NSData+Simperium.m */,
B56091531A717EE700A4E64A /* NSConditionLock+Simperium.h */,
B56091541A717EE700A4E64A /* NSConditionLock+Simperium.m */,
B5E03D96182C115100412572 /* JSONKit+Simperium.h */,
B5E03D97182C115100412572 /* JSONKit+Simperium.m */,
B5C91A0C1827E9CB0002D306 /* NSURLResponse+Simperium.h */,
Expand Down Expand Up @@ -1020,6 +1026,7 @@
2622FD10147F24CC00C8EEB4 /* SPMemberInt.h in Headers */,
B5DF229218B41E3200874C75 /* SPMemberJSON.h in Headers */,
B5C91A0A1827E8600002D306 /* SPHttpRequestQueue.h in Headers */,
B56091551A717EE700A4E64A /* NSConditionLock+Simperium.h in Headers */,
2622FD14147F24D700C8EEB4 /* SPMemberDouble.h in Headers */,
2622FD18147F24E000C8EEB4 /* SPMemberFloat.h in Headers */,
2622FD1C147F24F700C8EEB4 /* SPMemberEntity.h in Headers */,
Expand Down Expand Up @@ -1269,6 +1276,7 @@
2622FD0D147F24A700C8EEB4 /* SPMemberDate.m in Sources */,
2622FD11147F24CC00C8EEB4 /* SPMemberInt.m in Sources */,
2622FD15147F24D700C8EEB4 /* SPMemberDouble.m in Sources */,
B56091561A717EE700A4E64A /* NSConditionLock+Simperium.m in Sources */,
2622FD19147F24E000C8EEB4 /* SPMemberFloat.m in Sources */,
2622FD1D147F24F700C8EEB4 /* SPMemberEntity.m in Sources */,
2622FD25147F251200C8EEB4 /* SPMemberList.m in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions Simperium/NSConditionLock+Simperium.h
@@ -0,0 +1,17 @@
//
// NSConditionLock+Simperium.h
// Simperium
//
// Created by Jorge Leandro Perez on 1/22/15.
// Copyright (c) 2015 Simperium. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface NSConditionLock (Simperium)

- (void)sp_increaseCondition;
- (void)sp_decreaseCondition;

@end
26 changes: 26 additions & 0 deletions Simperium/NSConditionLock+Simperium.m
@@ -0,0 +1,26 @@
//
// NSConditionLock+Simperium.m
// Simperium
//
// Created by Jorge Leandro Perez on 1/22/15.
// Copyright (c) 2015 Simperium. All rights reserved.
//

#import "NSConditionLock+Simperium.h"


@implementation NSConditionLock (Simperium)

- (void)sp_increaseCondition {
[self lock];
NSInteger condition = self.condition + 1;
[self unlockWithCondition:condition];
}

- (void)sp_decreaseCondition {
[self lock];
NSInteger condition = self.condition - 1;
[self unlockWithCondition:condition];
}

@end
28 changes: 7 additions & 21 deletions Simperium/SPBucket.m
Expand Up @@ -24,8 +24,13 @@ @implementation SPBucket

@synthesize lastChangeSignature = _lastChangeSignature;

- (instancetype)initWithSchema:(SPSchema *)aSchema storage:(id<SPStorageProvider>)aStorage networkInterface:(id<SPNetworkInterface>)netInterface
relationshipResolver:(SPRelationshipResolver *)resolver label:(NSString *)label remoteName:(NSString *)remoteName clientID:(NSString *)clientID
- (instancetype)initWithSchema:(SPSchema *)aSchema
storage:(id<SPStorageProvider>)aStorage
networkInterface:(id<SPNetworkInterface>)netInterface
relationshipResolver:(SPRelationshipResolver *)resolver
label:(NSString *)label
remoteName:(NSString *)remoteName
clientID:(NSString *)clientID
{
self = [super init];
if (self) {
Expand Down Expand Up @@ -83,7 +88,6 @@ - (void)requestVersions:(int)numVersions key:(NSString *)simperiumKey {
[self.network requestVersions:numVersions object:diffable];
}


- (NSArray *)allObjects {
return [self.storage objectsForBucketName:self.name predicate:nil];
}
Expand All @@ -104,10 +108,6 @@ - (id)insertNewObjectForKey:(NSString *)simperiumKey {
return [diffable object];
}

- (void)insertObject:(id)object {
//id<SPDiffable>diffable = [storage insertObject:object bucketName:self.name];
}

- (void)deleteObject:(id)object {
[self.storage deleteObject:object];
}
Expand All @@ -116,18 +116,9 @@ - (void)deleteAllObjects {
[self.storage deleteAllObjectsForBucketName:self.name];
}

- (void)updateDictionaryForKey:(NSString *)key {
// id<SPDiffable>object = [storage objectForKey:key entityName:self.name];
// if (!object) {
// object = [storage insertNewObjectForEntityForName:self.name simperiumKey:key];
// }
// [object loadMemberData:data];
}

- (void)validateObjects {
// Allow the storage to determine the most efficient way to validate everything
[self.storage validateObjectsForBucketName:self.name];

[self.storage save];
}

Expand All @@ -136,10 +127,6 @@ - (void)unloadAllObjects {
[self.relationshipResolver reset:self.storage];
}

- (void)insertObject:(NSDictionary *)object atIndex:(NSUInteger)index {

}

- (NSArray *)objectsForKeys:(NSSet *)keys {
return [self.storage objectsForKeys:keys bucketName:self.name];
}
Expand All @@ -148,7 +135,6 @@ - (NSArray *)objectsForPredicate:(NSPredicate *)predicate {
return [self.storage objectsForBucketName:self.name predicate:predicate];
}


- (NSInteger)numObjects {
return [self.storage numObjectsForBucketName:self.name predicate:nil];
}
Expand Down

0 comments on commit 30663dc

Please sign in to comment.