4 * A Cocoa wrapper for scripting components.
6 * Original Author : Kent Sutherland <ksutherland@ithinksw.com>
7 * Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
8 * Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
10 * Copyright (c) 2002 - 2004 iThink Software.
15 #import "ITOSAComponent.h"
17 @implementation ITOSAComponent
19 + (ITOSAComponent *)AppleScriptComponent
21 return [[[ITOSAComponent alloc] initWithSubtype:kAppleScriptSubtype] autorelease];
24 + (ITOSAComponent *)componentWithCarbonComponent:(Component)component
26 return [[[ITOSAComponent alloc] initWithComponent:component] autorelease];
29 + (NSArray *)availableComponents
31 Component currentComponent = 0;
32 ComponentDescription cd;
33 NSMutableArray *components = [[NSMutableArray alloc] init];
35 cd.componentType = kOSAComponentType;
36 cd.componentSubType = 0;
37 cd.componentManufacturer = 0;
38 cd.componentFlags = 0;
39 cd.componentFlagsMask = 0;
40 while ((currentComponent = FindNextComponent(currentComponent, &cd)) != 0) {
41 [components addObject:[ITOSAComponent componentWithCarbonComponent:currentComponent]];
43 return [NSArray arrayWithArray:[components autorelease]];
46 - (id)initWithSubtype:(unsigned long)subtype
48 ComponentDescription cd;
49 cd.componentType = kOSAComponentType;
50 cd.componentSubType = subtype;
51 cd.componentManufacturer = 0;
52 cd.componentFlags = 0;
53 cd.componentFlagsMask = 0;
54 Component temp = FindNextComponent(0, &cd);
55 if ( (self = [self initWithComponent:temp]) ) {
60 - (id)initWithComponent:(Component)component;
62 if ( (self = [super init]) ) {
63 Handle componentName = NewHandle(0);
64 Handle componentInfo = NewHandle(0);
65 ComponentDescription description;
66 NSMutableDictionary *information;
68 _component = component;
69 _componentInstance = OpenComponent(component);
71 if (GetComponentInfo(component, &description, componentName, componentInfo, nil) != 0) {
72 NSLog(@"FATAL ERROR!");
76 information = [[NSMutableDictionary alloc] init];
81 OSAScriptingComponentName(_componentInstance, &name);
82 length = AEGetDescDataSize(&name);
83 buffer = malloc(length);
85 AEGetDescData(&name, buffer, length);
87 [information setObject:[NSString stringWithCString:buffer length:length] forKey:@"ITOSAComponentName"];
91 //[information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentName"];
92 [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentInfo"];
93 [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITOSAComponentSubtype"];
94 [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITOSAComponentManufacturer"];
95 _information = [information copy];
102 [_information release];
105 - (NSString *)description
107 return [_information objectForKey:@"ITOSAComponentName"];
110 - (Component)component
115 - (ComponentInstance)componentInstance
117 return _componentInstance;
120 - (NSDictionary *)information