New ITOSAComponent
authorKent Sutherland <ksuther@ithinksw.com>
Fri, 23 Jan 2004 22:10:36 +0000 (22:10 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Fri, 23 Jan 2004 22:10:36 +0000 (22:10 +0000)
ITFoundation.h
ITFoundation.xcode/project.pbxproj
ITOSAComponent.h [new file with mode: 0755]
ITOSAComponent.m [new file with mode: 0755]
ITOSAScript.h
ITOSAScript.m

index 03a83a4..64ab051 100755 (executable)
@@ -15,6 +15,7 @@
 #import <Cocoa/Cocoa.h>
 
 #import <ITFoundation/ITOSAScript.h>
+#import <ITFoundation/ITOSAComponent.h>
 #import <ITFoundation/ITAppleEventCenter.h>
 #import <ITFoundation/ITDebug.h>
 
index b8a2514..1780c87 100755 (executable)
                        children = (
                                370786C005C0B4D700E6D1BA,
                                370786C105C0B4D700E6D1BA,
+                               37B9B08005C1C47E00702FDB,
+                               37B9B08105C1C47E00702FDB,
                                7CA50B2B054E77950074E1D9,
                                7CA50B2C054E77950074E1D9,
                                7CA50B2F054E77A00074E1D9,
                        settings = {
                        };
                };
+               37B9B08005C1C47E00702FDB = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = ITOSAComponent.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               37B9B08105C1C47E00702FDB = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = ITOSAComponent.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               37B9B08205C1C47E00702FDB = {
+                       fileRef = 37B9B08005C1C47E00702FDB;
+                       isa = PBXBuildFile;
+                       settings = {
+                               ATTRIBUTES = (
+                                       Public,
+                               );
+                       };
+               };
+               37B9B08305C1C47E00702FDB = {
+                       fileRef = 37B9B08105C1C47E00702FDB;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
 //370
 //371
 //372
                                7CA50D7E054E7C600074E1D9,
                                7CA50B2D054E77950074E1D9,
                                370786C205C0B4D700E6D1BA,
+                               37B9B08205C1C47E00702FDB,
                                7CA50B31054E77A00074E1D9,
                                3D2D8A13055E07D800F59C27,
                                2AB93A3205705A0C007E748F,
                                7CF6C939057D65BA007FEC13,
                                7C97DC2F05B614300013E85F,
                                370786C305C0B4D700E6D1BA,
+                               37B9B08305C1C47E00702FDB,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/ITOSAComponent.h b/ITOSAComponent.h
new file mode 100755 (executable)
index 0000000..54b3b04
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *     ITFoundation
+ *      ITOSAComponent
+ *          A Cocoa wrapper for scripting components.
+ *
+ *     Original Author : Kent Sutherland <ksutherland@ithinksw.com>
+ *      Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
+ *      Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
+ *
+ *     Copyright (c) 2002 - 2004 iThink Software.
+ *     All Rights Reserved
+ *
+ */
+
+#import <Foundation/Foundation.h>
+#import <Carbon/Carbon.h>
+
+@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 (executable)
index 0000000..9ab1a7f
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ *     ITFoundation
+ *      ITOSAComponent
+ *          A Cocoa wrapper for scripting components.
+ *
+ *     Original Author : Kent Sutherland <ksutherland@ithinksw.com>
+ *      Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
+ *      Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
+ *
+ *     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
index 8462951..3d29aa9 100755 (executable)
 #import <Foundation/Foundation.h>
 #import <Carbon/Carbon.h>
 
+@class ITOSAComponent;
+
 @interface ITOSAScript : NSObject {
     NSString *_source;
-    unsigned long _scriptSubtype;
+    ITOSAComponent *_component;
 }
 
 - (id)initWithContentsOfFile:(NSString *)path;
 
 - (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;
 
index 6b079c8..833c84f 100755 (executable)
@@ -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);