]>
Commit | Line | Data |
---|---|---|
9ce05555 | 1 | /* |
8ca704e1 | 2 | * Copyright (c) 2011 Apple 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 | */ | |
f64f9b69 | 23 | |
9ce05555 | 24 | /* CFPlugIn_Instance.c |
8ca704e1 A |
25 | Copyright (c) 1999-2011, Apple Inc. All rights reserved. |
26 | Responsibility: David Smith | |
9ce05555 A |
27 | */ |
28 | ||
29 | #include "CFBundle_Internal.h" | |
30 | #include "CFInternal.h" | |
31 | ||
32 | static CFTypeID __kCFPlugInInstanceTypeID = _kCFRuntimeNotATypeID; | |
33 | ||
34 | struct __CFPlugInInstance { | |
35 | CFRuntimeBase _base; | |
36 | ||
37 | _CFPFactory *factory; | |
38 | ||
39 | CFPlugInInstanceGetInterfaceFunction getInterfaceFunction; | |
40 | CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceDataFunction; | |
bd5b749c A |
41 | |
42 | #ifdef _MSC_VER | |
43 | #pragma warning(push) | |
44 | #pragma warning(disable : 4200) | |
45 | #endif //_MSC_VER | |
9ce05555 | 46 | uint8_t _instanceData[0]; |
bd5b749c A |
47 | #ifdef _MSC_VER |
48 | #pragma warning(pop) | |
49 | #endif //_MSC_VER | |
9ce05555 A |
50 | }; |
51 | ||
52 | static CFStringRef __CFPlugInInstanceCopyDescription(CFTypeRef cf) { | |
53 | /* MF:!!! Implement me */ | |
54 | return CFSTR("Some CFPlugInInstance"); | |
55 | } | |
56 | ||
57 | static void __CFPlugInInstanceDeallocate(CFTypeRef cf) { | |
58 | CFPlugInInstanceRef instance = (CFPlugInInstanceRef)cf; | |
59 | ||
60 | __CFGenericValidateType(cf, __kCFPlugInInstanceTypeID); | |
61 | ||
62 | if (instance->deallocateInstanceDataFunction) { | |
63 | FAULT_CALLBACK((void **)&(instance->deallocateInstanceDataFunction)); | |
64 | (void)INVOKE_CALLBACK1(instance->deallocateInstanceDataFunction, (void *)(&instance->_instanceData[0])); | |
65 | } | |
66 | ||
cf7d2af9 | 67 | if (instance->factory) _CFPFactoryRemoveInstance(instance->factory); |
9ce05555 A |
68 | } |
69 | ||
70 | static const CFRuntimeClass __CFPlugInInstanceClass = { | |
71 | 0, | |
72 | "CFPlugInInstance", | |
73 | NULL, // init | |
74 | NULL, // copy | |
75 | __CFPlugInInstanceDeallocate, | |
76 | NULL, // equal | |
77 | NULL, // hash | |
78 | NULL, // | |
79 | __CFPlugInInstanceCopyDescription | |
80 | }; | |
81 | ||
82 | __private_extern__ void __CFPlugInInstanceInitialize(void) { | |
83 | __kCFPlugInInstanceTypeID = _CFRuntimeRegisterClass(&__CFPlugInInstanceClass); | |
84 | } | |
85 | ||
86 | CFTypeID CFPlugInInstanceGetTypeID(void) { | |
87 | return __kCFPlugInInstanceTypeID; | |
88 | } | |
cf7d2af9 | 89 | |
9ce05555 A |
90 | CF_EXPORT CFPlugInInstanceRef CFPlugInInstanceCreateWithInstanceDataSize(CFAllocatorRef allocator, CFIndex instanceDataSize, CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceFunction, CFStringRef factoryName, CFPlugInInstanceGetInterfaceFunction getInterfaceFunction) { |
91 | CFPlugInInstanceRef instance; | |
92 | UInt32 size; | |
93 | size = sizeof(struct __CFPlugInInstance) + instanceDataSize - sizeof(CFRuntimeBase); | |
94 | instance = (CFPlugInInstanceRef)_CFRuntimeCreateInstance(allocator, __kCFPlugInInstanceTypeID, size, NULL); | |
cf7d2af9 | 95 | if (!instance) return NULL; |
9ce05555 A |
96 | |
97 | instance->factory = _CFPFactoryFind((CFUUIDRef)factoryName, true); | |
cf7d2af9 | 98 | if (instance->factory) _CFPFactoryAddInstance(instance->factory); |
9ce05555 A |
99 | instance->getInterfaceFunction = getInterfaceFunction; |
100 | instance->deallocateInstanceDataFunction = deallocateInstanceFunction; | |
101 | ||
102 | return instance; | |
103 | } | |
104 | ||
105 | CF_EXPORT Boolean CFPlugInInstanceGetInterfaceFunctionTable(CFPlugInInstanceRef instance, CFStringRef interfaceName, void **ftbl) { | |
106 | void *myFtbl; | |
107 | Boolean result = false; | |
108 | ||
109 | if (instance->getInterfaceFunction) { | |
110 | FAULT_CALLBACK((void **)&(instance->getInterfaceFunction)); | |
111 | result = INVOKE_CALLBACK3(instance->getInterfaceFunction, instance, interfaceName, &myFtbl) ? true : false; | |
112 | } | |
cf7d2af9 | 113 | if (ftbl) *ftbl = (result ? myFtbl : NULL); |
9ce05555 A |
114 | return result; |
115 | } | |
116 | ||
117 | CF_EXPORT CFStringRef CFPlugInInstanceGetFactoryName(CFPlugInInstanceRef instance) { | |
118 | return (CFStringRef)_CFPFactoryGetFactoryID(instance->factory); | |
119 | } | |
120 | ||
121 | CF_EXPORT void *CFPlugInInstanceGetInstanceData(CFPlugInInstanceRef instance) { | |
122 | return (void *)(&instance->_instanceData[0]); | |
123 | } | |
124 |