Commits

Tuukka Norri committed 7dd248c

GCD
- Added an accessor to BXSocketDescriptor for allowing the use of GCD.
- Both CFRunLoop and GCD based descriptors are now tested.

Comments (0)

Files changed (6)

BaseTen.xcodeproj/project.pbxproj

 		53877EAE0E27667B0097C35F /* PGTSConstantValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 53877EAC0E27667B0097C35F /* PGTSConstantValue.m */; };
 		53877EEB0E2773E30097C35F /* NSRelationshipDescription+BXPGAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 53877EE90E2773E30097C35F /* NSRelationshipDescription+BXPGAdditions.h */; };
 		53877EEC0E2773E30097C35F /* NSRelationshipDescription+BXPGAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 53877EEA0E2773E30097C35F /* NSRelationshipDescription+BXPGAdditions.m */; };
-		538E031C11A4A5F700C3447F /* BXSocketDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E031A11A4A5F700C3447F /* BXSocketDescriptor.h */; };
+		538E031C11A4A5F700C3447F /* BXSocketDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E031A11A4A5F700C3447F /* BXSocketDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		538E031D11A4A5F700C3447F /* BXSocketDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 538E031B11A4A5F700C3447F /* BXSocketDescriptor.m */; };
 		538E032011A4A61F00C3447F /* BXRunLoopSocketDesciptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E031E11A4A61F00C3447F /* BXRunLoopSocketDesciptor.h */; };
 		538E032111A4A61F00C3447F /* BXRunLoopSocketDesciptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 538E031F11A4A61F00C3447F /* BXRunLoopSocketDesciptor.m */; };

Sources/BXDispatchSocketDescriptor.m

 
 - (id) initWithSocket: (int) socket
 {
-	if ((self = [super init]))
+	if ((self = [super initWithSocket: socket]))
 	{
 		mSocket = socket;
 	}

Sources/BXSocketDescriptor.h

 	BXValidationLock *mValidationLock;
 	id <BXSocketDescriptorDelegate> mDelegate;
 }
++ (BOOL) usesGCD;
++ (void) setUsesGCD: (BOOL) useGCD;
+
 + (id) copyDescriptorWithSocket: (int) socket;
 - (id) initWithSocket: (int) socket;
 - (void) install;

Sources/BXSocketDescriptor.m

 #import <dispatch/dispatch.h>
 
 
+static volatile BOOL stUsesGCD = NO;
+
 
 /** 
  * \internal
  * \ingroup basetenutility
  */
 @implementation BXSocketDescriptor
++ (BOOL) usesGCD
+{
+	BOOL retval = NO;
+	@synchronized (self)
+	{
+		retval = stUsesGCD;
+	}
+	return retval;
+}
+
+
++ (void) setUsesGCD: (BOOL) useGCD
+{
+	@synchronized (self)
+	{
+		stUsesGCD = useGCD;
+	}
+}
+
+
 /** 
  * \brief Instantiate an event source.
  */
 + (id) copyDescriptorWithSocket: (int) socket
 {
 	id retval = nil;
-#if 0 // Enable after testing.
-	if (NULL != dispatch_get_current_queue)
-		retval = [[BXDispatchSocketDescriptor alloc] initWithSocket: socket];
-	else
-#endif
-		retval = [[BXRunLoopSocketDesciptor alloc] initWithSocket: socket];
+	@synchronized (self)
+	{
+		if (NULL != dispatch_get_current_queue && stUsesGCD)
+			retval = [[BXDispatchSocketDescriptor alloc] initWithSocket: socket];
+		else
+			retval = [[BXRunLoopSocketDesciptor alloc] initWithSocket: socket];
+	}
 	
 	return retval;
 }

Sources/PGTSConnection.mm

 
 	if ([notifications count])
 	{
+		BXLogInfo (@"Received %lu notifications.", [notifications count]);
 		id <PGTSConnectionDelegate> delegate = [self delegate];
 		for (PGTSNotification *notification in notifications)
 			[delegate PGTSConnection: self gotNotification: notification];

UnitTests/Sources/TestLoader.m

 #import "TestLoader.h"
 #import <BaseTen/BaseTen.h>
 #import <BaseTen/BXLogger.h>
+#import <BaseTen/BXSocketDescriptor.h>
 #import "MKCSenTestCaseAdditions.h"
 
 #import "PGTSInvocationRecorderTests.h"
 	
 	//testClasses = [NSArray arrayWithObject: [BXHostResolverTests class]];
 	
-	for (Class testCaseClass in testClasses)
+	for (int i = 0; i < 2; i++)
 	{
-		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-		SenTestSuite *suite = [SenTestSuite testSuiteForTestCaseClass: testCaseClass];
-		SenTestRun *testRun = [suite run];
-		STAssertTrue (0 == [testRun unexpectedExceptionCount], @"Had %u unexpected exceptions.", [testRun unexpectedExceptionCount]);
-		[pool drain];
+		if (1 == i)
+		{
+			[BXSocketDescriptor setUsesGCD: YES];
+			NSLog (@"Using GCD with BXSocketDescriptor.");
+		}
+		else
+		{
+			[BXSocketDescriptor setUsesGCD: NO];
+			NSLog (@"Not using GCD with BXSocketDescriptor.");
+		}
+		
+		for (Class testCaseClass in testClasses)
+		{
+			NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+			SenTestSuite *suite = [SenTestSuite testSuiteForTestCaseClass: testCaseClass];
+			SenTestRun *testRun = [suite run];
+			STAssertTrue (0 == [testRun unexpectedExceptionCount], @"Had %u unexpected exceptions.", [testRun unexpectedExceptionCount]);
+			[pool drain];
+		}
 	}
 }
 @end