Changeset 28251


Ignore:
Timestamp:
Aug 26, 2007, 9:52:15 AM (13 years ago)
Author:
rhwood@…
Message:

Too many changes since last commit to recall. Sorry about that.

Location:
users/rhwood/Pallet/MPTool
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • users/rhwood/Pallet/MPTool/MPAgent.h

    r25083 r28251  
    1 //
    2 //  MPAgent.h
    3 //  DarwinPorts
    4 //
    51/*
    6  Copyright (c) 2003 Apple Computer, Inc.
    7  All rights reserved.
    8  
    9  Redistribution and use in source and binary forms, with or without
    10  modification, are permitted provided that the following conditions
    11  are met:
    12  1. Redistributions of source code must retain the above copyright
    13     notice, this list of conditions and the following disclaimer.
    14  2. Redistributions in binary form must reproduce the above copyright
    15     notice, this list of conditions and the following disclaimer in the
    16     documentation and/or other materials provided with the distribution.
    17  3. Neither the name of Apple Computer, Inc. nor the names of its contributors
    18     may be used to endorse or promote products derived from this software
    19     without specific prior written permission.
    20  
    21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    31  POSSIBILITY OF SUCH DAMAGE.
     2 * MPAgent.h
     3 * DarwinPorts
     4 *
     5 * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     17 *    its contributors may be used to endorse or promote products derived
     18 *    from this software without specific prior written permission.
     19 *
     20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3230 */
    3331
     
    4240    NSConnection                        *_connection;
    4341   
    44     NSLock                                      *_interpLock;
     42    NSLock                                      *_portExecLock;
    4543   
    4644    MPInterp                            *_interp;
    4745    NSMutableDictionary         *_ports;
    4846    NSDictionary                        *_currentOp;
     47       
     48        NSString                                *_applicationMessagePort;
    4949}
    5050
  • users/rhwood/Pallet/MPTool/MPAgent.m

    r23417 r28251  
    1 //
    2 //  MPAgent.h
    3 //  DarwinPorts
    4 //
    5 /*
    6  Copyright (c) 2003 Apple Computer, Inc.
    7  All rights reserved.
    8  
    9  Redistribution and use in source and binary forms, with or without
    10  modification, are permitted provided that the following conditions
    11  are met:
    12  1. Redistributions of source code must retain the above copyright
    13     notice, this list of conditions and the following disclaimer.
    14  2. Redistributions in binary form must reproduce the above copyright
    15     notice, this list of conditions and the following disclaimer in the
    16     documentation and/or other materials provided with the distribution.
    17  3. Neither the name of Apple Computer, Inc. nor the names of its contributors
    18     may be used to endorse or promote products derived from this software
    19     without specific prior written permission.
    20  
    21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    31  POSSIBILITY OF SUCH DAMAGE.
     1/*
     2 * MPAgent.m
     3 * DarwinPorts
     4 *
     5 * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     17 *    its contributors may be used to endorse or promote products derived
     18 *    from this software without specific prior written permission.
     19 *
     20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3230 */
    3331
     
    3533#import "MPObject.h"
    3634
    37 // package info
    38 static NSString *MPPackageName = @"darwinports";
    39 static NSString *MPPackageVersion = @"1.0";
    40 static NSString *MPPackageInit = @"dportinit";
    41 
    42 // commands
    43 static NSString *MPSearchCommand = @"dportsearch";
    44 static NSString *MPOpenCommand = @"dportopen";
    45 static NSString *MPExecCommand = @"dportexec";
    46 static NSString *MPCloseCommand = @"dportclose";
    47 
    48 // arguments
    49 static NSString *MPAnyPortArgument = @".+";
    50 
    51 // results
    52 static NSString *MPYesResult = @"1";
    53 static NSString *MPNoResult = @"0";
    54 
    55 // ui
    56 static NSString *MPUIPuts = @"ui_puts";
    57 static NSString *MPUIConfirm = @"ui_confirm";
    58 static NSString *MPUIYesNo = @"ui_yesno";
    59 static NSString *MPUIDisplay = @"ui_display";
    60 
    61 
    6235@implementation MPAgent
    6336/*
    64     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.
    65     This class is multi-threaded but all port operations are currently serialized (see more comments on this below)\
    66     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.   
     37    Serves as a bridge between the GUI app and the tcl interpreter.
     38    Uses distributed objects to communicate with a delegte (GUI front-end).
     39    All values exposed by the APIs to this class are generic objective-c data-types
     40    and not TCL MPObjects... clients talking to this class should not know or care that
     41    there's a tcl interpreter hiding underneath.   This class should also be the place to
     42    encapsulate all knowledge about the internal structure/constants of the ports system
     43    so that clients do not need to know about those details.
     44    This class is multi-threaded but all port operations are currently serialized
     45    (see more comments on this below).
     46    The agent does not cache any information but rather always calls the tcl
     47    engine to talk to the ports collection and get the most recent information.
     48    Caching should (and is) performed in the application front-end.
    6749*/
    6850
     
    7658    {
    7759
    78         _interpLock = [[NSLock alloc] init];
     60        _portExecLock = [[NSLock alloc] init];
    7961        _ports = [[NSMutableDictionary alloc] init];
    80        
    81         // configure our tcl interpreter
    82         _interp = [[MPInterp alloc] init];
    83         [_interp loadPackage: MPPackageName version: MPPackageVersion usingCommand: MPPackageInit];
    84         [_interp redirectCommand: [MPObject objectWithString: MPUIPuts] toObject: self];
    85         [_interp redirectCommand: [MPObject objectWithString: MPUIConfirm] toObject: self];
    86         [_interp redirectCommand: [MPObject objectWithString: MPUIYesNo] toObject: self];
    87         [_interp redirectCommand: [MPObject objectWithString: MPUIDisplay] toObject: self];
    88 
     62
     63                // this needs to be passed at launch time from launching application to completely abstract this
     64                _applicationMessagePort = MPAppMessagePort;
     65               
    8966        // configure our d.o. connection
    9067        _connection = [NSConnection defaultConnection];
    9168        [_connection setRootObject: self];
    9269        [_connection enableMultipleThreads];
    93         if ([_connection registerName: @"MPAgent"] == NO)
     70        [_connection setDelegate: self];
     71        if ([_connection registerName: MPAgentMessagePort] == NO)
    9472        {
    9573            NSLog(@"Couldn't register server on this host.");
    9674            exit(0);
    97         }
     75        } else {
     76                        NSLog(@"Registered %@ on this host.", MPAgentMessagePort);
     77                }
    9878
    9979        [[NSNotificationCenter defaultCenter] addObserver:self
     
    11191{
    11292    [_interp release];
    113     [_interpLock release];
     93    [_portExecLock release];
    11494    [super dealloc];
    11595}
    11696
    11797
     98- (BOOL) interpInit: (MPInterp *) interp
     99{
     100    // load required Tcl packages and set up UI call back
     101        NSLog(@"interpInit: enter");
     102    if(![interp loadPackage: MPPackageName version: MPPackageVersion usingCommand: MPPackageInit])
     103        return (NO);
     104        NSLog(@"interpInit: package loaded");
     105    if(![interp redirectCommand: MPUIPuts toObject: self])
     106        return (NO);
     107        NSLog(@"interpInit: UI commands redirected");
     108    return (YES);
     109}
     110
     111
    118112/** D.O. connection management **/
     113
     114- (BOOL) agentInit
     115{
     116    // configure our tcl interpreter
     117        NSLog(@"agentInit: enter");
     118    _interp = [[MPInterp alloc] init];
     119        NSLog(@"agentInit: interperter allocated");
     120    return ([self interpInit: _interp]);
     121}
     122
     123- (BOOL) connection: (NSConnection *)parentConnection shouldMakeNewConnection:(NSConnection *)newConnection
     124{
     125    /*
     126     * Ensure that connectionDidDie: is called if newConnection
     127     * dies without terminate being called
     128     */
     129    [[NSNotificationCenter defaultCenter] addObserver:self
     130        selector: @selector(connectionDidDie:)
     131        name: NSConnectionDidDieNotification
     132        object: newConnection];
     133    return YES;
     134}
    119135
    120136
     
    146162    NSString *error;
    147163    NSData *portsData;
    148    
    149     [_interpLock lock];   
    150    
     164       
    151165    [_ports removeAllObjects];
    152166    result = [_interp evaluateCommand: [MPObject objectWithString: MPSearchCommand]
     
    209223        [_ports setObject: portDict forKey: [portDict objectForKey: MPNameKey]];
    210224    }
    211     [_interpLock unlock];   
    212225
    213226    // we serialize the data before returning it so that we can pass a deep copy of
     
    224237}
    225238
    226 
    227 - (oneway void) executeTarget: (NSString *)target forPortName: (NSString *)portName
     239- (oneway void) executeTarget: (in bycopy NSString *)target forPortName: (in bycopy NSString *)portName
    228240/*
    229241    Detaches a new thread to perform the specified target on the specified port...
     
    232244    NSDictionary *op = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    233245        portName, @"portName",
    234         [MPObject objectWithString: target], @"target",
    235         [MPObject objectWithString: [[_ports objectForKey: portName] objectForKey: MPPortURLKey]], @"url",
     246        target, @"target",
     247        [[_ports objectForKey: portName] objectForKey: MPPortURLKey], @"url",
    236248        nil];
    237249    [NSThread detachNewThreadSelector: sel_getUid("_threadForOperation:")
     
    244256
    245257/*
    246     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.
    247     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).   
    248     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.
     258    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.
     259    Even though we have a separate thread for each operation all operations are currently serialized using the _portExecLock.
     260    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.
    249261*/
    250262
     
    253265{
    254266
    255     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];   
    256 
     267    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     268    MPInterp *interp = [[MPInterp alloc] init];
     269
     270    /* Initialize new interpreter */
     271    if (![self interpInit: interp])
     272        return;
     273   
    257274    // establish a separate connection for communication from this thread
    258     // back to the PortsManager.app
    259     NSConnection *connection = [NSConnection connectionWithRegisteredName: @"PMApp" host: nil];
     275    // back to the Pallet.app
     276    NSConnection *connection = [NSConnection connectionWithRegisteredName:_applicationMessagePort host: nil];
    260277    id <MPDelegateProtocol> delegate = [connection rootProxy];
    261278    [connection enableMultipleThreads];   
     
    265282        name: NSConnectionDidDieNotification
    266283        object: connection];
     284   
    267285    [[[NSThread currentThread] threadDictionary] setObject: delegate forKey: @"delegate"];
    268286   
    269     if ([delegate shouldPerformTarget: [[op objectForKey: @"target"] stringValue] forPortName: [op objectForKey: @"portName"]])
     287    if ([delegate shouldPerformTarget: [op objectForKey: @"target"] forPortName: [op objectForKey: @"portName"]])
    270288    {
    271289        MPObject *result = nil;
    272         [delegate willPerformTarget: [[op objectForKey: @"target"] stringValue] forPortName: [op objectForKey: @"portName"]];
    273         [_interpLock lock]; // this can block for a long time if another op is in progress
     290        [_portExecLock lock]; // this can block for a long time if another op is in progress
     291        [delegate willPerformTarget: [op objectForKey: @"target"] forPortName: [op objectForKey: @"portName"]];
    274292        _currentOp = op;
    275         MPObject *workName = [_interp evaluateCommand: [MPObject objectWithString: MPOpenCommand]
    276             withObject: [op objectForKey: @"url"]];
    277         if ([_interp succeeded])
     293        MPObject *workName = [interp evaluateCommand: [MPObject objectWithString: MPOpenCommand]
     294                                          withObject: [MPObject objectWithString: [op objectForKey: @"url"]]];
     295        if ([interp succeeded])
    278296        {
    279             result = [_interp evaluateCommand: [MPObject objectWithString: MPExecCommand]
    280                 withObjects: workName : [op objectForKey: @"target"]];
    281             if ([_interp succeeded])
     297            result = [interp evaluateCommand: [MPObject objectWithString: MPExecCommand]
     298                                 withObjects: workName : [MPObject objectWithString: [op objectForKey: @"target"]]];
     299            if ([interp succeeded])
    282300            {
    283                 result = [_interp evaluateCommand: [MPObject objectWithString: MPCloseCommand] withObject: workName];           
    284             } 
     301                result = [interp evaluateCommand: [MPObject objectWithString: MPCloseCommand] withObject: workName];           
     302            }
    285303        }
    286304        _currentOp = nil;
    287         [_interpLock unlock];
    288         [delegate didPerformTarget: [[op objectForKey: @"target"] stringValue] forPortName: [op objectForKey: @"portName"] withResult: [result stringValue]];
     305        [_portExecLock unlock];
     306        [delegate didPerformTarget: [op objectForKey: @"target"] forPortName: [op objectForKey: @"portName"] withResult: [result stringValue]];
    289307    }
    290308
    291     // Be sure to unregister for NSConnectionDidDieNotification before
     309    // Unregister for NSConnectionDidDieNotification before
    292310    // auto-releasing the connection object
    293311    [[NSNotificationCenter defaultCenter] removeObserver:self
     
    297315    [op release];
    298316    [pool release];
    299 
     317    /* Do NOT release interpreter until ALL MPObjects are released */
     318    [interp release];
    300319}
    301320
     
    303322- (MPObject *) ui_puts: (NSArray *)array
    304323{
    305     NSString *priority= [[array objectAtIndex: 1] stringValue];
    306     NSString *message = [[array objectAtIndex: 2] stringValue];
    307     BOOL noNewLine = (([array count] > 3) && [[array objectAtIndex:3] containsString: @"-nonewline"]);   
     324    NSDictionary *message = [[array objectAtIndex: 1] dictionaryValue];
     325    if (message == nil)
     326        return [MPObject objectWithString: MPNoResult];
     327
     328    NSString *data = [message objectForKey: @"data"];
     329    NSString *priority = [message objectForKey: @"priority"];
     330    if (data == nil || priority == nil)
     331        return [MPObject objectWithString: MPNoResult];
     332
    308333    id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
    309     [delegate displayMessage: [NSString stringWithFormat: @"%@%@", message, (noNewLine ? @"" : @"\n")]
    310         withPriority: priority
    311         forPortName: [_currentOp objectForKey: @"portName"]];       
     334    [delegate displayMessage: message forPortName: [_currentOp objectForKey: @"portName"]];
    312335    return [MPObject objectWithString: MPYesResult];
    313336}
    314337
    315338
    316 - (MPObject *) ui_display:(NSArray *) array
    317 {
    318     NSString *filename = [[array objectAtIndex:1] stringValue];
    319     NSString *contents = [NSString stringWithContentsOfFile: filename];
    320     if (nil != contents) {
    321         id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
    322         [delegate displayMessage: contents
    323                     withPriority: @"msg"
    324                      forPortName: [_currentOp objectForKey: @"portName"]];
    325         return [MPObject objectWithString: MPYesResult];
    326     }
    327     NSLog(@"%@ failed %@: %@", @"ui_display", @"stringWithContentsOfFile", filename);
    328     return [MPObject objectWithString: MPNoResult];
    329 }
    330 
    331 
    332 - (MPObject *) ui_confirm: (NSArray *) array
    333 {
    334     NSString *message = [[array objectAtIndex: 1] stringValue];
    335     id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
    336     BOOL result = [delegate askMessage: message
    337                          needsResponse: YES
    338                            forPortName: [_currentOp objectForKey: @"portName"]];
    339     return [MPObject objectWithString: (result) ? MPYesResult : MPNoResult];
    340 }
    341 
    342 
    343 - (MPObject *) ui_yesno:(NSArray *) array
    344 {
    345     NSString *message = [[array objectAtIndex: 1] stringValue];
    346     id delegate = [[[NSThread currentThread] threadDictionary] objectForKey: @"delegate"];
    347     BOOL result = [delegate askMessage: message
    348                          needsResponse: NO
    349                            forPortName: [_currentOp objectForKey: @"portName"]];
    350     return [MPObject objectWithString: (result) ? MPYesResult : MPNoResult];
    351 }
    352 
    353 
    354 
    355339@end
  • users/rhwood/Pallet/MPTool/MPAgentProtocol.h

    r23417 r28251  
    3131 POSSIBILITY OF SUCH DAMAGE.
    3232 */
     33
     34// mach port names */
     35#define MPAgentMessagePort @"org.macports.Pallet.Agent"
     36#define MPAppMessagePort @"org.macports.Pallet.Application"
    3337
    3438// port keys
  • users/rhwood/Pallet/MPTool/MPInterp.h

    r26307 r28251  
    1 //
    2 //  MPInterp.h
    3 //  DarwinPorts
    4 //
    51/*
    6  Copyright (c) 2003 Apple Computer, Inc.
    7  All rights reserved.
    8 
    9  Redistribution and use in source and binary forms, with or without
    10  modification, are permitted provided that the following conditions
    11  are met:
    12  1. Redistributions of source code must retain the above copyright
    13  notice, this list of conditions and the following disclaimer.
    14  2. Redistributions in binary form must reproduce the above copyright
    15  notice, this list of conditions and the following disclaimer in the
    16  documentation and/or other materials provided with the distribution.
    17  3. Neither the name of Apple Computer, Inc. nor the names of its contributors
    18  may be used to endorse or promote products derived from this software
    19  without specific prior written permission.
    20 
    21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    31  POSSIBILITY OF SUCH DAMAGE.
     2 * MPInterp.h
     3 * DarwinPorts
     4 *
     5 * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     17 *    its contributors may be used to endorse or promote products derived
     18 *    from this software without specific prior written permission.
     19 *
     20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3230 */
    3331
    3432#import <Foundation/Foundation.h>
    3533#include <tcl.h>
     34
     35// package info
     36static NSString *MPPackageName = @"macports";
     37static NSString *MPPackageVersion = @"1.0";
     38static NSString *MPPackageInit = @"mportinit";
     39
     40// commands
     41static NSString *MPSearchCommand = @"mportsearch";
     42static NSString *MPOpenCommand = @"mportopen";
     43static NSString *MPExecCommand = @"mportexec";
     44static NSString *MPCloseCommand = @"mportclose";
     45
     46// arguments
     47static NSString *MPAnyPortArgument = @".+";
     48
     49// results
     50static NSString *MPYesResult = @"1";
     51static NSString *MPNoResult = @"0";
     52static NSString *MPNullResult = @"";
     53
     54// ui
     55static NSString *MPUIPuts = @"ui_puts";
    3656
    3757@class MPObject;
     
    4666- (id) init;
    4767- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit;
    48 - (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion;
    4968
    5069- (MPObject *) setVariable: (MPObject *)variable toValue: (MPObject *)value;
     
    5473- (MPObject *) evaluateCommand: (MPObject *)command withObject: (MPObject *)arg;
    5574- (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1 :(MPObject *)arg2;
    56 - (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1: (MPObject *)arg2: (MPObject *)arg3;
    5775- (MPObject *) evaluate: (NSArray *)args;
    5876
    5977- (BOOL) succeeded;
    6078
    61 - (BOOL) redirectCommand: (MPObject *) command toObject: (id)handler;
     79- (BOOL) redirectCommand: (NSString *) command toObject: (id)handler;
    6280
    6381@end
  • users/rhwood/Pallet/MPTool/MPInterp.m

    r26307 r28251  
    1 //
    2 //  MPInterp.m
    3 //  DarwinPorts
    4 //
    51/*
    6  Copyright (c) 2003 Apple Computer, Inc.
    7  All rights reserved.
    8 
    9  Redistribution and use in source and binary forms, with or without
    10  modification, are permitted provided that the following conditions
    11  are met:
    12  1. Redistributions of source code must retain the above copyright
    13  notice, this list of conditions and the following disclaimer.
    14  2. Redistributions in binary form must reproduce the above copyright
    15  notice, this list of conditions and the following disclaimer in the
    16  documentation and/or other materials provided with the distribution.
    17  3. Neither the name of Apple Computer, Inc. nor the names of its contributors
    18  may be used to endorse or promote products derived from this software
    19  without specific prior written permission.
    20 
    21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    31  POSSIBILITY OF SUCH DAMAGE.
     2 * MPInterp.m
     3 * DarwinPorts
     4 *
     5 * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     17 *    its contributors may be used to endorse or promote products derived
     18 *    from this software without specific prior written permission.
     19 *
     20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3230 */
    3331
     
    4240@implementation MPInterp
    4341/*
    44     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.
     42    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.
    4543*/
    4644
     
    4846/** Redirect Handler */
    4947
    50 SEL makeSelector(NSString *name) {
     48static SEL makeSelector(NSString *name) {
    5149    NSString *methodName = [name stringByAppendingString:@":"];
    5250    return sel_getUid([methodName cString]);
     
    5553
    5654//Tcl_CreateObjCommand(_interp, [command cString], MPCommandHandler, handler, NULL);
    57 int MPCommandHandler(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
     55static int MPCommandHandler(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
    5856{
    5957    id handler = (id) clientData;
     
    8482        _interp = Tcl_CreateInterp();
    8583        Tcl_Init(_interp);
    86                
    8784    }
    8885    return self;
     
    9390{
    9491    Tcl_DeleteInterp(_interp);
    95     [super release];
    96 }
    97 
    98 - (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit
    99 {
    100         [self loadPackage:packageName version:packageVersion];
    101        
    102         if (TCL_OK == _status) {
    103                 [self evaluateCommand: [MPObject objectWithString: packageInit]];
    104         }
    105        
    106     return (TCL_OK == _status);
    107 }
    108 
    109 - (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit withArguments:(NSArray *)args
    110 {
    111         [self loadPackage:packageName version:packageVersion];
    112                
    113         if (TCL_OK == _status) {
    114                 [self evaluateCommand: [MPObject objectWithString: packageInit]];
    115         }
    116 
    117     return (TCL_OK == _status);
    118 }
    119 
    120 - (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion
     92    [super dealloc];
     93}
     94
     95
     96- (BOOL) loadPackage: (NSString *)packageName version: (NSString *)packageVersion usingCommand: (NSString *)packageInit
    12197{
    12298    char *name = (nil != packageName) ? strdup([packageName cString]) : NULL;
    12399    char *version = (nil != packageVersion) ? strdup([packageVersion cString]) : NULL;
    124        
    125     Tcl_PkgRequire(_interp, name, version, 0);
    126        
     100
     101    if (!Tcl_PkgRequire(_interp, name, version, 0))
     102        return NO;
     103   
     104    if (![self evaluateCommand: [MPObject objectWithString: packageInit]])
     105        return NO;
     106
    127107    if (name) free(name);
    128108    if (version) free(version);
    129        
     109
    130110    return (TCL_OK == _status);
    131111}
     112
    132113
    133114/** Variables */
     
    162143}
    163144
    164 - (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1: (MPObject *)arg2
     145- (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1 : (MPObject *)arg2
    165146{
    166147    NSArray *array = [NSArray arrayWithObjects:command,arg1,arg2,nil];
     
    168149}
    169150
    170 - (MPObject *) evaluateCommand: (MPObject *)command withObjects: (MPObject *)arg1: (MPObject *)arg2: (MPObject *)arg3
    171 {
    172     NSArray *array = [NSArray arrayWithObjects:command,arg1,arg2,arg3,nil];
    173     return [self evaluate:array];
    174 }
    175151
    176152- (MPObject *) evaluate: (NSArray*)args
     
    195171        NSLog(@"failed: %@\n args:\t%@", result, args);
    196172    }
     173    else
     174    {
     175        NSLog(@"succeeded args:\t%@", args);
     176    }
    197177    free(objv);
    198178    return result;
     
    208188
    209189
    210 - (BOOL) redirectCommand: (MPObject *)command toObject: (id)handler
    211 {
    212     SEL selector = makeSelector([command stringValue]);
     190- (BOOL) redirectCommand: (NSString *) command toObject: (id)handler
     191{
     192    SEL selector = makeSelector(command);
    213193    if (NULL == selector || ![handler respondsToSelector:selector])
    214194        return NO;
Note: See TracChangeset for help on using the changeset viewer.