[39747] branches/gsoc08-framework/MacPorts_Framework_Release

armahg at macports.org armahg at macports.org
Tue Sep 2 23:35:55 PDT 2008


Revision: 39747
          http://trac.macosforge.org/projects/macports/changeset/39747
Author:   armahg at macports.org
Date:     2008-09-02 23:35:55 -0700 (Tue, 02 Sep 2008)
Log Message:
-----------
Completed implementation of IPC notifications. The currently executing command is now stored in the current thread's dictionary with the key currentMethod. This is the cleanest option so far for storing and passing that information

Modified Paths:
--------------
    branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolIPCTester.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h
    branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h
    branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPPort.m

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolIPCTester.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolIPCTester.m	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolIPCTester.m	2008-09-03 06:35:55 UTC (rev 39747)
@@ -18,9 +18,68 @@
 }
 -(BOOL) installUninstallManipulation:(NSString *)portName;
 -(BOOL) selfUpdate;
+-(void) registerForLocalNotifications;
+
 @end
 
 @implementation PortManipulator
+
+-(id) init {
+	self = [super init];
+	if (self != nil) {
+		//[self registerForLocalNotifications];
+	}
+	return self;
+}
+
+-(void) registerForLocalNotifications {
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:MPINFO
+											   object:nil];
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:MPMSG
+											   object:nil];
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:MPERROR
+											   object:nil];
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:MPWARN
+											   object:nil];
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:MPDEBUG
+											   object:nil];
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:MPDEFAULT
+											   object:nil];
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(respondToLocalNotification:) 
+												 name:@"testMacPortsNotification"
+											   object:nil];
+}
+
+-(void) respondToLocalNotification:(NSNotification *)notification {
+	id sentDict = [notification userInfo];
+	
+	//Just NSLog it for now
+	if(sentDict == nil)
+		NSLog(@"MPMacPorts received notification with empty userInfo Dictionary");
+	else
+		NSLog(@"MPMacPorts received notification with userInfo %@" , [sentDict description]);
+}
+
+
 -(BOOL) selfUpdate {
 	NSError *err = nil;
 	[[MPMacPorts sharedInstance] selfUpdate:&err];
@@ -108,27 +167,27 @@
 	
 	[[MPMacPorts sharedInstance] setAuthorizationMode:YES];
 	
-	PortManipulator * pm = [[PortManipulator alloc] init];
+//	PortManipulator * pm = [[PortManipulator alloc] init];
+//	
+//	if([pm installUninstallManipulation:@"pngcrush"]) {
+//		NSLog(@"pngcrush INSTALLATION SUCCESSFUL");
+//	}
+//	else {
+//		NSLog(@"pngcrush INSTALLATION UNSUCCESSFUL");
+//	}
+//	
+//	if([pm selfUpdate]) {
+//		NSLog(@"SELFUPDATE SUCCESSFUL");
+//	}
+//	else {
+//		NSLog(@"SELFUPDATE UNSUCCESSFUL");
+//	}
+//	
+//	
+//	[pm release];
 	
-	if([pm installUninstallManipulation:@"pngcrush"]) {
-		NSLog(@"pngcrush INSTALLATION SUCCESSFUL");
-	}
-	else {
-		NSLog(@"pngcrush INSTALLATION UNSUCCESSFUL");
-	}
 	
-	if([pm selfUpdate]) {
-		NSLog(@"SELFUPDATE SUCCESSFUL");
-	}
-	else {
-		NSLog(@"SELFUPDATE UNSUCCESSFUL");
-	}
 	
-	
-	[pm release];
-	
-	
-	
 	//[pool release];
 	
 	return 0;

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-09-03 06:35:55 UTC (rev 39747)
@@ -108,17 +108,7 @@
 		
 		//Get the Tcl function that called this method
 		if (! [[mln performingTclCommand] isEqualToString:@""]) {
-			NSArray * cmd = [[mln performingTclCommand] componentsSeparatedByString:@"_"];
-			
-			//if code is working right, this value should always be YES
-			//when we are in this part of the code
-			if([cmd count] > 0) {
-				//NSLog(@"Class type is %@", NSStringFromClass([[cmd objectAtIndex:0] class]));
-				
-				if( [[cmd objectAtIndex:0] isEqualToString:@"YES"]) {
-					[info setObject:[cmd objectAtIndex:1] forKey:MPMETHOD];
-				}
-			}
+			[info setObject:[mln performingTclCommand] forKey:MPMETHOD];
 		}		
 		if (global != 0) {
 			[[NSDistributedNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:info];
@@ -420,16 +410,23 @@
 	//if ([notificationObject respondsToSelector:@selector(startServerThread)]) {
 	NSThread * cThread = [NSThread currentThread];
 	NSLog(@"STARTING SERVER THREAD with previous thread %@", [cThread threadDictionary]);
+	
+	//This is important to note ... the tcl command being executed is saved in the
+	//current thread's thread dictionary in the upper tier method that calls this one. 
+	// This means we are only going to guarantee
+	//thread saftey for Framework clients at the the level of MPMacPorts, MPPorts etc. and above
+	NSDictionary * serverInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+								 ipcFilePathCopy, @"ipcFilePath",
+								 [[MPNotifications sharedListener] performingTclCommand], @"currentMethod",
+								 nil];
+	
 	[NSThread detachNewThreadSelector:@selector(startIPCServerThread:) 
 							 toTarget:notificationObject 
-						   withObject:ipcFilePathCopy];
+						   withObject:serverInfo];
 	//[notificationObject startIPCServerThread];
 	//}
 	
 	
-	
-	
-	
 	//Retrieving the path for interpInit.tcl for our helper tool
 	NSString * interpInitPath = [[NSBundle bundleForClass:[MPInterpreter class]] 
 								 pathForResource:@"interpInit" ofType:@"tcl"];

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m	2008-09-03 06:35:55 UTC (rev 39747)
@@ -108,7 +108,7 @@
 	
 	// This needs to throw an exception if things don't go well
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPorts_sync_Started" object:nil];
-	[[MPNotifications sharedListener] setPerformingTclCommand:@"YES_sync"];
+	[[MPNotifications sharedListener] setPerformingTclCommand:@"sync"];
 	
 	if ([self authorizationMode])
 		result = [interpreter evaluateStringWithMPHelperTool:@"mportsync" error:sError];
@@ -124,7 +124,7 @@
 - (void)selfUpdate:(NSError**)sError {
 	//Also needs to throw an exception if things don't go well
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPorts_selfupdate_Started" object:nil];
-	[[MPNotifications sharedListener] setPerformingTclCommand:@"YES_selfUpdate"];
+	[[MPNotifications sharedListener] setPerformingTclCommand:@"selfUpdate"];
 	
 	if([self authorizationMode])
 		[interpreter evaluateStringWithMPHelperTool:@"macports::selfupdate" error:sError];

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h	2008-09-03 06:35:55 UTC (rev 39747)
@@ -14,8 +14,8 @@
 @interface MPNotifications (IPCAdditions) 
 -(BOOL) terminateBackgroundThread;
 -(void) setTerminateBackgroundThread:(BOOL)newStatus;
--(void) startIPCServerThread:(NSString *) socketFilePath;
+-(void) startIPCServerThread:(NSDictionary *)serverInfo;
 -(void) prepareIPCServerThread;
 -(void) stopIPCServerThread;
-
+-(void) sendIPCNotification:(NSString *)message;
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m	2008-09-03 06:35:55 UTC (rev 39747)
@@ -813,8 +813,13 @@
         //fprintf(stderr, "%p: Shout   \"%.*s\"\n", client, (int) sizeof(packet->fMessage), packet->fMessage);
 		
 		NSString * shout = [NSString stringWithCString:packet->fMessage encoding:NSUTF8StringEncoding];
-		NSLog(@"CLIENT SHOUT BEING CALLED (YAAAY!!) : %@" , shout);
-        
+		//NSLog(@"CLIENT SHOUT BEING CALLED (YAAAY!!) : %@" , shout);
+		[[MPNotifications sharedListener] sendIPCNotification:shout];
+//		[[NSNotificationCenter defaultCenter] postNotificationName:MPINFO 
+//															object:nil 
+//														  userInfo:[NSDictionary dictionaryWithObjectsAndKeys:shout, MPMESSAGE, nil]];
+		
+
         // We make a snapshot of the client list because clients might disappear 
         // as we talk to them.  That is, the act of talking to the client might 
         // cause us to notice that the client is dead.
@@ -913,7 +918,7 @@
 		//loop running. For now i'm not synchronizing variable access since the
 		//worst that could happen is that the server is late in reading a chaged
 		//value update
-		//clientHasQuit = 1;
+		clientHasQuit = 1;
     }
 	
 	return result;
@@ -1344,11 +1349,14 @@
 	terminateBackgroundThread = newStatus;
 }
 
--(void) startIPCServerThread:(NSString *)socketFilePath {
+-(void) startIPCServerThread:(NSDictionary *)serverInfo {
 	NSAutoreleasePool * sPool = [[NSAutoreleasePool alloc] init];
 	
 	NSLog(@"INSIDE SERVER THREAD");
 	
+	[[MPNotifications sharedListener] 
+	 setPerformingTclCommand:[serverInfo objectForKey:@"currentMethod"]];
+	
 	//Configure runloop
 	int         err = 0;
     int         listenerFD;
@@ -1411,11 +1419,8 @@
     }
     if (err == 0) {
         //err = SafeBindUnixDomainSocket(listenerFD, kServerSocketPath);
-		NSLog(@"Socket file path is %@", socketFilePath);
-		
-		char testPath [MAXPATHLEN];
-		strcpy(testPath, [socketFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
-        err = SafeBindUnixDomainSocket(listenerFD, [socketFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
+		//NSLog(@"Socket file path is %@", socketFilePath);
+		err = SafeBindUnixDomainSocket(listenerFD, [[serverInfo objectForKey:@"ipcFilePath"] cStringUsingEncoding:NSUTF8StringEncoding]);
 		didBind = (err == 0);
 		NSLog(@"Binding Socket %i", err);
     }
@@ -1481,6 +1486,7 @@
 	//check to ensure that that doesn't create problems
 	CFRunLoopStop([currentLoop getCFRunLoop]);
 	
+	[[MPNotifications sharedListener] setPerformingTclCommand:@""];
 	[sPool release];
 }
 
@@ -1492,5 +1498,24 @@
 	terminateBackgroundThread == YES;
 }
 
-
+-(void) sendIPCNotification:(NSString *)message {
+	NSArray * array = [message componentsSeparatedByString:MPSEPARATOR];
+	
+	//Strip off "--->" from message
+	NSMutableString * msg = [NSMutableString stringWithString:[array objectAtIndex:3]];
+	[msg setString:[[msg componentsSeparatedByString:@"--->"] componentsJoinedByString:@""]];
+	
+	// Array is of the form 
+    // Notification type, MPCHANNEL, MPPREFIX, MPMESSAGE
+	// e.g. MPInfoNotification_&MP&_stdout_&MP&_None_&MP&_total size is 18781178  speedup is 57.00
+	NSDictionary * userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+									  [[MPNotifications sharedListener] performingTclCommand], MPMETHOD,
+									  [array objectAtIndex:1], MPCHANNEL,
+									  [array objectAtIndex:2], MPPREFIX,
+									  msg, MPMESSAGE,  nil];
+	
+	[[NSNotificationCenter defaultCenter] postNotificationName:[array objectAtIndex:0] 
+														object:nil 
+													  userInfo:userInfo];
+}
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h	2008-09-03 06:35:55 UTC (rev 39747)
@@ -72,8 +72,8 @@
 #define MPDEBUG @"MPDebugNotification"
 #define MPALL @"MPAllNotification"
 
+#import "MPInterpreter.h"
 
-
 /*!
  @class MPNotifications
  @abstract A class to handle notifying Framework clients of port activity
@@ -134,6 +134,7 @@
 //These methods aren't for the public ... yet ...
 -(void)setPerformingTclCommand:(NSString *)string;
 -(NSString *)performingTclCommand;
+-(BOOL) postNotificationOnMainThread:(NSString *) message;
 
 
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m	2008-09-03 06:35:55 UTC (rev 39747)
@@ -99,20 +99,6 @@
 	[super dealloc];
 }
 
-
-- (void) setPerformingTclCommand:(NSString *)tclString {
-	
-	if(performingTclCommand != tclString){
-		[performingTclCommand release];
-		performingTclCommand = [tclString copy];
-	}
-	
-}
-
-- (NSString *) performingTclCommand {
-	return performingTclCommand;
-}
-
 //Should I raise an exception for invalid blockOptions that are
 //passed to this method?
 -(BOOL)checkIfNotificationBlocked:(NSString *)option {
@@ -137,6 +123,38 @@
 	}
 }
 
+#pragma mark -
+#pragma mark Private Methods
 
+-(BOOL) postNotificationOnMainThread:(NSString *) message {
+//	[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MPINFO 
+//																		object:nil 
+//																	  userInfo:[NSDictionary dictionaryWithObjectsAndKeys:message, MPMESSAGE, nil]];
+	[[NSNotificationCenter defaultCenter] postNotificationName:MPINFO 
+															object:nil 
+														  userInfo:[NSDictionary dictionaryWithObjectsAndKeys:message, MPMESSAGE, nil]];
+	
+	return YES;
+}
 
+
+- (void) setPerformingTclCommand:(NSString *)tclString {
+	
+	[[[NSThread currentThread] threadDictionary] setObject:tclString forKey:@"performingTclCommand"];
+	
+//	if(performingTclCommand != tclString){
+//		[performingTclCommand release];
+//		performingTclCommand = [tclString copy];
+//	}
+	
+}
+
+- (NSString *) performingTclCommand {
+//	return performingTclCommand;
+	id tclCmd = [[[NSThread currentThread] threadDictionary] objectForKey:@"performingTclCommand"];
+	if (tclCmd == nil)
+		return @"";
+	return tclCmd;
+}
+
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPPort.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPPort.m	2008-09-03 03:01:28 UTC (rev 39746)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPPort.m	2008-09-03 06:35:55 UTC (rev 39747)
@@ -193,8 +193,8 @@
 	
 	//Send Global Notifications and update MPNotifications variable
 	[self sendGlobalExecNotification:procedure withStatus:@"Started"];
-	NSString * tclCmd = [@"YES_" stringByAppendingString:procedure];
-	[[MPNotifications sharedListener] setPerformingTclCommand:tclCmd];
+	//NSString * tclCmd = [@"YES_" stringByAppendingString:procedure];
+	[[MPNotifications sharedListener] setPerformingTclCommand:procedure];
 	
 	if ([parentMacPortsInstance authorizationMode]) {
 		[interpreter evaluateStringWithMPHelperTool: 
@@ -238,8 +238,8 @@
 	
 	//Send Global Notifications and update MPNotifications variable
 	[self sendGlobalExecNotification:target withStatus:@"Started"];
-	NSString * tclCmd = [@"YES_" stringByAppendingString:target];
-	[[MPNotifications sharedListener] setPerformingTclCommand:tclCmd];
+	//NSString * tclCmd = [@"YES_" stringByAppendingString:target];
+	[[MPNotifications sharedListener] setPerformingTclCommand:target];
 	
 	if ([parentMacPortsInstance authorizationMode]) {
 		[interpreter evaluateStringWithMPHelperTool:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080902/fb426f84/attachment.html 


More information about the macports-changes mailing list