From: Fraser S. <fra...@us...> - 2004-10-10 21:42:50
|
Update of /cvsroot/ljkit/LJKit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26675 Modified Files: LJAccount.m Log Message: Converted LJAccount to post all its notifications using -[NSObject performSelectorOnMainThread] which makes calling login asynchronously much more reliable Index: LJAccount.m =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount.m,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** LJAccount.m 10 Oct 2004 16:35:51 -0000 1.10 --- LJAccount.m 10 Oct 2004 21:42:12 -0000 1.11 *************** *** 421,426 **** if (parameters) [info setObject:parameters forKey:@"LJParameters"]; [info setObject:[NSNumber numberWithInt:(connectionID++)] forKey:@"LJConnection"]; ! [noticeCenter postNotificationName:LJAccountWillConnectNotification ! object:self userInfo:info]; // Do the dirty deed. NS_DURING --- 421,432 ---- if (parameters) [info setObject:parameters forKey:@"LJParameters"]; [info setObject:[NSNumber numberWithInt:(connectionID++)] forKey:@"LJConnection"]; ! ! // [FS] Fire notification with -performSelectorOnMainThread: ! NSNotification *willLoginNote = [NSNotification notificationWithName: LJAccountWillConnectNotification object: self userInfo: info]; ! [noticeCenter performSelectorOnMainThread: @selector(postNotification:) ! withObject: willLoginNote ! waitUntilDone: YES]; ! // End change. ! // Do the dirty deed. NS_DURING *************** *** 449,454 **** if (reply) [info setObject:reply forKey:@"LJReply"]; if (exception) [info setObject:exception forKey:@"LJException"]; ! [noticeCenter postNotificationName:LJAccountDidConnectNotification ! object:self userInfo:info]; [info release]; [exception raise]; // will do nothing if no exception was set --- 455,468 ---- if (reply) [info setObject:reply forKey:@"LJReply"]; if (exception) [info setObject:exception forKey:@"LJException"]; ! ! // [FS] Change to fire notification onMainThread. ! NSNotification *didLoginNote = [NSNotification notificationWithName: LJAccountDidConnectNotification ! object: self ! userInfo: info]; ! [noticeCenter performSelectorOnMainThread: @selector(postNotification:) ! withObject: didLoginNote ! waitUntilDone: YES]; ! // end ! [info release]; [exception raise]; // will do nothing if no exception was set *************** *** 490,495 **** NSAssert(password != nil, @"Password must not be nil."); NSAssert((loginFlags & LJReservedLoginFlags) == 0, @"A reserved login flag was set."); ! [noticeCenter postNotificationName:LJAccountWillLoginNotification ! object:self userInfo:nil]; [self willChangeValueForKey:@"isLoggedIn"]; // Configure server object with login information. --- 504,518 ---- NSAssert(password != nil, @"Password must not be nil."); NSAssert((loginFlags & LJReservedLoginFlags) == 0, @"A reserved login flag was set."); ! ! // [FS] Convert to fire notification onMainThread ! NSNotification *loginNote = [NSNotification notificationWithName: LJAccountWillLoginNotification ! object: self ! userInfo: nil]; ! [noticeCenter performSelectorOnMainThread: @selector(postNotification:) ! withObject: loginNote ! waitUntilDone: YES]; ! ! // [FS] end change. ! [self willChangeValueForKey:@"isLoggedIn"]; // Configure server object with login information. *************** *** 519,524 **** info = [NSDictionary dictionaryWithObject:localException forKey:@"LJException"]; ! [noticeCenter postNotificationName:LJAccountDidNotLoginNotification ! object:self userInfo:info]; [localException raise]; NS_ENDHANDLER --- 542,555 ---- info = [NSDictionary dictionaryWithObject:localException forKey:@"LJException"]; ! ! // [FS] onMainThread conversion ! NSNotification *failureNote = [NSNotification notificationWithName: LJAccountDidNotLoginNotification ! object: self ! userInfo: info]; ! [noticeCenter performSelectorOnMainThread: @selector(postNotification:) ! withObject: failureNote ! waitUntilDone: YES]; ! // [FS] end. ! [localException raise]; NS_ENDHANDLER *************** *** 548,553 **** _isLoggedIn = YES; [self didChangeValueForKey:@"isLoggedIn"]; ! [noticeCenter postNotificationName:LJAccountDidLoginNotification ! object:self userInfo:nil]; } --- 579,591 ---- _isLoggedIn = YES; [self didChangeValueForKey:@"isLoggedIn"]; ! ! // [FS] onMainThread conversion ! NSNotification *successNote = [NSNotification notificationWithName: LJAccountDidLoginNotification ! object: self ! userInfo: nil]; ! [noticeCenter performSelectorOnMainThread: @selector(postNotification:) ! withObject: successNote ! waitUntilDone: YES]; ! // [FS] end change. } |