From 5edc719e9181e04faaa247bfa389471bc57b9402 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Fri, 23 Jan 2004 22:10:36 +0000 Subject: [PATCH] New ITOSAComponent --- ITFoundation.h | 1 + ITFoundation.xcode/project.pbxproj | 35 +++++++++++ ITOSAComponent.h | 32 ++++++++++ ITOSAComponent.m | 95 ++++++++++++++++++++++++++++++ ITOSAScript.h | 11 +++- ITOSAScript.m | 24 +++++--- 6 files changed, 187 insertions(+), 11 deletions(-) create mode 100755 ITOSAComponent.h create mode 100755 ITOSAComponent.m diff --git a/ITFoundation.h b/ITFoundation.h index 03a83a4..64ab051 100755 --- a/ITFoundation.h +++ b/ITFoundation.h @@ -15,6 +15,7 @@ #import #import +#import #import #import diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index b8a2514..1780c87 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -153,6 +153,8 @@ children = ( 370786C005C0B4D700E6D1BA, 370786C105C0B4D700E6D1BA, + 37B9B08005C1C47E00702FDB, + 37B9B08105C1C47E00702FDB, 7CA50B2B054E77950074E1D9, 7CA50B2C054E77950074E1D9, 7CA50B2F054E77A00074E1D9, @@ -334,6 +336,37 @@ settings = { }; }; + 37B9B08005C1C47E00702FDB = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = ITOSAComponent.h; + refType = 4; + sourceTree = ""; + }; + 37B9B08105C1C47E00702FDB = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = ITOSAComponent.m; + refType = 4; + sourceTree = ""; + }; + 37B9B08205C1C47E00702FDB = { + fileRef = 37B9B08005C1C47E00702FDB; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + 37B9B08305C1C47E00702FDB = { + fileRef = 37B9B08105C1C47E00702FDB; + isa = PBXBuildFile; + settings = { + }; + }; //370 //371 //372 @@ -654,6 +687,7 @@ 7CA50D7E054E7C600074E1D9, 7CA50B2D054E77950074E1D9, 370786C205C0B4D700E6D1BA, + 37B9B08205C1C47E00702FDB, 7CA50B31054E77A00074E1D9, 3D2D8A13055E07D800F59C27, 2AB93A3205705A0C007E748F, @@ -695,6 +729,7 @@ 7CF6C939057D65BA007FEC13, 7C97DC2F05B614300013E85F, 370786C305C0B4D700E6D1BA, + 37B9B08305C1C47E00702FDB, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; diff --git a/ITOSAComponent.h b/ITOSAComponent.h new file mode 100755 index 0000000..54b3b04 --- /dev/null +++ b/ITOSAComponent.h @@ -0,0 +1,32 @@ +/* + * ITFoundation + * ITOSAComponent + * A Cocoa wrapper for scripting components. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * Responsibility : Joseph Spiros + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + +#import +#import + +@interface ITOSAComponent : NSObject { + Component _component; + ComponentInstance _componentInstance; + NSDictionary *_information; +} ++ (NSArray *)availableComponents; + +- (id)initWithSubtype:(unsigned long)subtype; +- (id)initWithComponent:(Component)component; + +- (Component)component; +- (ComponentInstance)componentInstance; +- (NSDictionary *)information; + +@end diff --git a/ITOSAComponent.m b/ITOSAComponent.m new file mode 100755 index 0000000..9ab1a7f --- /dev/null +++ b/ITOSAComponent.m @@ -0,0 +1,95 @@ +/* + * ITFoundation + * ITOSAComponent + * A Cocoa wrapper for scripting components. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * Responsibility : Joseph Spiros + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + +#import "ITOSAComponent.h" + +@implementation ITOSAComponent + ++ (NSArray *)availableComponents +{ + Component currentComponent = 0; + ComponentDescription cd; + + cd.componentType = kOSAComponentType; + cd.componentSubType = 0; + cd.componentManufacturer = 0; + cd.componentFlags = 0; + cd.componentFlagsMask = 0; + + while ((currentComponent = FindNextComponent(0, &cd)) != 0) { + } + return [NSArray array]; +} + +- (id)initWithSubtype:(unsigned long)subtype +{ + ComponentDescription cd; + cd.componentType = kOSAComponentType; + cd.componentSubType = subtype; + cd.componentManufacturer = 0; + cd.componentFlags = 0; + cd.componentFlagsMask = 0; + Component temp = FindNextComponent(0, &cd); + if ( (self = [self initWithComponent:temp]) ) { + } + return self; +} + +- (id)initWithComponent:(Component)component; +{ + if ( (self = [super init]) ) { + Handle componentName = NewHandle(0); + Handle componentInfo = NewHandle(0); + ComponentDescription description; + NSMutableDictionary *information; + + _component = component; + _componentInstance = OpenComponent(component); + + if (GetComponentInfo(component, &description, componentName, componentInfo, nil) != 0) { + NSLog(@"FATAL ERROR!"); + return nil; + } + + information = [[NSMutableDictionary alloc] init]; + [information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITComponentName"]; + [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITComponentInfo"]; + [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITComponentSubtype"]; + [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITComponentManufacturer"]; + + } + return self; +} + +- (void)dealloc +{ + [_information release]; +} + +- (Component)component +{ + return _component; +} + +- (ComponentInstance)componentInstance +{ + return _componentInstance; +} + +- (NSDictionary *)information +{ + return _information; +} + +@end diff --git a/ITOSAScript.h b/ITOSAScript.h index 8462951..3d29aa9 100755 --- a/ITOSAScript.h +++ b/ITOSAScript.h @@ -15,9 +15,11 @@ #import #import +@class ITOSAComponent; + @interface ITOSAScript : NSObject { NSString *_source; - unsigned long _scriptSubtype; + ITOSAComponent *_component; } - (id)initWithContentsOfFile:(NSString *)path; @@ -25,8 +27,11 @@ - (NSString *)source; - (void)setSource:(NSString *)newSource; -- (unsigned long)scriptSubtype; -- (void)setScriptSubtype:(unsigned long)newSubtype; +- (ITOSAComponent *)component; +- (void)setComponent:(ITOSAComponent *)newComponent; + +- (BOOL)compile; +- (BOOL)isCompiled; - (NSString *)execute; diff --git a/ITOSAScript.m b/ITOSAScript.m index 6b079c8..833c84f 100755 --- a/ITOSAScript.m +++ b/ITOSAScript.m @@ -19,6 +19,7 @@ Script Subtypes: */ #import "ITOSAScript.h" +#import "ITOSAComponent.h" @implementation ITOSAScript @@ -26,7 +27,6 @@ Script Subtypes: { if ( (self = [super init]) ) { _source = nil; - _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript } return self; } @@ -35,7 +35,6 @@ Script Subtypes: { if ( (self = [super init]) ) { _source = [[NSString alloc] initWithContentsOfFile:path]; - _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript } return self; } @@ -44,7 +43,6 @@ Script Subtypes: { if ( (self = [super init]) ) { [self setSource:source]; - _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript } return self; } @@ -66,14 +64,24 @@ Script Subtypes: _source = [newSource copy]; } -- (unsigned long)scriptSubtype +- (ITOSAComponent *)component { - return _scriptSubtype; + return _component; } -- (void)setScriptSubtype:(unsigned long)newSubtype +- (void)setComponent:(ITOSAComponent *)newComponent { - _scriptSubtype = newSubtype; + _component = newComponent; +} + +- (BOOL)compile +{ + return NO; +} + +- (BOOL)isCompiled +{ + return NO; } - (NSString *)execute @@ -85,7 +93,7 @@ Script Subtypes: AECreateDesc(typeChar, [_source cString], [_source cStringLength], &scriptDesc); - OSADoScript(OpenDefaultComponent(kOSAComponentType, _scriptSubtype), &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc); + OSADoScript([_component componentInstance], &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc); length = AEGetDescDataSize(&resultDesc); buffer = malloc(length); -- 2.20.1