9ab1a7f68793d08587dd0c329dfd806bc096acd4
[ITFoundation.git] / ITOSAComponent.m
1 /*
2  *      ITFoundation
3  *      ITOSAComponent
4  *          A Cocoa wrapper for scripting components.
5  *
6  *      Original Author : Kent Sutherland <ksutherland@ithinksw.com>
7  *      Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
8  *      Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
9  *
10  *      Copyright (c) 2002 - 2004 iThink Software.
11  *      All Rights Reserved
12  *
13  */
14
15 #import "ITOSAComponent.h"
16
17 @implementation ITOSAComponent
18
19 + (NSArray *)availableComponents
20 {
21     Component currentComponent = 0;
22     ComponentDescription cd;
23     
24     cd.componentType = kOSAComponentType;
25     cd.componentSubType = 0;
26     cd.componentManufacturer = 0;
27     cd.componentFlags = 0;
28     cd.componentFlagsMask = 0;
29     
30     while ((currentComponent = FindNextComponent(0, &cd)) != 0) {
31     }
32     return [NSArray array];
33 }
34
35 - (id)initWithSubtype:(unsigned long)subtype
36 {
37     ComponentDescription cd;
38     cd.componentType = kOSAComponentType;
39     cd.componentSubType = subtype;
40     cd.componentManufacturer = 0;
41     cd.componentFlags = 0;
42     cd.componentFlagsMask = 0;
43     Component temp = FindNextComponent(0, &cd);
44     if ( (self = [self initWithComponent:temp]) ) {
45     }
46     return self;
47 }
48
49 - (id)initWithComponent:(Component)component;
50 {
51     if ( (self = [super init]) ) {
52         Handle componentName = NewHandle(0);
53         Handle componentInfo = NewHandle(0);
54         ComponentDescription description;
55         NSMutableDictionary *information;
56         
57         _component = component;
58         _componentInstance = OpenComponent(component);
59         
60         if (GetComponentInfo(component, &description, componentName, componentInfo, nil) != 0) {
61             NSLog(@"FATAL ERROR!");
62             return nil;
63         }
64         
65         information = [[NSMutableDictionary alloc] init];
66         [information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITComponentName"];
67         [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITComponentInfo"];
68         [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITComponentSubtype"];
69         [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITComponentManufacturer"];
70         
71     }
72     return self;
73 }
74
75 - (void)dealloc
76 {
77     [_information release];
78 }
79
80 - (Component)component
81 {
82     return _component;
83 }
84
85 - (ComponentInstance)componentInstance
86 {
87     return _componentInstance;
88 }
89
90 - (NSDictionary *)information
91 {
92     return _information;
93 }
94
95 @end