]>
Commit | Line | Data |
---|---|---|
9ce05555 | 1 | /* |
d8925383 | 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. |
9ce05555 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
9ce05555 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* CFPlugIn_Instance.c | |
24 | Copyright 1999-2002, Apple, Inc. All rights reserved. | |
25 | Responsibility: Doug Davidson | |
26 | */ | |
27 | ||
28 | #include "CFBundle_Internal.h" | |
29 | #include "CFInternal.h" | |
30 | ||
31 | static CFTypeID __kCFPlugInInstanceTypeID = _kCFRuntimeNotATypeID; | |
32 | ||
33 | struct __CFPlugInInstance { | |
34 | CFRuntimeBase _base; | |
35 | ||
36 | _CFPFactory *factory; | |
37 | ||
38 | CFPlugInInstanceGetInterfaceFunction getInterfaceFunction; | |
39 | CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceDataFunction; | |
40 | ||
41 | uint8_t _instanceData[0]; | |
42 | }; | |
43 | ||
44 | static CFStringRef __CFPlugInInstanceCopyDescription(CFTypeRef cf) { | |
45 | /* MF:!!! Implement me */ | |
46 | return CFSTR("Some CFPlugInInstance"); | |
47 | } | |
48 | ||
49 | static void __CFPlugInInstanceDeallocate(CFTypeRef cf) { | |
50 | CFPlugInInstanceRef instance = (CFPlugInInstanceRef)cf; | |
51 | ||
52 | __CFGenericValidateType(cf, __kCFPlugInInstanceTypeID); | |
53 | ||
54 | if (instance->deallocateInstanceDataFunction) { | |
55 | FAULT_CALLBACK((void **)&(instance->deallocateInstanceDataFunction)); | |
56 | (void)INVOKE_CALLBACK1(instance->deallocateInstanceDataFunction, (void *)(&instance->_instanceData[0])); | |
57 | } | |
58 | ||
59 | if (instance->factory) { | |
60 | _CFPFactoryRemoveInstance(instance->factory); | |
61 | } | |
62 | } | |
63 | ||
64 | static const CFRuntimeClass __CFPlugInInstanceClass = { | |
65 | 0, | |
66 | "CFPlugInInstance", | |
67 | NULL, // init | |
68 | NULL, // copy | |
69 | __CFPlugInInstanceDeallocate, | |
70 | NULL, // equal | |
71 | NULL, // hash | |
72 | NULL, // | |
73 | __CFPlugInInstanceCopyDescription | |
74 | }; | |
75 | ||
76 | __private_extern__ void __CFPlugInInstanceInitialize(void) { | |
77 | __kCFPlugInInstanceTypeID = _CFRuntimeRegisterClass(&__CFPlugInInstanceClass); | |
78 | } | |
79 | ||
80 | CFTypeID CFPlugInInstanceGetTypeID(void) { | |
81 | return __kCFPlugInInstanceTypeID; | |
82 | } | |
83 | CF_EXPORT CFPlugInInstanceRef CFPlugInInstanceCreateWithInstanceDataSize(CFAllocatorRef allocator, CFIndex instanceDataSize, CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceFunction, CFStringRef factoryName, CFPlugInInstanceGetInterfaceFunction getInterfaceFunction) { | |
84 | CFPlugInInstanceRef instance; | |
85 | UInt32 size; | |
86 | size = sizeof(struct __CFPlugInInstance) + instanceDataSize - sizeof(CFRuntimeBase); | |
87 | instance = (CFPlugInInstanceRef)_CFRuntimeCreateInstance(allocator, __kCFPlugInInstanceTypeID, size, NULL); | |
88 | if (NULL == instance) { | |
89 | return NULL; | |
90 | } | |
91 | ||
92 | instance->factory = _CFPFactoryFind((CFUUIDRef)factoryName, true); | |
93 | if (instance->factory) { | |
94 | _CFPFactoryAddInstance(instance->factory); | |
95 | } | |
96 | instance->getInterfaceFunction = getInterfaceFunction; | |
97 | instance->deallocateInstanceDataFunction = deallocateInstanceFunction; | |
98 | ||
99 | return instance; | |
100 | } | |
101 | ||
102 | CF_EXPORT Boolean CFPlugInInstanceGetInterfaceFunctionTable(CFPlugInInstanceRef instance, CFStringRef interfaceName, void **ftbl) { | |
103 | void *myFtbl; | |
104 | Boolean result = false; | |
105 | ||
106 | if (instance->getInterfaceFunction) { | |
107 | FAULT_CALLBACK((void **)&(instance->getInterfaceFunction)); | |
108 | result = INVOKE_CALLBACK3(instance->getInterfaceFunction, instance, interfaceName, &myFtbl) ? true : false; | |
109 | } | |
110 | if (ftbl) { | |
111 | *ftbl = (result ? myFtbl : NULL); | |
112 | } | |
113 | return result; | |
114 | } | |
115 | ||
116 | CF_EXPORT CFStringRef CFPlugInInstanceGetFactoryName(CFPlugInInstanceRef instance) { | |
117 | return (CFStringRef)_CFPFactoryGetFactoryID(instance->factory); | |
118 | } | |
119 | ||
120 | CF_EXPORT void *CFPlugInInstanceGetInstanceData(CFPlugInInstanceRef instance) { | |
121 | return (void *)(&instance->_instanceData[0]); | |
122 | } | |
123 |