[39197] branches/gsoc08-framework/MacPorts_Framework_Release

armahg at macports.org armahg at macports.org
Tue Aug 12 06:12:02 PDT 2008


Revision: 39197
          http://trac.macosforge.org/projects/macports/changeset/39197
Author:   armahg at macports.org
Date:     2008-08-12 06:12:02 -0700 (Tue, 12 Aug 2008)
Log Message:
-----------
Cleaned up code for MPInterpreter.m and MPInterpreter.h classes. Removed unused methods and some comments. Removed AuthorizationRef warning in MPMacPorts.m

Modified Paths:
--------------
    branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h
    branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h	2008-08-12 12:36:34 UTC (rev 39196)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h	2008-08-12 13:12:02 UTC (rev 39197)
@@ -26,8 +26,8 @@
  *	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  *	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  *	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-						   *	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-						   *	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ *	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  *	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  *	POSSIBILITY OF SUCH DAMAGE.
@@ -36,19 +36,18 @@
 /*!
  @header
  The MPInterpreter class allows access to a shared per-thread Tcl interpreter for
- execution of MacPorts commands from upper levels in the API.
+ execution of MacPorts commands from upper levels in the API. This class is intended
+ for internal use. Framework users should not have to interact with it directly in
+ order to perform port operations.
  */
 
 #import <Cocoa/Cocoa.h>
 #import <Security/Security.h>
 #include <tcl.h>  
 #import "MPNotifications.h"
-#import "MPInterpreterProtocol.h"
 
 
 //Defining some flags for MPHelperTool
-#define SELF_REPAIR @"--self-repair"
-#define REC_COUNT @"--rec-count"
 #define MP_HELPER @"MPHelperTool"
 
 #define	MPPackage				@"macports"
@@ -67,11 +66,8 @@
 
 
 
-/////////////////////////////////////////////////////////////////
-#pragma mark ***** Globals
 
 
-
 /*!
  @class MPInterpreter
  @abstract Tcl interpreter object
@@ -79,8 +75,8 @@
  is where the Objective-C API meets the Tcl command line. It is a per-thread interpreter to allow
  users of the API to multi-thread their programs with relative ease.
  */
- at interface MPInterpreter : NSObject <MPInterpreterProtocol> {
-
+ at interface MPInterpreter : NSObject  {
+	
 	Tcl_Interp* _interpreter;
 	NSString * helperToolInterpCommand;
 	NSString * helperToolCommandResult;
@@ -94,68 +90,35 @@
  */
 + (MPInterpreter *)sharedInterpreter;
 
-- (Tcl_Interp *) sharedTclInterpreter;
-- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray*)args;
 
+/*!
+ @brief Return singleton shared MPInterpreter instance for specified macports tcl package path
+ @param path An NSString specifying the absolute path for the macports tcl package
+ */
 + (MPInterpreter *)sharedInterpreterWithPkgPath:(NSString *)path;
-- (id) initWithPkgPath:(NSString *)path;
 
 
+
 #pragma Port Operations
 
 #pragma Port Settings
 
 #pragma Utilities
 
+
 /*!
- @brief Returns the NSstring result of evaluating a Tcl expression
- @param  statement An NSArray containing the Tcl expression
- @discussion For example, here is the header definition of a MacPorts Tcl API
- call proc macports::getindex {source}. This is how to call this procedure
- in Tcl: [macports::getindex $source]. Calling the macports::getindex
- procedure from Objective-C code with -evaluateArrayAsString however takes the following form:
- 
- [SomeMPInterpreterObject evaluateArrayAsString:[NSArray arrayWithObjects:
-	@"return [macports::getindex",
-	[NSString stringWithString:@"SomeValidMacPortsSourcePath"],
-	@"]",
-	nil]];
- 
- Each element in the array is an NSString. Note the "return" in the first element of the statement
- NSArray.
- */
-//- (NSString *)evaluateArrayAsString:(NSArray *)statement;
-/*!
  @brief Returns the NSString result of evaluating a Tcl expression
  @param  statement An NSString containing the Tcl expression
- @discussion Using the macports::getindex {source} procedure as an example (see discussion for 
- -evaluateArrayAsString), we have the following Objective-C form for calling the macports::getindex
- procedure:
+ @param	 mportError A reference pointer to the NSError object which will be used for error handling.
+ @discussion Using the macports::getindex {source} procedure as an example we 
+ have the following Objective-C form for calling the macports::getindex procedure:
  
  [SomeMPInterpreterObject evaluateStringAsString:
-							[NSString stringWithString:@"return [macports::getindex SomeValidMacPortsSourcePath]"]];
+ [NSString stringWithString:@"return [macports::getindex SomeValidMacPortsSourcePath]"]];
  */
 - (NSString *)evaluateStringAsString:(NSString *)statement error:(NSError **)mportError;
 
 
-//Redoing evaluateStringAsString and evaluateArrayAsString to return a two element NSDictionary.
-//First element will have key TCL_RETURN_CODE and be an NSNumber with int value of TCL_OK,
-//TCL_RETURN , TCL_ERROR etc. The second key will be TCL_RETURN_STRING and have the same NSString
-//value as is being currently returned. This is going to require a lot of refactoring and changing
-//stuff so i'm only going to document and remove old code after new code is working and i've done
-//a commit. Obtaining the return code will make error handling in the framework much less
-//cumbersome
-//- (NSDictionary *)evaluateArrayAsString:(NSArray *)statement;
-//- (NSDictionary *)evaluateStringAsString:(NSString *)statement;
-
-
-//After eliminating evaluateArrayAsString ... I'm wondering if I should take jberry's advice
-//hmm ... well this method needs to return two pieces of information ... the string
-//and an indicator of success .. oh wait ... I can jut check the returned error variable
-//for a successful method ... back to Randall's implementation with some tweaks then ... 
-
-
-
 /*!
  @brief Returns an NSArray whose elements are the the elements of a Tcl list in the form of an NSString
  @param list A Tcl list in the form of an NSString
@@ -189,11 +152,13 @@
  */
 - (NSString *)getVariableAsString:(NSString *)variable;
 
-// METHODS FOR INTERNAL USE ONLY
--(void)setAuthorizationRef:(AuthorizationRef)authRef;
--(BOOL)checkIfAuthorized;
 
-//For testing helper tools
+// METHODS FOR INTERNAL USE ONLY
+- (id) initWithPkgPath:(NSString *)path;
+- (Tcl_Interp *) sharedInternalTclInterpreter;
+- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray*)args;
+- (void)setAuthorizationRef:(AuthorizationRef)authRef;
+- (BOOL)checkIfAuthorized;
 -(NSString *)evaluateStringWithMPHelperTool:(NSString *)statement;
--(NSString *)evaluateStringWithSimpleMPDOPHelperTool:(NSString *)statement;
+
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-08-12 12:36:34 UTC (rev 39196)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-08-12 13:12:02 UTC (rev 39197)
@@ -164,82 +164,7 @@
 }
 
 #pragma mark -
-#pragma mark Authorization Code
 
-- (BOOL)checkIfAuthorized {
-	if  (internalMacPortsAuthRef == NULL ) {
-		return NO;
-	}
-	return YES;
-}
-
--(void)setAuthorizationRef:(AuthorizationRef)authRef {
-	//I can do this since Framework client responsible
-	//for managing memory for Authorization
-	internalMacPortsAuthRef = authRef;
-}
-
-
-
-
-#pragma mark -
-
-#pragma mark MPInterpreterProtocol
-
-- (BOOL) vendSelfForServer {
-	NSConnection * defaultConn;
-	defaultConn = [NSConnection defaultConnection];
-	//NSLog(@"Creating connection ...");
-	
-	[defaultConn setRootObject:self];
-	
-	//NSLog(@"Connection Created ... "); //%@, %@", defaultConn, [defaultConn statistics]);
-	return [defaultConn registerName:MP_DOSERVER];
-	
-}
-
-- (bycopy NSString *) evaluateStringFromMPHelperTool:(in bycopy NSString *)statement {
-	//- (NSString *) evaluateStringFromMPHelperTool:(NSString *)statement {	
-	//TO DO ->  error:(inout NSError **)evalError {
-	//NSError * evalError;
-	NSString * result = [self evaluateStringAsString:statement error:nil];
-	
-	//TO DO : WORK ON ERROR STUFF AFTER GETTING BASIC FUNCTIONALITY WORKING
-	//For now ... Perhaps I might now have to take jberry's advice on ... Oh wait
-	//I should be able to pass by reference duh!
-	//return @"returning from evaluateStringFromMPHelperTool";
-	return result;
-}
-
-
-- (void) setTclCommand:(in bycopy NSString *)tclCmd {
-	if (![helperToolInterpCommand isEqualToString:tclCmd]) {
-		
-		[helperToolInterpCommand release];
-		helperToolInterpCommand = [tclCmd copy];
-	}
-	
-}
-- (bycopy NSString *)getTclCommand {
-	return helperToolInterpCommand;
-}
-
-- (void) setTclCommandResult:(in bycopy NSString *)tclCmdResult {
-	if (![helperToolCommandResult isEqualToString:tclCmdResult]) {
-		[helperToolCommandResult release];
-		helperToolCommandResult = [tclCmdResult copy];
-	}
-}
-- (bycopy NSString *) getTclCommandResult {
-	return helperToolCommandResult;
-}
-
-- (void) log :(in bycopy id) logOutput {
-	NSLog(@"MPInterpreterProtocol Logging : %@", logOutput);
-}
-
-#pragma mark -
-
 #pragma mark MPInterpreter Code
 
 //This variable is set during initialization and is
@@ -279,12 +204,7 @@
 			NSLog(@"Error in Tcl_PkgProvide: %s", Tcl_GetStringResult(_interpreter));
 			Tcl_DeleteInterp(_interpreter);
 		}
-		
-		/*if( Tcl_EvalFile(_interpreter, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"] pathForResource:@"init" ofType:@"tcl"] UTF8String]) != TCL_OK) {
-		 NSLog(@"Error in Tcl_EvalFile init.tcl: %s", Tcl_GetStringResult(_interpreter));
-		 Tcl_DeleteInterp(_interpreter);
-		 }*/
-		
+				
 		if( Tcl_EvalFile(_interpreter, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"] 
 										 pathForResource:@"init" 
 										 ofType:@"tcl"] UTF8String]) != TCL_OK) {
@@ -298,32 +218,12 @@
 		
 		//Initialize the MacPorts Tcl Package Path string
 		tclInterpreterPkgPath = [NSString stringWithString:path];
-		
-		//Initialize the Run Loop because we don't know if framework will be
-		//run in a Foundation Kit or App Kit. Hopefully this won't hurt if the
-		//run loop is already running. We are doing this so that our NSConnection
-		//object is able to handle Distributed Object messages
-		//NOTE: Since MPinterpreter instances are created per thread, we don't have to
-		//worry (I hope) about running loops for different threads
-		//[[NSRunLoop currentRunLoop] run];
-		
-		//if (![self vendSelfForServer]) {
-//			NSLog(@"Failed To initialize NSConnection server ");
-//			//Should probably do some more error handling over here
-//		}
-//		else
-//			NSLog(@"MPInterpreter Initialized ...");
-		
-		
+				
 	}
 	return self;
 }
 
-- (Tcl_Interp *) sharedTclInterpreter {
-	return _interpreter;
-}
 
-
 + (MPInterpreter*)sharedInterpreter {
 	
 	return [self sharedInterpreterWithPkgPath:MP_DEFAULT_PKG_PATH];
@@ -374,23 +274,6 @@
 #pragma Port Settings
 
 #pragma Utilities
-
-- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray *)args {
-	NSTask * task = [[NSTask alloc] init];
-	[task setLaunchPath:pathToExecutable];
-	[task setArguments:args];
-	[task launch];
-	[task waitUntilExit];
-	int status = [task terminationStatus];
-	[task release];
-	return status;
-}
-
-/*- (NSDictionary *)evaluateArrayAsString:(NSArray *)statement {
- return [self evaluateStringAsString:[statement componentsJoinedByString:@" "]];
- }
- 
- */
 - (NSString *)evaluateStringAsString:(NSString *)statement error:(NSError**)mportError{
 	//NSLog(@"Calling evaluateStringAsString with argument %@", statement);
 	
@@ -433,15 +316,6 @@
 }
 
 
-/*
- - (NSDictionary *)evaluateStringAsString:(NSString *)statement {
- int return_code = Tcl_Eval(_interpreter, [statement UTF8String]);
- return [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:return_code], TCL_RETURN_CODE, 
- [NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)], TCL_RETURN_STRING, nil];
- }
- */
-
 - (NSArray *)arrayFromTclListAsString:(NSString *)list {
 	NSMutableArray *array;
 	int tclCount;
@@ -486,7 +360,25 @@
 }
 
 #pragma mark -
-#pragma mark Helper Tool(s) Code
+#pragma mark Authorization Code
+
+- (BOOL)checkIfAuthorized {
+	if  (internalMacPortsAuthRef == NULL ) {
+		return NO;
+	}
+	return YES;
+}
+
+-(void)setAuthorizationRef:(AuthorizationRef)authRef {
+	//I can do this since Framework client responsible
+	//for managing memory for Authorization
+	internalMacPortsAuthRef = authRef;
+}
+
+
+
+#pragma mark -
+#pragma mark For Internal Use
 //NOTE: We expect the Framework client to initialize the AuthorizationRef
 //Completely before calling any privileged operation. Perhaps we
 //should check for this and send an NSError ... rather than go
@@ -583,51 +475,23 @@
 	NSLog(@"AFTER Tool Execution request is %@ , response is %@ \n\n", request, response);
 	//NSLog(@"response dictionary is %@", response);
 	return (NSString *) newresult;
-	
-	
-	/*
-	 NSString * fakeResult = @"Frustrated";
-	 return fakeResult;
-	 
-	 //Read from file and see if it was written to
-	 NSString * testFilePath = [[NSBundle bundleForClass:[self class]]
-	 pathForResource:@"TestFile" ofType:@"test"];
-	 NSError * readError = nil;
-	 NSString * result = [NSString stringWithContentsOfFile:testFilePath 
-	 encoding:NSUTF8StringEncoding
-	 error:&readError];
-	 if (readError) {
-	 NSLog(@"Error is %@", [readError description]);
-	 return @"There was an error Reading";
-	 }
-	 else if ([result isEqualToString:@""]) {
-	 return @"An empty string was read";
-	 }
-	 else if (result == nil) {
-	 return @"Resulting String is NIL";
-	 }
-	 else
-	 return result;
-	 
-	 return @"This shouldn't happen";
-	 */
+
 }
 
-
--(NSString *) evaluateStringWithSimpleMPDOPHelperTool:(NSString *)statement  {
+- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray *)args {
 	NSTask * task = [[NSTask alloc] init];
-	[task setLaunchPath:[[NSBundle bundleForClass:[MPInterpreter class]] 
-						 pathForResource:@"SimpleDOMPHelperTool" 
-						 ofType:nil]];
-	[task setArguments:[NSArray arrayWithObjects:statement, nil]];
+	[task setLaunchPath:pathToExecutable];
+	[task setArguments:args];
 	[task launch];
-	
 	[task waitUntilExit];
-	
-	[task terminationStatus];
-	
-	return [self getTclCommandResult];
+	int status = [task terminationStatus];
+	[task release];
+	return status;
 }
 
 
+- (Tcl_Interp *) sharedInternalTclInterpreter {
+	return _interpreter;
+}
+
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m	2008-08-12 12:36:34 UTC (rev 39196)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPMacPorts.m	2008-08-12 13:12:02 UTC (rev 39197)
@@ -116,7 +116,7 @@
 	//result = [interpreter evaluateStringWithMPHelperTool:@"mportsync"];
 	//[interpreter evaluateStringWithSimpleMPDOPHelperTool:@"mportsync"];
 	
-	result = [interpreter getTclCommandResult];
+	//result = [interpreter getTclCommandResult];
 	
 	[[MPNotifications sharedListener] setPerformingTclCommand:@""];
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPortsSyncFinished" object:nil];
@@ -264,8 +264,9 @@
 //Internal Method for setting our Authorization Reference
 - (void) setAuthorizationRef { 
 	if ([[self delegate] respondsToSelector:@selector(getAuthorizationRef)]) {
-		[interpreter setAuthorizationRef:
-		 [[self delegate] performSelector:@selector(getAuthorizationRef)]];
+		
+		AuthorizationRef clientRef = (AuthorizationRef) [[self delegate] performSelector:@selector(getAuthorizationRef)];
+		[interpreter setAuthorizationRef:clientRef];
 	}
 	//else { //I think i'll iniitalizeAuthorization lazily .. i.e. right
 	//before using helper tool
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080812/cc3806e9/attachment.html 


More information about the macports-changes mailing list