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 #warning Need to add a constant data store containing all available component instances... could be lazy and build it on class +load.
19 @implementation ITOSAComponent
21 + (ITOSAComponent *)appleScriptComponent
23 return [[[ITOSAComponent alloc] initWithSubtype:kAppleScriptSubtype] autorelease];
26 + (ITOSAComponent *)componentWithCarbonComponent:(Component)component
28 return [[[ITOSAComponent alloc] initWithComponent:component] autorelease];
31 + (NSArray *)availableComponents
33 Component currentComponent = 0;
34 ComponentDescription cd;
35 NSMutableArray *components = [[NSMutableArray alloc] init];
37 cd.componentType = kOSAComponentType;
38 cd.componentSubType = 0;
39 cd.componentManufacturer = 0;
40 cd.componentFlags = 0;
41 cd.componentFlagsMask = 0;
42 while ((currentComponent = FindNextComponent(currentComponent, &cd)) != 0) {
43 [components addObject:[ITOSAComponent componentWithCarbonComponent:currentComponent]];
45 return [NSArray arrayWithArray:[components autorelease]];
48 - (id)initWithSubtype:(unsigned long)subtype
50 ComponentDescription cd;
51 cd.componentType = kOSAComponentType;
52 cd.componentSubType = subtype;
53 cd.componentManufacturer = 0;
54 cd.componentFlags = 0;
55 cd.componentFlagsMask = 0;
56 Component temp = FindNextComponent(0, &cd);
57 if ( (self = [self initWithComponent:temp]) ) {
62 - (id)initWithComponent:(Component)component;
64 if ( (self = [super init]) ) {
65 Handle componentName = NewHandle(0);
66 Handle componentInfo = NewHandle(0);
67 ComponentDescription description;
68 NSMutableDictionary *information;
70 _component = component;
71 _componentInstance = OpenComponent(component);
73 if (GetComponentInfo(component, &description, componentName, componentInfo, nil) != 0) {
74 NSLog(@"FATAL ERROR!");
78 information = [[NSMutableDictionary alloc] init];
83 OSAScriptingComponentName(_componentInstance, &name);
84 length = AEGetDescDataSize(&name);
85 buffer = malloc(length);
87 AEGetDescData(&name, buffer, length);
89 [information setObject:[NSString stringWithCString:buffer length:length] forKey:@"ITOSAComponentName"];
93 //[information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentName"];
94 [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentInfo"];
95 [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITOSAComponentSubtype"];
96 [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITOSAComponentManufacturer"];
97 _information = [information copy];
104 [_information release];
107 - (NSString *)description
109 return [_information objectForKey:@"ITOSAComponentName"];
112 - (Component)component
117 - (ComponentInstance)componentInstance
119 return _componentInstance;
122 - (NSDictionary *)information