[28251] users/rhwood/Pallet/MPTool

source_changes at macosforge.org source_changes at macosforge.org
Sun Aug 26 02:52:15 PDT 2007


Revision: 28251
          http://trac.macosforge.org/projects/macports/changeset/28251
Author:   rhwood at macports.org
Date:     2007-08-26 02:52:15 -0700 (Sun, 26 Aug 2007)

Log Message:
-----------
Too many changes since last commit to recall. Sorry about that.

Modified Paths:
--------------
    users/rhwood/Pallet/MPTool/MPAgent.h
    users/rhwood/Pallet/MPTool/MPAgent.m
    users/rhwood/Pallet/MPTool/MPAgentProtocol.h
    users/rhwood/Pallet/MPTool/MPInterp.h
    users/rhwood/Pallet/MPTool/MPInterp.m

Modified: users/rhwood/Pallet/MPTool/MPAgent.h
===================================================================
--- users/rhwood/Pallet/MPTool/MPAgent.h	2007-08-26 09:36:05 UTC (rev 28250)
+++ users/rhwood/Pallet/MPTool/MPAgent.h	2007-08-26 09:52:15 UTC (rev 28251)
@@ -1,34 +1,32 @@
-//
-//  MPAgent.h
-//  DarwinPorts
-//
 /*
- Copyright (c) 2003 Apple Computer, Inc.
- All rights reserved.
- 
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
- 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
-    may be used to endorse or promote products derived from this software
-    without specific prior written permission.
- 
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- 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
- 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.
+ * MPAgent.h
+ * DarwinPorts
+ *
+ * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS 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 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.
  */
 
 #include <Foundation/Foundation.h>
@@ -41,11 +39,13 @@
 
     NSConnection 			*_connection;
     
-    NSLock					*_interpLock;
+    NSLock					*_portExecLock;
     
     MPInterp 				*_interp;
     NSMutableDictionary 	*_ports;
     NSDictionary			*_currentOp;
+	
+	NSString				*_applicationMessagePort;
 }
 
 

Modified: users/rhwood/Pallet/MPTool/MPAgent.m
===================================================================
--- users/rhwood/Pallet/MPTool/MPAgent.m	2007-08-26 09:36:05 UTC (rev 28250)
+++ users/rhwood/Pallet/MPTool/MPAgent.m	2007-08-26 09:52:15 UTC (rev 28251)
@@ -1,69 +1,51 @@
-//
-//  MPAgent.h
-//  DarwinPorts
-//
 /*
- Copyright (c) 2003 Apple Computer, Inc.
- All rights reserved.
- 
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
- 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
-    may be used to endorse or promote products derived from this software
-    without specific prior written permission.
- 
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- 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
- 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.
+ * MPAgent.m
+ * DarwinPorts
+ *
+ * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS 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 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.
  */
 
 #import "MPAgent.h"
 #import "MPObject.h"
 
-// package info
-static NSString *MPPackageName = @"darwinports";
-static NSString *MPPackageVersion = @"1.0";
-static NSString *MPPackageInit = @"dportinit";
-
-// commands
-static NSString *MPSearchCommand = @"dportsearch";
-static NSString *MPOpenCommand = @"dportopen";
-static NSString *MPExecCommand = @"dportexec";
-static NSString *MPCloseCommand = @"dportclose";
-
-// arguments
-static NSString *MPAnyPortArgument = @".+";
-
-// results
-static NSString *MPYesResult = @"1";
-static NSString *MPNoResult = @"0";
-
-// ui
-static NSString *MPUIPuts = @"ui_puts";
-static NSString *MPUIConfirm = @"ui_confirm";
-static NSString *MPUIYesNo = @"ui_yesno";
-static NSString *MPUIDisplay = @"ui_display"; 
-
-
 @implementation MPAgent
 /*
-    Serves as a bridge between the GUI app and the tcl interpreter.   Uses distributed objects to communicate with a delegte (GUI front-end).  All values exposed by the APIs to this class are generic objective-c data-types and not TCL MPObjects... clients talking to this class should not know or care that there's a tcl interpreter hiding underneath.   This class should also be the place to encapsulate all knowledge about the internal structure/constants of the ports system so that clients do not need to know about those details.
-    This class is multi-threaded but all port operations are currently serialized (see more comments on this below)\
-    The agent does not cache any information but rather always calls the tcl engine to talk to the ports collection and get the most recent information.   Caching should (and is) performed in the application front-end.    
+    Serves as a bridge between the GUI app and the tcl interpreter.
+    Uses distributed objects to communicate with a delegte (GUI front-end).
+    All values exposed by the APIs to this class are generic objective-c data-types
+    and not TCL MPObjects... clients talking to this class should not know or care that
+    there's a tcl interpreter hiding underneath.   This class should also be the place to
+    encapsulate all knowledge about the internal structure/constants of the ports system
+    so that clients do not need to know about those details.
+    This class is multi-threaded but all port operations are currently serialized
+    (see more comments on this below).
+    The agent does not cache any information but rather always calls the tcl
+    engine to talk to the ports collection and get the most recent information.
+    Caching should (and is) performed in the application front-end.
 */
 
 /** Init and clean-up **/
@@ -75,26 +57,24 @@
     if (self = [super init])
     {
 
-        _interpLock = [[NSLock alloc] init];
+        _portExecLock = [[NSLock alloc] init];
         _ports = [[NSMutableDictionary alloc] init];
-        
-        // configure our tcl interpreter
-        _interp = [[MPInterp alloc] init];
-        [_interp loadPackage: MPPackageName version: MPPackageVersion usingCommand: MPPackageInit];
-        [_interp redirectCommand: [MPObject objectWithString: MPUIPuts] toObject: self];
-        [_interp redirectCommand: [MPObject objectWithString: MPUIConfirm] toObject: self];
-        [_interp redirectCommand: [MPObject objectWithString: MPUIYesNo] toObject: self];
-        [_interp redirectCommand: [MPObject objectWithString: MPUIDisplay] toObject: self];
 
+		// this needs to be passed at launch time from launching application to completely abstract this
+		_applicationMessagePort = MPAppMessagePort;
+		
         // configure our d.o. connection
         _connection = [NSConnection defaultConnection];
         [_connection setRootObject: self];
         [_connection enableMultipleThreads];
-        if ([_connection registerName: @"MPAgent"] == NO) 
+        [_connection setDelegate: self];
+        if ([_connection registerName: MPAgentMessagePort] == NO) 
         {
             NSLog(@"Couldn't register server on this host.");
             exit(0);
-        }
+        } else {
+			NSLog(@"Registered %@ on this host.", MPAgentMessagePort);
+		}
 
         [[NSNotificationCenter defaultCenter] addObserver:self
             selector: @selector(connectionDidDie:)
@@ -110,14 +90,50 @@
 - (void) dealloc
 {
     [_interp release];
-    [_interpLock release];
+    [_portExecLock release];
     [super dealloc];
 }
 
 
+- (BOOL) interpInit: (MPInterp *) interp
+{
+    // load required Tcl packages and set up UI call back
+	NSLog(@"interpInit: enter");
+    if(![interp loadPackage: MPPackageName version: MPPackageVersion usingCommand: MPPackageInit])
+        return (NO);
+	NSLog(@"interpInit: package loaded");
+    if(![interp redirectCommand: MPUIPuts toObject: self])
+        return (NO);
+	NSLog(@"interpInit: UI commands redirected");
+    return (YES);
+}
+
+
 /** D.O. connection management **/
 
+- (BOOL) agentInit
+{
+    // configure our tcl interpreter
+	NSLog(@"agentInit: enter");
+    _interp = [[MPInterp alloc] init];
+	NSLog(@"agentInit: interperter allocated");
+    return ([self interpInit: _interp]);
+}
 
+- (BOOL) connection: (NSConnection *)parentConnection shouldMakeNewConnection:(NSConnection *)newConnection
+{
+    /*
+     * Ensure that connectionDidDie: is called if newConnection
+     * dies without terminate being called
+     */
+    [[NSNotificationCenter defaultCenter] addObserver:self
+	selector: @selector(connectionDidDie:)
+        name: NSConnectionDidDieNotification
+        object: newConnection];
+    return YES;
+}
+
+
 - (void) connectionDidDie: (id)connection
 {
     exit(0);
@@ -145,9 +161,7 @@
     MPObject *result;
     NSString *error;
     NSData *portsData;
-    
-    [_interpLock lock];    
-    
+        
     [_ports removeAllObjects];
     result = [_interp evaluateCommand: [MPObject objectWithString: MPSearchCommand] 
         withObject: [MPObject objectWithString: MPAnyPortArgument]];
@@ -208,7 +222,6 @@
         }
         [_ports setObject: portDict forKey: [portDict objectForKey: MPNameKey]];
     }
-    [_interpLock unlock];    
 
     // we serialize the data before returning it so that we can pass a deep copy of
     // the entire dictionary back in a single D.O. exchange.   if we just pass
@@ -223,16 +236,15 @@
     
 }
 
-
-- (oneway void) executeTarget: (NSString *)target forPortName: (NSString *)portName
+- (oneway void) executeTarget: (in bycopy NSString *)target forPortName: (in bycopy NSString *)portName
 /*
     Detaches a new thread to perform the specified target on the specified port... 
 */
 {
     NSDictionary *op = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
         portName, @"portName",
-        [MPObject objectWithString: target], @"target",
-        [MPObject objectWithString: [[_ports objectForKey: portName] objectForKey: MPPortURLKey]], @"url",
+        target, @"target",
+        [[_ports objectForKey: portName] objectForKey: MPPortURLKey], @"url",
         nil];
     [NSThread detachNewThreadSelector: sel_getUid("_threadForOperation:") 
         toTarget: self 
@@ -243,20 +255,25 @@
 /** Execution thread methods */
 
 /*
-    Everything beyond this point code executes in secondary threads.  I've made a conscious effort to not share any objects (except for the _interpLock) between the primary thread and the secondary threads to minimize the need to worry about thread-safe data sharing between threads.
-    Even though we have a separate thread for each operation all operations are currently serialized using the _interpLock.   If we wish to allow multiple simultaneous operations in the future then each thread will have to instantiate it's own interpreter (and the gui will also have to be made more flexible to sort out messages coming back from multiple simultaneous operations).   
-    If we allow multiple truly simultaneous operations we also need to think about situations such as what happens if you start installing Port A and Port B both of which have a dependency on C?  Does C get installed twice?  Or even worse what if you start installing port A which depends on port C and simultaneously start uninstalling C?  etc.   For now easier to sidestep the whole issue by serializing everything.
+    Everything beyond this point code executes in secondary threads.  I've made a conscious effort to not share any objects (except for the _portExecLock) between the primary thread and the secondary threads to minimize the need to worry about thread-safe data sharing between threads.
+    Even though we have a separate thread for each operation all operations are currently serialized using the _portExecLock.
+    If we allow multiple simultaneous operations we also need to think about situations such as what happens if you start installing Port A and Port B both of which have a dependency on C?  Does C get installed twice?  Or even worse what if you start installing port A which depends on port C and simultaneously start uninstalling C?  etc.   For now easier to sidestep the whole issue by serializing everything.
 */
 
 
 - (void) _threadForOperation: (NSMutableDictionary *)op
 {
 
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    MPInterp *interp = [[MPInterp alloc] init];
 
+    /* Initialize new interpreter */
+    if (![self interpInit: interp])
+        return;
+    
     // establish a separate connection for communication from this thread
-    // back to the PortsManager.app
-    NSConnection *connection = [NSConnection connectionWithRegisteredName: @"PMApp" host: nil];
+    // back to the Pallet.app
+    NSConnection *connection = [NSConnection connectionWithRegisteredName:_applicationMessagePort host: nil];
     id <MPDelegateProtocol> delegate = [connection rootProxy];
     [connection enableMultipleThreads];    
     [(NSDistantObject *)delegate setProtocolForProxy:@protocol(MPDelegateProtocol)];
@@ -264,31 +281,32 @@
         selector: @selector(connectionDidDie:)
         name: NSConnectionDidDieNotification
         object: connection];
+    
     [[[NSThread currentThread] threadDictionary] setObject: delegate forKey: @"delegate"];
     
-    if ([delegate shouldPerformTarget: [[op objectForKey: @"target"] stringValue] forPortName: [op objectForKey: @"portName"]])
+    if ([delegate shouldPerformTarget: [op objectForKey: @"target"] forPortName: [op objectForKey: @"portName"]])
     {
         MPObject *result = nil;
-        [delegate willPerformTarget: [[op objectForKey: @"target"] stringValue] forPortName: [op objectForKey: @"portName"]];
-        [_interpLock lock]; // this can block for a long time if another op is in progress
+        [_portExecLock lock]; // this can block for a long time if another op is in progress
+        [delegate willPerformTarget: [op objectForKey: @"target"] forPortName: [op objectForKey: @"portName"]];
         _currentOp = op;
-        MPObject *workName = [_interp evaluateCommand: [MPObject objectWithString: MPOpenCommand] 
-            withObject: [op objectForKey: @"url"]];
-        if ([_interp succeeded])
+        MPObject *workName = [interp evaluateCommand: [MPObject objectWithString: MPOpenCommand]
+                                          withObject: [MPObject objectWithString: [op objectForKey: @"url"]]];
+        if ([interp succeeded])
         {
-            result = [_interp evaluateCommand: [MPObject objectWithString: MPExecCommand] 
-                withObjects: workName : [op objectForKey: @"target"]];
-            if ([_interp succeeded]) 
+            result = [interp evaluateCommand: [MPObject objectWithString: MPExecCommand]
+                                 withObjects: workName : [MPObject objectWithString: [op objectForKey: @"target"]]];
+            if ([interp succeeded]) 
             {
-                result = [_interp evaluateCommand: [MPObject objectWithString: MPCloseCommand] withObject: workName];            
-            } 
+                result = [interp evaluateCommand: [MPObject objectWithString: MPCloseCommand] withObject: workName];            
+            }
         }
         _currentOp = nil;
-        [_interpLock unlock];
-        [delegate didPerformTarget: [[op objectForKey: @"target"] stringValue] forPortName: [op objectForKey: @"portName"] withResult: [result stringValue]];
+        [_portExecLock unlock];
+        [delegate didPerformTarget: [op objectForKey: @"target"] forPortName: [op objectForKey: @"portName"] withResult: [result stringValue]];
     }
 
-    // Be sure to unregister for NSConnectionDidDieNotification before
+    // Unregister for NSConnectionDidDieNotification before
     // auto-releasing the connection object
     [[NSNotificationCenter defaultCenter] removeObserver:self
         name: NSConnectionDidDieNotification
@@ -296,60 +314,26 @@
 
     [op release];
     [pool release];
-
+    /* Do NOT release interpreter until ALL MPObjects are released */
+    [interp release];
 }
 
 
 - (MPObject *) ui_puts: (NSArray *)array 
 {
-    NSString *priority= [[array objectAtIndex: 1] stringValue];
-    NSString *message = [[array objectAtIndex: 2] stringValue];
-    BOOL noNewLine = (([array count] > 3) && [[array objectAtIndex:3] containsString: @"-nonewline"]);    
-    id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
-    [delegate displayMessage: [NSString stringWithFormat: @"%@%@", message, (noNewLine ? @"" : @"\n")]
-        withPriority: priority
-        forPortName: [_currentOp objectForKey: @"portName"]];        
-    return [MPObject objectWithString: MPYesResult];
-}
+    NSDictionary *message = [[array objectAtIndex: 1] dictionaryValue];
+    if (message == nil)
+    	return [MPObject objectWithString: MPNoResult];
 
+    NSString *data = [message objectForKey: @"data"];
+    NSString *priority = [message objectForKey: @"priority"];
+    if (data == nil || priority == nil)
+    	return [MPObject objectWithString: MPNoResult];
 
-- (MPObject *) ui_display:(NSArray *) array
-{
-    NSString *filename = [[array objectAtIndex:1] stringValue];
-    NSString *contents = [NSString stringWithContentsOfFile: filename];
-    if (nil != contents) {
-        id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
-        [delegate displayMessage: contents 
-                    withPriority: @"msg"
-                     forPortName: [_currentOp objectForKey: @"portName"]];
-        return [MPObject objectWithString: MPYesResult];
-    }
-    NSLog(@"%@ failed %@: %@", @"ui_display", @"stringWithContentsOfFile", filename);
-    return [MPObject objectWithString: MPNoResult];
-}
-
-
-- (MPObject *) ui_confirm: (NSArray *) array 
-{
-    NSString *message = [[array objectAtIndex: 1] stringValue];
     id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
-    BOOL result = [delegate askMessage: message
-                         needsResponse: YES
-                           forPortName: [_currentOp objectForKey: @"portName"]];
-    return [MPObject objectWithString: (result) ? MPYesResult : MPNoResult];
+    [delegate displayMessage: message forPortName: [_currentOp objectForKey: @"portName"]];
+    return [MPObject objectWithString: MPYesResult];
 }
 
 
-- (MPObject *) ui_yesno:(NSArray *) array 
-{
-    NSString *message = [[array objectAtIndex: 1] stringValue];
-    id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
-    BOOL result = [delegate askMessage: message
-                         needsResponse: NO
-                           forPortName: [_currentOp objectForKey: @"portName"]];
-    return [MPObject objectWithString: (result) ? MPYesResult : MPNoResult];
-}
-
-
-
 @end

Modified: users/rhwood/Pallet/MPTool/MPAgentProtocol.h
===================================================================
--- users/rhwood/Pallet/MPTool/MPAgentProtocol.h	2007-08-26 09:36:05 UTC (rev 28250)
+++ users/rhwood/Pallet/MPTool/MPAgentProtocol.h	2007-08-26 09:52:15 UTC (rev 28251)
@@ -31,6 +31,10 @@
  POSSIBILITY OF SUCH DAMAGE.
  */
 
+// mach port names */
+#define MPAgentMessagePort @"org.macports.Pallet.Agent"
+#define MPAppMessagePort @"org.macports.Pallet.Application"
+
 // port keys 
 #define MPNameKey				@"name"
 #define MPVersionKey			@"version"

Modified: users/rhwood/Pallet/MPTool/MPInterp.h
===================================================================
--- users/rhwood/Pallet/MPTool/MPInterp.h	2007-08-26 09:36:05 UTC (rev 28250)
+++ users/rhwood/Pallet/MPTool/MPInterp.h	2007-08-26 09:52:15 UTC (rev 28251)
@@ -1,39 +1,59 @@
-//
-//  MPInterp.h
-//  DarwinPorts
-//
 /*
- Copyright (c) 2003 Apple Computer, Inc.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- 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
- 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.
+ * MPInterp.h
+ * DarwinPorts
+ *
+ * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS 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 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.
  */
 
 #import <Foundation/Foundation.h>
 #include <tcl.h>
 
+// package info
+static NSString *MPPackageName = @"macports";
+static NSString *MPPackageVersion = @"1.0";
+static NSString *MPPackageInit = @"mportinit";
+
+// commands
+static NSString *MPSearchCommand = @"mportsearch";
+static NSString *MPOpenCommand = @"mportopen";
+static NSString *MPExecCommand = @"mportexec";
+static NSString *MPCloseCommand = @"mportclose";
+
+// arguments
+static NSString *MPAnyPortArgument = @".+";
+
+// results
+static NSString *MPYesResult = @"1";
+static NSString *MPNoResult = @"0";
+static NSString *MPNullResult = @"";
+
+// ui
+static NSString *MPUIPuts = @"ui_puts";
+
 @class MPObject;
 
 @interface MPInterp : NSObject 
@@ -45,7 +65,6 @@
 
 - (id) init;
 - (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit;
-- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion;
 
 - (MPObject *) setVariable: (MPObject *)variable toValue: (MPObject *)value;
 - (MPObject *) getVariable: (MPObject *)variable;
@@ -53,11 +72,10 @@
 - (MPObject *) evaluateCommand: (MPObject *)command;
 - (MPObject *) evaluateCommand: (MPObject *)command withObject: (MPObject *)arg;
 - (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1 :(MPObject *)arg2;
-- (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1: (MPObject *)arg2: (MPObject *)arg3;
 - (MPObject *) evaluate: (NSArray *)args;
 
 - (BOOL) succeeded;
 
-- (BOOL) redirectCommand: (MPObject *) command toObject: (id)handler;
+- (BOOL) redirectCommand: (NSString *) command toObject: (id)handler;
 
 @end

Modified: users/rhwood/Pallet/MPTool/MPInterp.m
===================================================================
--- users/rhwood/Pallet/MPTool/MPInterp.m	2007-08-26 09:36:05 UTC (rev 28250)
+++ users/rhwood/Pallet/MPTool/MPInterp.m	2007-08-26 09:52:15 UTC (rev 28251)
@@ -1,34 +1,32 @@
-//
-//  MPInterp.m
-//  DarwinPorts
-//
 /*
- Copyright (c) 2003 Apple Computer, Inc.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- 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
- 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.
+ * MPInterp.m
+ * DarwinPorts
+ *
+ * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS 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 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.
  */
 
 #import "MPInterp.h"
@@ -41,20 +39,20 @@
 
 @implementation MPInterp
 /*
-    A thin objective-c wrapper for the tcl interperter - the intent is that this should be a generic TCL interpreter and should not have any specific knowledge of the ports system.
+    A thin objective-c wrapper for the tcl interpreter - the intent is that this should be a generic TCL interpreter and should not have any specific knowledge of the ports system.
 */
 
 
 /** Redirect Handler */
 
-SEL makeSelector(NSString *name) {
+static SEL makeSelector(NSString *name) {
     NSString *methodName = [name stringByAppendingString:@":"];
     return sel_getUid([methodName cString]);
 }
 
 
 //Tcl_CreateObjCommand(_interp, [command cString], MPCommandHandler, handler, NULL);
-int MPCommandHandler(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[]) 
+static int MPCommandHandler(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[]) 
 {
     id handler = (id) clientData;
     NSMutableArray *array = [NSMutableArray array];
@@ -83,7 +81,6 @@
     {
         _interp = Tcl_CreateInterp();
         Tcl_Init(_interp);
-		
     }
     return self;
 }
@@ -92,44 +89,28 @@
 - (void) dealloc 
 {
     Tcl_DeleteInterp(_interp);
-    [super release];
+    [super dealloc];
 }
 
-- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit
-{
-	[self loadPackage:packageName version:packageVersion];
-	
-	if (TCL_OK == _status) {
-		[self evaluateCommand: [MPObject objectWithString: packageInit]];
-	}
-	
-    return (TCL_OK == _status);
-}
 
-- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit withArguments:(NSArray *)args
+- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit 
 {
-	[self loadPackage:packageName version:packageVersion];
-		
-	if (TCL_OK == _status) {
-		[self evaluateCommand: [MPObject objectWithString: packageInit]];
-	}
-
-    return (TCL_OK == _status);
-}
-
-- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion
-{
     char *name = (nil != packageName) ? strdup([packageName cString]) : NULL;
     char *version = (nil != packageVersion) ? strdup([packageVersion cString]) : NULL;
-	
-    Tcl_PkgRequire(_interp, name, version, 0);
-	
+
+    if (!Tcl_PkgRequire(_interp, name, version, 0))
+        return NO;
+    
+    if (![self evaluateCommand: [MPObject objectWithString: packageInit]])
+        return NO;
+
     if (name) free(name);
     if (version) free(version);
-	
+
     return (TCL_OK == _status);
 }
 
+
 /** Variables */
 
 - (MPObject *) setVariable:(MPObject*) variable toValue:(MPObject*) value 
@@ -161,17 +142,12 @@
     return [self evaluateCommand:command withObjects:arg :nil];
 }
 
-- (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1: (MPObject *)arg2
+- (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1 : (MPObject *)arg2 
 {
     NSArray *array = [NSArray arrayWithObjects:command,arg1,arg2,nil];
     return [self evaluate:array];
 }
 
-- (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1: (MPObject *)arg2: (MPObject *)arg3
-{
-    NSArray *array = [NSArray arrayWithObjects:command,arg1,arg2,arg3,nil];
-    return [self evaluate:array];
-}
 
 - (MPObject *) evaluate: (NSArray*)args 
 {
@@ -194,6 +170,10 @@
     {
         NSLog(@"failed: %@\n args:\t%@", result, args);
     }
+    else
+    {
+        NSLog(@"succeeded args:\t%@", args);
+    }
     free(objv);
     return result;
 }
@@ -207,9 +187,9 @@
 /** Notifications */
 
 
-- (BOOL) redirectCommand: (MPObject *)command toObject: (id)handler
+- (BOOL) redirectCommand: (NSString *) command toObject: (id)handler
 {
-    SEL selector = makeSelector([command stringValue]);
+    SEL selector = makeSelector(command);
     if (NULL == selector || ![handler respondsToSelector:selector])
         return NO;
     

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070826/4737366b/attachment.html


More information about the macports-changes mailing list