[54152] branches/gsoc09-gui/MacPorts_Framework

juanger at macports.org juanger at macports.org
Tue Jul 21 18:06:13 PDT 2009


Revision: 54152
          http://trac.macports.org/changeset/54152
Author:   juanger at macports.org
Date:     2009-07-21 18:06:12 -0700 (Tue, 21 Jul 2009)
Log Message:
-----------
New Notifications for MPPortProcess

Modified Paths:
--------------
    branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m
    branches/gsoc09-gui/MacPorts_Framework/MPPortProcess.m
    branches/gsoc09-gui/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj
    branches/gsoc09-gui/MacPorts_Framework/portProcessInit.tcl

Added Paths:
-----------
    branches/gsoc09-gui/MacPorts_Framework/SimpleLog.h
    branches/gsoc09-gui/MacPorts_Framework/SimpleLog.m

Modified: branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m	2009-07-22 00:53:23 UTC (rev 54151)
+++ branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m	2009-07-22 01:06:12 UTC (rev 54152)
@@ -458,23 +458,22 @@
 	NSString * firstResult;
 	NSString * secondResult;
 	
-	*mportError = nil;
-    //  firstResult = [self evaluateStringAsString:statement error:mportError];
-   	firstResult = [self evaluateStringWithMPPortProcess:statement error:mportError];
+	//*mportError = nil;
+   	//firstResult = [self evaluateStringWithMPPortProcess:statement error:mportError];
 	
 	//Because of string results of methods like mportsync (which returns the empty string)
 	//the only way to truly check for an error is to check the mportError parameter.
 	//If it is nil then there was no error, if not we re-evaluate with privileges using
 	//the helper tool
 	
-	if ( *mportError != nil) {
+	//if ( *mportError != nil) {
 		*mportError = nil; 
 		secondResult = [self evaluateStringWithMPHelperTool:statement error:mportError];
 		
 		return secondResult;
-	}
+	//}
 	
-	return firstResult;
+	//return firstResult;
 }
 
 //NOTE: We expect the Framework client to initialize the AuthorizationRef

Modified: branches/gsoc09-gui/MacPorts_Framework/MPPortProcess.m
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/MPPortProcess.m	2009-07-22 00:53:23 UTC (rev 54151)
+++ branches/gsoc09-gui/MacPorts_Framework/MPPortProcess.m	2009-07-22 01:06:12 UTC (rev 54152)
@@ -7,6 +7,7 @@
 //
 
 #import "MPPortProcess.h"
+#import "SimpleLog.h"
 
 @interface MPPortProcess (PrivateMethods)
 
@@ -23,6 +24,10 @@
     return self;
 }
 
+- (oneway void)setDelegate:(byref id)newDelegate {
+    delegate = newDelegate;
+}
+
 - (oneway void)evaluateString:(bycopy id)statement {
     // TODO Handle the posible errors and notifications
     Tcl_Eval(interpreter, [statement UTF8String]);
@@ -49,8 +54,11 @@
 		NSLog(@"Error in Tcl_EvalFile macports_fastload.tcl: %s", Tcl_GetStringResult(interpreter));
 		Tcl_DeleteInterp(interpreter);
 	}
-    // TODO Load notifications methods
-    
+    // Load notifications methods
+    Tcl_CreateObjCommand(interpreter, "simplelog", Notify_Command, NULL, NULL);
+	if (Tcl_PkgProvide(interpreter, "simplelog", "1.0") != TCL_OK) {
+		NSLog(@"Error in Tcl_PkgProvide: %s", Tcl_GetStringResult(interpreter));
+	}
     // Load portProcessInit.tcl
     NSString *portProcessInitPath = @"portProcessInit.tcl";
     if( Tcl_EvalFile(interpreter, [portProcessInitPath UTF8String]) == TCL_ERROR) {

Modified: branches/gsoc09-gui/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj	2009-07-22 00:53:23 UTC (rev 54151)
+++ branches/gsoc09-gui/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj	2009-07-22 01:06:12 UTC (rev 54152)
@@ -21,6 +21,8 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+		218DEE2610162091003B5A3B /* SimpleLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 218DED83101612F1003B5A3B /* SimpleLog.m */; };
+		218DEE3E10162157003B5A3B /* SimpleLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 218DED82101612F1003B5A3B /* SimpleLog.h */; };
 		21D95442100940FF00DEF58A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EB6FC900E45DEA80057962C /* Foundation.framework */; };
 		21D954431009411400DEF58A /* Tcl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA0F56E0DFEB55E00C15082 /* Tcl.framework */; };
 		21D954471009412F00DEF58A /* MPPortProcess.m in Sources */ = {isa = PBXBuildFile; fileRef = 21D954461009412F00DEF58A /* MPPortProcess.m */; };
@@ -128,6 +130,8 @@
 		089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
 		21067BB50FE5B25800CAD732 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = "<group>"; };
+		218DED82101612F1003B5A3B /* SimpleLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLog.h; sourceTree = "<group>"; };
+		218DED83101612F1003B5A3B /* SimpleLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SimpleLog.m; sourceTree = "<group>"; };
 		21D9543E100940EE00DEF58A /* MPPortProcess */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MPPortProcess; sourceTree = BUILT_PRODUCTS_DIR; };
 		21D954461009412F00DEF58A /* MPPortProcess.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPortProcess.m; sourceTree = "<group>"; };
 		21D954491009413800DEF58A /* MPPortProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPortProcess.h; sourceTree = "<group>"; };
@@ -187,7 +191,7 @@
 		6EE6DDAA0E626DC900FB2115 /* MPHelperToolIPCTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPHelperToolIPCTester.m; sourceTree = "<group>"; };
 		6EE6DDCC0E6276AA00FB2115 /* MPNotifications+IPCAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPNotifications+IPCAdditions.h"; sourceTree = "<group>"; };
 		6EE6DDCD0E6276AA00FB2115 /* MPNotifications+IPCAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPNotifications+IPCAdditions.m"; sourceTree = "<group>"; };
-		6EE93E660E493AC600AECE9E /* interpInit.tcl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = interpInit.tcl; sourceTree = "<group>"; };
+		6EE93E660E493AC600AECE9E /* interpInit.tcl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = interpInit.tcl; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.simpleColoring; };
 		6EE93E780E495B3100AECE9E /* Tcl.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Tcl.framework; path = Library/Frameworks/Tcl.framework; sourceTree = SDKROOT; };
 		8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
 		8DC2EF5B0486A6940098B216 /* MacPorts.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MacPorts.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -357,6 +361,8 @@
 			children = (
 				21D954491009413800DEF58A /* MPPortProcess.h */,
 				21D954461009412F00DEF58A /* MPPortProcess.m */,
+				218DED82101612F1003B5A3B /* SimpleLog.h */,
+				218DED83101612F1003B5A3B /* SimpleLog.m */,
 			);
 			name = MPPortProcess;
 			sourceTree = "<group>";
@@ -433,6 +439,14 @@
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
+		218DEE4010162175003B5A3B /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				218DEE3E10162157003B5A3B /* SimpleLog.h in Headers */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		6ED12AD30E3E9AE10026773D /* Headers */ = {
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
@@ -472,6 +486,7 @@
 			isa = PBXNativeTarget;
 			buildConfigurationList = 21D954481009413000DEF58A /* Build configuration list for PBXNativeTarget "MPPortProcess" */;
 			buildPhases = (
+				218DEE4010162175003B5A3B /* Headers */,
 				21D9543B100940EE00DEF58A /* Sources */,
 				21D9543C100940EE00DEF58A /* Frameworks */,
 			);
@@ -685,6 +700,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				21D954471009412F00DEF58A /* MPPortProcess.m in Sources */,
+				218DEE2610162091003B5A3B /* SimpleLog.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: branches/gsoc09-gui/MacPorts_Framework/SimpleLog.h
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/SimpleLog.h	                        (rev 0)
+++ branches/gsoc09-gui/MacPorts_Framework/SimpleLog.h	2009-07-22 01:06:12 UTC (rev 54152)
@@ -0,0 +1,14 @@
+/*
+ *  SimpleLog.h
+ *  MacPorts.Framework
+ *
+ *  Created by Juan Germán Castañeda Echevarría on 7/21/09.
+ *  Copyright 2009 UNAM. All rights reserved.
+ *
+ */
+
+#include <tcl.h>
+
+id delegate;
+
+int Notify_Command(ClientData clientData, Tcl_Interp *interpreter, int objc, Tcl_Obj *CONST objv[]);
\ No newline at end of file

Added: branches/gsoc09-gui/MacPorts_Framework/SimpleLog.m
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/SimpleLog.m	                        (rev 0)
+++ branches/gsoc09-gui/MacPorts_Framework/SimpleLog.m	2009-07-22 01:06:12 UTC (rev 54152)
@@ -0,0 +1,28 @@
+/*
+ *  SimpleLog.m
+ *  MacPorts.Framework
+ *
+ *  Created by Juan Germán Castañeda Echevarría on 7/21/09.
+ *  Copyright 2009 UNAM. All rights reserved.
+ *
+ */
+
+#include "SimpleLog.h"
+
+ at interface NSObject (SimpleLogDelegate) 
+-(void)processDidBeginRunning;
+-(void)processDidEndRunning;
+ at end
+
+int Notify_Command(ClientData clientData, Tcl_Interp *interpreter, int objc, Tcl_Obj *CONST objv[]){
+    int returnCode = TCL_ERROR;
+	
+    //NSLog();
+    
+    if(delegate && [delegate respondsToSelector:@selector(reactToNotification)]) {
+        // send messages to delegate
+        [delegate processDidBeginRunning];
+    }
+    
+	return returnCode;
+}
\ No newline at end of file

Modified: branches/gsoc09-gui/MacPorts_Framework/portProcessInit.tcl
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/portProcessInit.tcl	2009-07-22 00:53:23 UTC (rev 54151)
+++ branches/gsoc09-gui/MacPorts_Framework/portProcessInit.tcl	2009-07-22 01:06:12 UTC (rev 54152)
@@ -1,7 +1,6 @@
 package require macports
-#package require notifications Require My new notifications extension
+package require simplelog #Require My new notifications extension
 
-
 #Set ui_options to log all messages to stdout and notify system
 #filtering is done on the Obj-C side of things
 set ui_options(ports_debug) "yes"
@@ -18,6 +17,121 @@
 	return 0
 }
 
+# UI Callback
+proc ui_prefix {priority} {
+    switch $priority {
+        debug {
+        	return "DEBUG: "
+        }
+        error {
+        	return "Error: "
+        }
+        warn {
+        	return "Warning: "
+        }
+        default {
+        	return ""
+        }
+    }
+}
+
+proc ui_channels {priority} {
+    global logfd
+    switch $priority {
+        debug {
+            if {[ui_isset ports_debug]} {
+            	return {stderr}
+            } else {
+            	return {}
+            }
+        }
+        info {
+            if {[ui_isset ports_verbose]} {
+                return {stdout}
+            } else {
+                return {}
+			}
+		}
+        msg {
+            if {[ui_isset ports_quiet]} {
+                return {}
+			} else {
+				return {stdout}
+			}
+		}
+        error {
+        	return {stderr}
+        }
+        default {
+        	return {stdout}
+        }
+    }
+}
+
+
+
+#Modifying UI initialization to enable notifications
+#Redefine ui_$pritority to throw global notifications
+#This is currently under works ... a reasonable solution
+#should be coming up soon
+proc ui_init {priority prefix channels message} {
+	#puts "INSIDE ui_init priority with prefix $prefix and message $message"
+	
+    # Get the list of channels.
+    try {
+        set channels [ui_channels $priority]
+    } catch * {
+        set channels [ui_channels_default $priority]
+    }
+    
+    #set channels [ui_channels $priority]
+    
+    # Simplify ui_$priority.
+    set nbchans [llength $channels]
+    if {$nbchans == 0} {
+        proc ::ui_$priority {str} [subst {
+        	simplelog "$nottype $chan $prefix" "\$str" 
+        }]
+    } else {
+        try {
+            set prefix [ui_prefix $priority]
+        } catch * {
+            set prefix [ui_prefix_default $priority]
+        }
+        
+        #set prefix [ui_prefix $priority]
+        
+        if {$nbchans == 1} {
+          set chan [lindex $channels 0]
+
+          proc ::ui_$priority {args} [subst {
+            if {\[lindex \$args 0\] == "-nonewline"} {
+              puts $chan "$prefix\[lindex \$args 1\]"
+              simplelog "$nottype $chan $prefix" "\[lindex \$args 1\]"
+            } else {
+              puts -nonewline $chan "$prefix\[lindex \$args 1\]"
+              simplelog "$nottype $chan $prefix" "\[lindex \$args 0\]"
+            }
+          }]
+        } else {
+          proc ::ui_$priority {args} [subst {
+            foreach chan \$channels {
+              if {\[lindex \$args 0\] == "-nonewline"} {
+                puts $chan "$prefix\[lindex \$args 1\]"
+                simplelog "$nottype $chan $prefix" "\[lindex \$args 1\]"
+              } else {
+                puts -nonewline $chan "$prefix\[lindex \$args 1\]"
+                simplelog "$nottype $chan $prefix" "\[lindex \$args 0\]"
+              }
+            }
+          }]
+        }
+
+    # Call ui_$priority - Is this step necessary? Consult with Randall
+    #::ui_$priority $message
+    }
+}
+
 #Wrapping the following API routines to catch errors
 #and log error Information in a similar fashion to code
 #in macports.tcl.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090721/ae393b49/attachment.html>


More information about the macports-changes mailing list