]> git.saurik.com Git - apple/cf.git/blob - CFPlugIn_Instance.c
CF-476.10.tar.gz
[apple/cf.git] / CFPlugIn_Instance.c
1 /*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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 (c) 1999-2007 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 #ifdef _MSC_VER
42 #pragma warning(push)
43 #pragma warning(disable : 4200)
44 #endif //_MSC_VER
45 uint8_t _instanceData[0];
46 #ifdef _MSC_VER
47 #pragma warning(pop)
48 #endif //_MSC_VER
49 };
50
51 static CFStringRef __CFPlugInInstanceCopyDescription(CFTypeRef cf) {
52 /* MF:!!! Implement me */
53 return CFSTR("Some CFPlugInInstance");
54 }
55
56 static void __CFPlugInInstanceDeallocate(CFTypeRef cf) {
57 CFPlugInInstanceRef instance = (CFPlugInInstanceRef)cf;
58
59 __CFGenericValidateType(cf, __kCFPlugInInstanceTypeID);
60
61 if (instance->deallocateInstanceDataFunction) {
62 FAULT_CALLBACK((void **)&(instance->deallocateInstanceDataFunction));
63 (void)INVOKE_CALLBACK1(instance->deallocateInstanceDataFunction, (void *)(&instance->_instanceData[0]));
64 }
65
66 if (instance->factory) {
67 _CFPFactoryRemoveInstance(instance->factory);
68 }
69 }
70
71 static const CFRuntimeClass __CFPlugInInstanceClass = {
72 0,
73 "CFPlugInInstance",
74 NULL, // init
75 NULL, // copy
76 __CFPlugInInstanceDeallocate,
77 NULL, // equal
78 NULL, // hash
79 NULL, //
80 __CFPlugInInstanceCopyDescription
81 };
82
83 __private_extern__ void __CFPlugInInstanceInitialize(void) {
84 __kCFPlugInInstanceTypeID = _CFRuntimeRegisterClass(&__CFPlugInInstanceClass);
85 }
86
87 CFTypeID CFPlugInInstanceGetTypeID(void) {
88 return __kCFPlugInInstanceTypeID;
89 }
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);
95 if (NULL == instance) {
96 return NULL;
97 }
98
99 instance->factory = _CFPFactoryFind((CFUUIDRef)factoryName, true);
100 if (instance->factory) {
101 _CFPFactoryAddInstance(instance->factory);
102 }
103 instance->getInterfaceFunction = getInterfaceFunction;
104 instance->deallocateInstanceDataFunction = deallocateInstanceFunction;
105
106 return instance;
107 }
108
109 CF_EXPORT Boolean CFPlugInInstanceGetInterfaceFunctionTable(CFPlugInInstanceRef instance, CFStringRef interfaceName, void **ftbl) {
110 void *myFtbl;
111 Boolean result = false;
112
113 if (instance->getInterfaceFunction) {
114 FAULT_CALLBACK((void **)&(instance->getInterfaceFunction));
115 result = INVOKE_CALLBACK3(instance->getInterfaceFunction, instance, interfaceName, &myFtbl) ? true : false;
116 }
117 if (ftbl) {
118 *ftbl = (result ? myFtbl : NULL);
119 }
120 return result;
121 }
122
123 CF_EXPORT CFStringRef CFPlugInInstanceGetFactoryName(CFPlugInInstanceRef instance) {
124 return (CFStringRef)_CFPFactoryGetFactoryID(instance->factory);
125 }
126
127 CF_EXPORT void *CFPlugInInstanceGetInstanceData(CFPlugInInstanceRef instance) {
128 return (void *)(&instance->_instanceData[0]);
129 }
130