Ignore:
Timestamp:
Aug 12, 2008, 1:12:02 PM (9 years ago)
Author:
armahg@…
Message:

Cleaned up code for MPInterpreter.m and MPInterpreter.h classes. Removed unused methods and some comments. Removed AuthorizationRef warning in MPMacPorts.m

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m

    r39103 r39197  
    165165
    166166#pragma mark -
    167 #pragma mark Authorization Code
    168 
    169 - (BOOL)checkIfAuthorized {
    170         if  (internalMacPortsAuthRef == NULL ) {
    171                 return NO;
    172         }
    173         return YES;
    174 }
    175 
    176 -(void)setAuthorizationRef:(AuthorizationRef)authRef {
    177         //I can do this since Framework client responsible
    178         //for managing memory for Authorization
    179         internalMacPortsAuthRef = authRef;
    180 }
    181 
    182 
    183 
    184 
    185 #pragma mark -
    186 
    187 #pragma mark MPInterpreterProtocol
    188 
    189 - (BOOL) vendSelfForServer {
    190         NSConnection * defaultConn;
    191         defaultConn = [NSConnection defaultConnection];
    192         //NSLog(@"Creating connection ...");
    193        
    194         [defaultConn setRootObject:self];
    195        
    196         //NSLog(@"Connection Created ... "); //%@, %@", defaultConn, [defaultConn statistics]);
    197         return [defaultConn registerName:MP_DOSERVER];
    198        
    199 }
    200 
    201 - (bycopy NSString *) evaluateStringFromMPHelperTool:(in bycopy NSString *)statement {
    202         //- (NSString *) evaluateStringFromMPHelperTool:(NSString *)statement {
    203         //TO DO ->  error:(inout NSError **)evalError {
    204         //NSError * evalError;
    205         NSString * result = [self evaluateStringAsString:statement error:nil];
    206        
    207         //TO DO : WORK ON ERROR STUFF AFTER GETTING BASIC FUNCTIONALITY WORKING
    208         //For now ... Perhaps I might now have to take jberry's advice on ... Oh wait
    209         //I should be able to pass by reference duh!
    210         //return @"returning from evaluateStringFromMPHelperTool";
    211         return result;
    212 }
    213 
    214 
    215 - (void) setTclCommand:(in bycopy NSString *)tclCmd {
    216         if (![helperToolInterpCommand isEqualToString:tclCmd]) {
    217                
    218                 [helperToolInterpCommand release];
    219                 helperToolInterpCommand = [tclCmd copy];
    220         }
    221        
    222 }
    223 - (bycopy NSString *)getTclCommand {
    224         return helperToolInterpCommand;
    225 }
    226 
    227 - (void) setTclCommandResult:(in bycopy NSString *)tclCmdResult {
    228         if (![helperToolCommandResult isEqualToString:tclCmdResult]) {
    229                 [helperToolCommandResult release];
    230                 helperToolCommandResult = [tclCmdResult copy];
    231         }
    232 }
    233 - (bycopy NSString *) getTclCommandResult {
    234         return helperToolCommandResult;
    235 }
    236 
    237 - (void) log :(in bycopy id) logOutput {
    238         NSLog(@"MPInterpreterProtocol Logging : %@", logOutput);
    239 }
    240 
    241 #pragma mark -
    242167
    243168#pragma mark MPInterpreter Code
     
    280205                        Tcl_DeleteInterp(_interpreter);
    281206                }
    282                
    283                 /*if( Tcl_EvalFile(_interpreter, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"] pathForResource:@"init" ofType:@"tcl"] UTF8String]) != TCL_OK) {
    284                  NSLog(@"Error in Tcl_EvalFile init.tcl: %s", Tcl_GetStringResult(_interpreter));
    285                  Tcl_DeleteInterp(_interpreter);
    286                  }*/
    287                
     207                               
    288208                if( Tcl_EvalFile(_interpreter, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"]
    289209                                                                                 pathForResource:@"init"
     
    299219                //Initialize the MacPorts Tcl Package Path string
    300220                tclInterpreterPkgPath = [NSString stringWithString:path];
    301                
    302                 //Initialize the Run Loop because we don't know if framework will be
    303                 //run in a Foundation Kit or App Kit. Hopefully this won't hurt if the
    304                 //run loop is already running. We are doing this so that our NSConnection
    305                 //object is able to handle Distributed Object messages
    306                 //NOTE: Since MPinterpreter instances are created per thread, we don't have to
    307                 //worry (I hope) about running loops for different threads
    308                 //[[NSRunLoop currentRunLoop] run];
    309                
    310                 //if (![self vendSelfForServer]) {
    311 //                      NSLog(@"Failed To initialize NSConnection server ");
    312 //                      //Should probably do some more error handling over here
    313 //              }
    314 //              else
    315 //                      NSLog(@"MPInterpreter Initialized ...");
    316                
    317                
     221                               
    318222        }
    319223        return self;
    320 }
    321 
    322 - (Tcl_Interp *) sharedTclInterpreter {
    323         return _interpreter;
    324224}
    325225
     
    375275
    376276#pragma Utilities
    377 
    378 - (int) execute:(NSString *)pathToExecutable withArgs:(NSArray *)args {
    379         NSTask * task = [[NSTask alloc] init];
    380         [task setLaunchPath:pathToExecutable];
    381         [task setArguments:args];
    382         [task launch];
    383         [task waitUntilExit];
    384         int status = [task terminationStatus];
    385         [task release];
    386         return status;
    387 }
    388 
    389 /*- (NSDictionary *)evaluateArrayAsString:(NSArray *)statement {
    390  return [self evaluateStringAsString:[statement componentsJoinedByString:@" "]];
    391  }
    392  
    393  */
    394277- (NSString *)evaluateStringAsString:(NSString *)statement error:(NSError**)mportError{
    395278        //NSLog(@"Calling evaluateStringAsString with argument %@", statement);
     
    434317
    435318
    436 /*
    437  - (NSDictionary *)evaluateStringAsString:(NSString *)statement {
    438  int return_code = Tcl_Eval(_interpreter, [statement UTF8String]);
    439  return [NSDictionary dictionaryWithObjectsAndKeys:
    440  [NSNumber numberWithInt:return_code], TCL_RETURN_CODE,
    441  [NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)], TCL_RETURN_STRING, nil];
    442  }
    443  */
    444 
    445319- (NSArray *)arrayFromTclListAsString:(NSString *)list {
    446320        NSMutableArray *array;
     
    487361
    488362#pragma mark -
    489 #pragma mark Helper Tool(s) Code
     363#pragma mark Authorization Code
     364
     365- (BOOL)checkIfAuthorized {
     366        if  (internalMacPortsAuthRef == NULL ) {
     367                return NO;
     368        }
     369        return YES;
     370}
     371
     372-(void)setAuthorizationRef:(AuthorizationRef)authRef {
     373        //I can do this since Framework client responsible
     374        //for managing memory for Authorization
     375        internalMacPortsAuthRef = authRef;
     376}
     377
     378
     379
     380#pragma mark -
     381#pragma mark For Internal Use
    490382//NOTE: We expect the Framework client to initialize the AuthorizationRef
    491383//Completely before calling any privileged operation. Perhaps we
     
    584476        //NSLog(@"response dictionary is %@", response);
    585477        return (NSString *) newresult;
    586        
    587        
    588         /*
    589          NSString * fakeResult = @"Frustrated";
    590          return fakeResult;
    591          
    592          //Read from file and see if it was written to
    593          NSString * testFilePath = [[NSBundle bundleForClass:[self class]]
    594          pathForResource:@"TestFile" ofType:@"test"];
    595          NSError * readError = nil;
    596          NSString * result = [NSString stringWithContentsOfFile:testFilePath
    597          encoding:NSUTF8StringEncoding
    598          error:&readError];
    599          if (readError) {
    600          NSLog(@"Error is %@", [readError description]);
    601          return @"There was an error Reading";
    602          }
    603          else if ([result isEqualToString:@""]) {
    604          return @"An empty string was read";
    605          }
    606          else if (result == nil) {
    607          return @"Resulting String is NIL";
    608          }
    609          else
    610          return result;
    611          
    612          return @"This shouldn't happen";
    613          */
    614 }
    615 
    616 
    617 -(NSString *) evaluateStringWithSimpleMPDOPHelperTool:(NSString *)statement  {
     478
     479}
     480
     481- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray *)args {
    618482        NSTask * task = [[NSTask alloc] init];
    619         [task setLaunchPath:[[NSBundle bundleForClass:[MPInterpreter class]]
    620                                                  pathForResource:@"SimpleDOMPHelperTool"
    621                                                  ofType:nil]];
    622         [task setArguments:[NSArray arrayWithObjects:statement, nil]];
     483        [task setLaunchPath:pathToExecutable];
     484        [task setArguments:args];
    623485        [task launch];
    624        
    625486        [task waitUntilExit];
    626        
    627         [task terminationStatus];
    628        
    629         return [self getTclCommandResult];
    630 }
    631 
     487        int status = [task terminationStatus];
     488        [task release];
     489        return status;
     490}
     491
     492
     493- (Tcl_Interp *) sharedInternalTclInterpreter {
     494        return _interpreter;
     495}
    632496
    633497@end
Note: See TracChangeset for help on using the changeset viewer.