Ignore:
Timestamp:
Oct 5, 2008, 2:52:05 AM (16 years ago)
Author:
armahg@…
Message:

Added setPortOptions method to MPMacPorts. Builds ok. Yet to document funcionality and test method

Location:
contrib/MacPorts_Framework
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • contrib/MacPorts_Framework/MPInterpreter.h

    r40216 r40518  
    9898@interface MPInterpreter : NSObject  {
    9999       
    100         Tcl_Interp* _interpreter;
    101         NSString * helperToolInterpCommand;
    102         NSString * helperToolCommandResult;
     100        Tcl_Interp*     _interpreter;
     101        NSString *      helperToolInterpCommand;
     102        NSString *      helperToolCommandResult;
     103        NSArray *       defaultPortOptions;
    103104       
    104105}
    105106
    106 
     107//Internal methods
     108-(BOOL) setOptionsForNewTclPort:(NSArray *)options;
    107109
    108110/*!
     
    110112 */
    111113+ (MPInterpreter *)sharedInterpreter;
     114
     115
    112116
    113117
     
    116120 @param path An NSString specifying the absolute path for the macports tcl package
    117121 */
    118 + (MPInterpreter *)sharedInterpreterWithPkgPath:(NSString *)path;
     122+ (MPInterpreter *)sharedInterpreterWithPkgPath:(NSString *)path portOptions:(NSArray *)options;
    119123
    120124
     
    190194
    191195// METHODS FOR INTERNAL USE ONLY
    192 - (id) initWithPkgPath:(NSString *)path;
    193196- (Tcl_Interp *) sharedInternalTclInterpreter;
    194197- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray*)args;
  • contrib/MacPorts_Framework/MPInterpreter.m

    r40301 r40518  
    165165static NSString * tclInterpreterPkgPath = nil;
    166166
    167 
    168 - (id) init {
    169         return [self initWithPkgPath:MP_DEFAULT_PKG_PATH];
    170 }
    171 
    172 //Internal method for initializing Tcl interpreter
     167#pragma mark -
     168#pragma mark Internal Methods
     169//Internal method for initializing actual C Tcl interpreter
    173170//Should I be using a double pointer like is done for NSError ?
    174171-(BOOL) initTclInterpreter:(Tcl_Interp * *)interp withPath:(NSString *)path {
    175172        BOOL result = NO;
    176        
    177173        *interp = Tcl_CreateInterp();
    178174       
     
    187183                return result;
    188184        }
     185       
     186        if (path == nil)
     187                path = MP_DEFAULT_PKG_PATH;
    189188       
    190189       
     
    206205       
    207206        if( Tcl_EvalFile(*interp, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"]
    208                                                                          pathForResource:@"init"
    209                                                                          ofType:@"tcl"] UTF8String]) != TCL_OK) {
     207                                                                pathForResource:@"init"
     208                                                                ofType:@"tcl"] UTF8String]) != TCL_OK) {
    210209                NSLog(@"Error in Tcl_EvalFile init.tcl: %s", Tcl_GetStringResult(*interp));
    211210                Tcl_DeleteInterp(*interp);
     
    228227                       
    229228                        while ((opt = [optionsEnum nextObject])) {
    230                                 if (Tcl_Eval(*interp , [[NSString stringWithFormat:@"set ui_options(%@) \"yes\"", opt] UTF8String]) != TCL_OK)
     229                                if (Tcl_Eval(*interp , [[NSString stringWithFormat:@"set ui_options(%@) \"yes\"", opt] UTF8String]) != TCL_OK) {
     230                                        NSLog(@"Error in Tcl_Eval for set ui_options: %s", Tcl_GetStringResult(*interp));
    231231                                        return result;
     232                                }
    232233                        }
    233234                        result = YES;
     
    239240}
    240241
    241 - (id) initWithPkgPath:(NSString *)path {
     242//Wrapper method for above. Used when
     243-(BOOL) setOptionsForNewTclPort:(NSArray *)options {
     244        BOOL result = NO;
     245       
     246        //First delete our internal Tcl interpreter
     247        Tcl_DeleteInterp(_interpreter);
     248       
     249        if (tclInterpreterPkgPath == nil)
     250                result = [self initTclInterpreter:&_interpreter withPath:MP_DEFAULT_PKG_PATH];
     251        else
     252                result = [self initTclInterpreter:&_interpreter withPath:tclInterpreterPkgPath];
     253       
     254        BOOL tempResult = [self setOptions:options forTclInterpreter:&_interpreter];
     255               
     256       
     257       
     258       
     259        return (result && tempResult) ;
     260}
     261
     262- (id) initWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
    242263        if (self = [super init]) {
    243264               
    244265                [self initTclInterpreter:&_interpreter withPath:path];
     266               
     267                //set port options maybe I should do this elsewhere?
     268                defaultPortOptions = [NSArray arrayWithObjects: MPDEBUGOPTION, nil];
     269                if (options == nil)
     270                        options = defaultPortOptions;
     271                [self setOptions:options forTclInterpreter:&_interpreter];
    245272               
    246273                //Initialize helperToolInterpCommand
     
    256283
    257284
    258 + (MPInterpreter*)sharedInterpreter {
    259        
    260         return [self sharedInterpreterWithPkgPath:MP_DEFAULT_PKG_PATH];
     285#pragma mark API methods
     286- (id) init {
     287        return [self initWithPkgPath:MP_DEFAULT_PKG_PATH portOptions:nil];
    261288}
    262289
     
    264291        @synchronized(self) {
    265292                if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"] == nil) {
    266                         [[self alloc] initWithPkgPath:path]; // assignment not done here
     293                        [[self alloc] initWithPkgPath:path portOptions:nil]; // assignment not done here
     294                }
     295        }
     296        return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"];
     297}
     298
     299+ (MPInterpreter*)sharedInterpreter{
     300        return [self sharedInterpreterWithPkgPath:MP_DEFAULT_PKG_PATH];
     301}
     302
     303
     304
     305+ (MPInterpreter*)sharedInterpreterWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
     306        @synchronized(self) {
     307                if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"] == nil) {
     308                        [[self alloc] initWithPkgPath:path portOptions:options]; // assignment not done here
    267309                }
    268310        }
  • contrib/MacPorts_Framework/MPMacPorts.h

    r39766 r40518  
    8282+ (MPMacPorts *)sharedInstance;
    8383
     84+ (MPMacPorts *)sharedInstanceWithPortOptions:(NSArray *)options;
     85
    8486//Names of messages below are subject to change
    8587+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path;
    86 - (id) initWithPkgPath:(NSString *)path;
     88+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path portOptions:(NSArray *)options;
     89- (id) initWithPkgPath:(NSString *)path portOptions:(NSArray *)options;
     90- (BOOL) setPortOptions:(NSArray *)options;
    8791
    8892/*!
  • contrib/MacPorts_Framework/MPMacPorts.m

    r39766 r40518  
    4242
    4343- (id) init {
    44         return [self initWithPkgPath:MP_DEFAULT_PKG_PATH];
    45 }
    46 
    47 
    48 - (id) initWithPkgPath:(NSString *)path {
     44        return [self initWithPkgPath:MP_DEFAULT_PKG_PATH portOptions:nil];
     45}
     46
     47
     48- (id) initWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
    4949        if (self = [super init]) {
    50                 interpreter = [MPInterpreter sharedInterpreterWithPkgPath:path];
     50                interpreter = [MPInterpreter sharedInterpreterWithPkgPath:path portOptions:nil];
    5151                //[self registerForLocalNotifications];
    5252        }
     
    5656+ (MPMacPorts *)sharedInstance {
    5757        return [self sharedInstanceWithPkgPath:MP_DEFAULT_PKG_PATH];
     58}
     59
     60+ (MPMacPorts *)sharedInstanceWithPortOptions:(NSArray *)options {
     61        return [self sharedInstanceWithPkgPath:MP_DEFAULT_PKG_PATH portOptions:options];
     62}
     63
     64+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
     65        @synchronized(self) {
     66                if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"] == nil) {
     67                        [[self alloc] initWithPkgPath:path portOptions:options ]; // assignment not done here
     68                }
     69        }
     70        return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"];
    5871}
    5972
     
    6174        @synchronized(self) {
    6275                if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"] == nil) {
    63                         [[self alloc] initWithPkgPath:path]; // assignment not done here
     76                        [[self alloc] initWithPkgPath:path portOptions:nil ]; // assignment not done here
    6477                }
    6578        }
     
    6780}
    6881
    69 
     82- (BOOL) setPortOptions:(NSArray *)options {
     83        return [interpreter setOptionsForNewTclPort:options];
     84}
    7085
    7186
  • contrib/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj

    r39766 r40518  
    8888                        remoteGlobalIDString = 8DC2EF4F0486A6940098B216;
    8989                        remoteInfo = MacPorts;
    90                 };
    91                 6E31A2890E6F7910002804D0 /* PBXContainerItemProxy */ = {
    92                         isa = PBXContainerItemProxy;
    93                         containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
    94                         proxyType = 1;
    95                         remoteGlobalIDString = DFE353650CFB8F0C003BACFC;
    96                         remoteInfo = Docs;
    9790                };
    9891                6EC2608B0E4270110013BC48 /* PBXContainerItemProxy */ = {
     
    522515                                6ED12A530E3E55A50026773D /* PBXTargetDependency */,
    523516                                6EC2608C0E4270110013BC48 /* PBXTargetDependency */,
    524                                 6E31A28A0E6F7910002804D0 /* PBXTargetDependency */,
    525517                        );
    526518                        name = MacPorts;
     
    694686                        target = 8DC2EF4F0486A6940098B216 /* MacPorts */;
    695687                        targetProxy = 6E1AE8460E232D0700F6D7BC /* PBXContainerItemProxy */;
    696                 };
    697                 6E31A28A0E6F7910002804D0 /* PBXTargetDependency */ = {
    698                         isa = PBXTargetDependency;
    699                         target = DFE353650CFB8F0C003BACFC /* Docs */;
    700                         targetProxy = 6E31A2890E6F7910002804D0 /* PBXContainerItemProxy */;
    701688                };
    702689                6EC2608C0E4270110013BC48 /* PBXTargetDependency */ = {
Note: See TracChangeset for help on using the changeset viewer.