-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITOSAComponent.m
113 lines (93 loc) · 3.15 KB
/
ITOSAComponent.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#import "ITOSAComponent.h"
// Need to add a constant data store containing all available component instances... could be lazy and build it on class +load.
@implementation ITOSAComponent
+ (ITOSAComponent *)appleScriptComponent
{
return [[[ITOSAComponent alloc] initWithSubtype:kAppleScriptSubtype] autorelease];
}
+ (ITOSAComponent *)componentWithCarbonComponent:(Component)component
{
return [[[ITOSAComponent alloc] initWithComponent:component] autorelease];
}
+ (NSArray *)availableComponents
{
Component currentComponent = 0;
ComponentDescription cd;
NSMutableArray *components = [[NSMutableArray alloc] init];
cd.componentType = kOSAComponentType;
cd.componentSubType = 0;
cd.componentManufacturer = 0;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
while ((currentComponent = FindNextComponent(currentComponent, &cd)) != 0) {
[components addObject:[ITOSAComponent componentWithCarbonComponent:currentComponent]];
}
return [NSArray arrayWithArray:[components autorelease]];
}
- (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];
AEDesc name;
Ptr buffer;
Size length;
OSAScriptingComponentName(_componentInstance, &name);
length = AEGetDescDataSize(&name);
buffer = malloc(length);
AEGetDescData(&name, buffer, length);
AEDisposeDesc(&name);
[information setObject:[NSString stringWithCString:buffer length:length] forKey:@"ITOSAComponentName"];
free(buffer);
buffer = NULL;
//[information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentName"];
[information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentInfo"];
[information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITOSAComponentSubtype"];
[information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITOSAComponentManufacturer"];
_information = [information copy];
}
return self;
}
- (void)dealloc
{
[_information release];
}
- (NSString *)description
{
return [_information objectForKey:@"ITOSAComponentName"];
}
- (Component)component
{
return _component;
}
- (ComponentInstance)componentInstance
{
return _componentInstance;
}
- (NSDictionary *)information
{
return _information;
}
@end