1 #import "ITOSAComponent.h"
3 // Need to add a constant data store containing all available component instances... could be lazy and build it on class +load.
5 @implementation ITOSAComponent
7 + (ITOSAComponent *)appleScriptComponent
9 return [[[ITOSAComponent alloc] initWithSubtype:kAppleScriptSubtype] autorelease];
12 + (ITOSAComponent *)componentWithCarbonComponent:(Component)component
14 return [[[ITOSAComponent alloc] initWithComponent:component] autorelease];
17 + (NSArray *)availableComponents
19 Component currentComponent = 0;
20 ComponentDescription cd;
21 NSMutableArray *components = [[NSMutableArray alloc] init];
23 cd.componentType = kOSAComponentType;
24 cd.componentSubType = 0;
25 cd.componentManufacturer = 0;
26 cd.componentFlags = 0;
27 cd.componentFlagsMask = 0;
28 while ((currentComponent = FindNextComponent(currentComponent, &cd)) != 0) {
29 [components addObject:[ITOSAComponent componentWithCarbonComponent:currentComponent]];
31 return [NSArray arrayWithArray:[components autorelease]];
34 - (id)initWithSubtype:(unsigned long)subtype
36 ComponentDescription cd;
37 cd.componentType = kOSAComponentType;
38 cd.componentSubType = subtype;
39 cd.componentManufacturer = 0;
40 cd.componentFlags = 0;
41 cd.componentFlagsMask = 0;
42 Component temp = FindNextComponent(0, &cd);
43 if ( (self = [self initWithComponent:temp]) ) {
48 - (id)initWithComponent:(Component)component;
50 if ( (self = [super init]) ) {
51 Handle componentName = NewHandle(0);
52 Handle componentInfo = NewHandle(0);
53 ComponentDescription description;
54 NSMutableDictionary *information;
56 _component = component;
57 _componentInstance = OpenComponent(component);
59 if (GetComponentInfo(component, &description, componentName, componentInfo, nil) != 0) {
60 NSLog(@"FATAL ERROR!");
64 information = [[NSMutableDictionary alloc] init];
69 OSAScriptingComponentName(_componentInstance, &name);
70 length = AEGetDescDataSize(&name);
71 buffer = malloc(length);
73 AEGetDescData(&name, buffer, length);
75 [information setObject:[NSString stringWithCString:buffer length:length] forKey:@"ITOSAComponentName"];
79 //[information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentName"];
80 [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentInfo"];
81 [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITOSAComponentSubtype"];
82 [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITOSAComponentManufacturer"];
83 _information = [information copy];
90 [_information release];
93 - (NSString *)description
95 return [_information objectForKey:@"ITOSAComponentName"];
98 - (Component)component
103 - (ComponentInstance)componentInstance
105 return _componentInstance;
108 - (NSDictionary *)information