Commits

Tuukka Norri  committed 1edbe0f

Trying to sort out run loop -related issues by using a BaseTen-specific mode which is also made common

  • Participants
  • Parent commits 99d05ae

Comments (0)

Files changed (6)

File Sources/BXConstants.h

 BX_EXPORT NSString* const kBXRelationshipsKey;
 BX_EXPORT NSString* const kBXPredicateKey;
 BX_EXPORT NSString* const kBXOwnerObjectVariableName;
+BX_EXPORT NSString* const kBXRunLoopCommonMode;
 
 BX_EXPORT NSString* const kBXErrorDomain;
 BX_EXPORT NSString* const kBXErrorMessageKey;

File Sources/BXConstants.m

 
 NSString* const kBXErrorDomain = @"kBXErrorDomain";
 NSString* const kBXErrorMessageKey = @"kBXErrorMessageKey";
-NSString* const kBXObjectKey = @"kBXObjectKey";
+NSString* const kBXObjectKey = @"kBXObjectKey";
+
+NSString* const kBXRunLoopCommonMode = @"kBXRunLoopCommonMode";

File Sources/PGTSConnection.h

 - (SSL *) SSLStruct;
 - (CFSocketRef) socket;
 - (BOOL) canSend;
+- (void) setCFRunLoop: (CFRunLoopRef) aRef;
 
 - (id <PGTSCertificateVerificationDelegate>) certificateVerificationDelegate;
 - (void) setCertificateVerificationDelegate: (id <PGTSCertificateVerificationDelegate>) anObject;

File Sources/PGTSConnection.mm

 #import "BXLogger.h"
 #import "BXEnumerate.h"
 #import "BXArraySize.h"
+#import "BXConstants.h"
 
 #import "NSString+PGTSAdditions.h"
 
 	{
 		mQueue = [[NSMutableArray alloc] init];
 		mCertificateVerificationDelegate = [PGTSCertificateVerificationDelegate defaultCertificateVerificationDelegate];
+		[self setCFRunLoop: CFRunLoopGetCurrent ()];
 	}
 	return self;
 }
 
+- (void) setCFRunLoop: (CFRunLoopRef) aRef
+{
+	if (mRunLoop != aRef)
+	{
+		if (mRunLoop) CFRelease (mRunLoop);
+		if (aRef)
+		{
+			mRunLoop = aRef;
+			CFRetain (mRunLoop);
+			CFRunLoopAddCommonMode (mRunLoop, (CFStringRef) kBXRunLoopCommonMode);
+		}
+	}
+}
+
 - (void) freeCFTypes
 {
 	//Don't release the connection. Delegate will handle it.
 		BXAssertLog (mSocketSource, @"Expected socketSource to have been created.");
 		BXAssertLog (CFRunLoopSourceIsValid (mSocketSource), @"Expected socketSource to be valid.");
 		
-		CFRunLoopRef runloop = mRunLoop ?: CFRunLoopGetCurrent ();
-		CFStringRef mode = kCFRunLoopCommonModes;
 		CFSocketDisableCallBacks (mSocket, kCFSocketWriteCallBack);
 		CFSocketEnableCallBacks (mSocket, kCFSocketReadCallBack);
-		CFRunLoopAddSource (runloop, mSocketSource, mode);
+		CFRunLoopAddSource (mRunLoop, mSocketSource, (CFStringRef) kBXRunLoopCommonMode);
 		
-		[self beginTrackingNetworkStatusIn: runloop mode: mode];
+		[self beginTrackingNetworkStatusIn: mRunLoop mode: (CFStringRef) kBXRunLoopCommonMode];
 		
 		if (0 < [mQueue count])
 			[self sendNextQuery];

File Sources/PGTSConnectionMonitor.m

 #import "PGTSProbes.h"
 #import "BXLogger.h"
 #import "BXArraySize.h"
+#import "BXConstants.h"
 #import <IOKit/pwr_mgt/IOPMLib.h>
 #import <IOKit/IOMessage.h>
 #import <AppKit/AppKit.h>
 		IONotificationPortRef ioNotificationPort = NULL;
 		mIOPowerSession = IORegisterForSystemPower (self, &ioNotificationPort, &WorkspaceWillSleep, &ioNotifier);
 		if (mIOPowerSession)
-			CFRunLoopAddSource (CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource (ioNotificationPort), kCFRunLoopCommonModes);
+		{
+			CFRunLoopRef rl = CFRunLoopGetCurrent ();
+			CFRunLoopAddCommonMode (rl, (CFStringRef) kBXRunLoopCommonMode);
+			CFRunLoopAddSource (rl, IONotificationPortGetRunLoopSource (ioNotificationPort), (CFStringRef) kBXRunLoopCommonMode);
+		}
 		else
+		{
 			BXLogError (@"Failed to register for system sleep.");
+		}
 	}
 	return self;
 }

File Sources/PGTSConnector.m

 #import "PGTSConnector.h"
 #import "PGTSConnection.h"
 #import "PGTSConstants.h"
+#import "BXConstants.h"
 #import "PGTSCertificateVerificationDelegateProtocol.h"
 #import "BXLogger.h"
 #import "BXError.h"
 ScheduleHost (CFHostRef theHost, CFRunLoopRef theRunLoop)
 {
 	if (theHost && theRunLoop)
-		CFHostUnscheduleFromRunLoop (theHost, theRunLoop, kCFRunLoopCommonModes);
+		CFHostUnscheduleFromRunLoop (theHost, theRunLoop, (CFStringRef) kBXRunLoopCommonMode);
 }
 
 
 UnscheduleHost (CFHostRef theHost, CFRunLoopRef theRunLoop)
 {
 	if (theHost && theRunLoop)
-		CFHostScheduleWithRunLoop (theHost, theRunLoop, kCFRunLoopCommonModes);
+		CFHostScheduleWithRunLoop (theHost, theRunLoop, (CFStringRef) kBXRunLoopCommonMode);
 }
 
 
 	if ((self = [super init]))
 	{
 		mExpectedCallBack = 0;
+		[self setCFRunLoop: CFRunLoopGetCurrent ()];
 	}
 	return self;
 }
 		{
 			mRunLoop = aRef;
 			CFRetain (mRunLoop);
+			CFRunLoopAddCommonMode (mRunLoop, (CFStringRef) kBXRunLoopCommonMode);
 		}
 	}
 }
 	if (0 < [name length] && '/' != [name characterAtIndex: 0])
 	{
 		Boolean status = FALSE;
-		CFRunLoopRef runloop = mRunLoop ?: CFRunLoopGetCurrent ();
 		CFHostClientContext ctx = {
 			0,
 			self,
 		mHost = CFHostCreateWithName (NULL, (CFStringRef) name);
 		status = CFHostSetClient (mHost, &HostReady, &ctx);
 		BXLogDebug (@"Set host client: %d.", status);
-		ScheduleHost (mHost, runloop);
+		ScheduleHost (mHost, mRunLoop);
 		
 		status = CFHostStartInfoResolution (mHost, kCFHostAddresses, &mHostError);
 		BXLogDebug (@"Started host info resolution: %d.", status);
 		if (! status)
 		{
-			UnscheduleHost (mHost, runloop);
+			UnscheduleHost (mHost, mRunLoop);
 			[self continueFromNameResolution: &mHostError];
 		}
 	}
 	BXAssertLog (mSocketSource, @"Expected socketSource to have been created.");
 	BXAssertLog (CFRunLoopSourceIsValid (mSocketSource), @"Expected socketSource to be valid.");
 	
-	CFRunLoopRef runloop = mRunLoop ?: CFRunLoopGetCurrent ();
 	CFSocketDisableCallBacks (mSocket, kCFSocketReadCallBack);
 	CFSocketEnableCallBacks (mSocket, kCFSocketWriteCallBack);
 	mExpectedCallBack = kCFSocketWriteCallBack;
-	CFRunLoopAddSource (runloop, mSocketSource, kCFRunLoopCommonModes);
+	CFRunLoopAddSource (mRunLoop, mSocketSource, (CFStringRef) kBXRunLoopCommonMode);
 }
 @end