Author: ericwa Date: Mon Mar 24 08:14:37 2014 New Revision: 10624 URL: http://svn.gna.org/viewcvs/etoile?rev=10624&view=rev Log: COSynchronizerJSON: don't mix up message order for queued messages
Modified: trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.h trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.m trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.h trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.m Modified: trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.h URL: http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.h?rev=10624&r1=10623&r2=10624&view=diff ============================================================================== --- trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.h (original) +++ trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.h Mon Mar 24 08:14:37 2014 @@ -19,8 +19,7 @@ @interface COSynchronizerJSONClient : NSObject <COSynchronizerClientDelegate> { - NSMutableArray *queuedOutgoingMessages; - NSMutableArray *queuedIncomingMessages; + NSMutableArray *queuedMessages; BOOL paused; } Modified: trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.m URL: http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.m?rev=10624&r1=10623&r2=10624&view=diff ============================================================================== --- trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.m (original) +++ trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONClient.m Mon Mar 24 08:14:37 2014 @@ -21,8 +21,7 @@ - (instancetype) init { SUPERINIT; - queuedOutgoingMessages = [NSMutableArray new]; - queuedIncomingMessages = [NSMutableArray new]; + queuedMessages = [NSMutableArray new]; return self; } - (void) sendPropertyListToServer: (id)aPropertyList @@ -30,7 +29,7 @@ NSString *text = [COSynchronizerJSONUtils serializePropertyList: aPropertyList]; if (paused) { - [queuedOutgoingMessages addObject: text]; + [queuedMessages addObject: @{ @"text" : text, @"type" : @"outgoing" }]; } else { @@ -81,7 +80,7 @@ { if (paused) { - [queuedIncomingMessages addObject: text]; + [queuedMessages addObject: @{ @"text" : text, @"type" : @"incoming" }]; } else { @@ -117,30 +116,21 @@ [delegate JSONClient: self sendTextToServer: text]; } -- (void) processQueuedIncomingMessages -{ - NSArray *incomingMessages = [NSArray arrayWithArray: queuedIncomingMessages]; - [queuedIncomingMessages removeAllObjects]; - for (NSString *incomingMessage in incomingMessages) - { - [self processIncomingText: incomingMessage]; - } -} - -- (void) processQueuedOutgoingMessages -{ - NSArray *outgoingMessages = [NSArray arrayWithArray: queuedOutgoingMessages]; - [queuedOutgoingMessages removeAllObjects]; - for (NSString *outgoingMessage in outgoingMessages) - { - [self processOutgoingText: outgoingMessage]; - } -} - - (void) processQueuedMessages { - [self processQueuedIncomingMessages]; - [self processQueuedOutgoingMessages]; + NSArray *messages = [NSArray arrayWithArray: queuedMessages]; + [queuedMessages removeAllObjects]; + for (NSDictionary *msg in messages) + { + if ([msg[@"type"] isEqualToString: @"incoming"]) + { + [self processIncomingText: msg[@"text"]]; + } + else + { + [self processOutgoingText: msg[@"text"]]; + } + } } - (BOOL) paused Modified: trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.h URL: http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.h?rev=10624&r1=10623&r2=10624&view=diff ============================================================================== --- trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.h (original) +++ trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.h Mon Mar 24 08:14:37 2014 @@ -17,8 +17,7 @@ @interface COSynchronizerJSONServer : NSObject <COSynchronizerServerDelegate> { - NSMutableDictionary *queuedOutgoingMessagesByClient; - NSMutableArray *queuedIncomingMessages; + NSMutableArray *queuedMessages; BOOL paused; } Modified: trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.m URL: http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.m?rev=10624&r1=10623&r2=10624&view=diff ============================================================================== --- trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.m (original) +++ trunk/Etoile/Frameworks/CoreObject/Synchronization/COSynchronizerJSONServer.m Mon Mar 24 08:14:37 2014 @@ -21,8 +21,7 @@ - (instancetype) init { SUPERINIT; - queuedOutgoingMessagesByClient = [NSMutableDictionary new]; - queuedIncomingMessages = [NSMutableArray new]; + queuedMessages = [NSMutableArray new]; return self; } @@ -32,13 +31,7 @@ if (paused) { - NSMutableArray *userQueue = queuedOutgoingMessagesByClient[aClient]; - if (userQueue == nil) - { - userQueue = [NSMutableArray new]; - queuedOutgoingMessagesByClient[aClient] = userQueue; - } - [userQueue addObject: text]; + [queuedMessages addObject: @{ @"text" : text, @"type" : @"outgoing", @"client" : aClient }]; } else { @@ -100,7 +93,7 @@ { if (paused) { - [queuedIncomingMessages addObject: text]; + [queuedMessages addObject: @{ @"text" : text, @"type" : @"incoming", @"client" : aClient }]; } else { @@ -123,33 +116,21 @@ } } -- (void) processQueuedIncomingMessages +- (void) processQueuedMessages { - NSArray *incomingMessages = [NSArray arrayWithArray: queuedIncomingMessages]; - [queuedIncomingMessages removeAllObjects]; - for (NSString *incomingMessage in incomingMessages) + NSArray *messages = [NSArray arrayWithArray: queuedMessages]; + [queuedMessages removeAllObjects]; + for (NSDictionary *msg in messages) { - [self processIncomingText: incomingMessage]; - } -} - -- (void) processQueuedOutgoingMessages -{ - for (NSString *aClient in queuedOutgoingMessagesByClient) - { - NSArray *messages = queuedOutgoingMessagesByClient[aClient]; - for (NSString *text in messages) + if ([msg[@"type"] isEqualToString: @"incoming"]) { - [delegate JSONServer: self sendText: text toClient: aClient]; + [self processIncomingText: msg[@"text"]]; + } + else + { + [delegate JSONServer: self sendText: msg[@"text"] toClient: msg[@"client"]]; } } - [queuedOutgoingMessagesByClient removeAllObjects]; -} - -- (void) processQueuedMessages -{ - [self processQueuedIncomingMessages]; - [self processQueuedOutgoingMessages]; } - (BOOL) paused _______________________________________________ Etoile-cvs mailing list Etoile-cvs@gna.org https://mail.gna.org/listinfo/etoile-cvs