2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 /* CFPlugIn_Instance.c
24 Copyright (c) 1999-2007 Apple Inc. All rights reserved.
25 Responsibility: Doug Davidson
28 #include "CFBundle_Internal.h"
29 #include "CFInternal.h"
31 static CFTypeID __kCFPlugInInstanceTypeID
= _kCFRuntimeNotATypeID
;
33 struct __CFPlugInInstance
{
38 CFPlugInInstanceGetInterfaceFunction getInterfaceFunction
;
39 CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceDataFunction
;
43 #pragma warning(disable : 4200)
45 uint8_t _instanceData
[0];
51 static CFStringRef
__CFPlugInInstanceCopyDescription(CFTypeRef cf
) {
52 /* MF:!!! Implement me */
53 return CFSTR("Some CFPlugInInstance");
56 static void __CFPlugInInstanceDeallocate(CFTypeRef cf
) {
57 CFPlugInInstanceRef instance
= (CFPlugInInstanceRef
)cf
;
59 __CFGenericValidateType(cf
, __kCFPlugInInstanceTypeID
);
61 if (instance
->deallocateInstanceDataFunction
) {
62 FAULT_CALLBACK((void **)&(instance
->deallocateInstanceDataFunction
));
63 (void)INVOKE_CALLBACK1(instance
->deallocateInstanceDataFunction
, (void *)(&instance
->_instanceData
[0]));
66 if (instance
->factory
) {
67 _CFPFactoryRemoveInstance(instance
->factory
);
71 static const CFRuntimeClass __CFPlugInInstanceClass
= {
76 __CFPlugInInstanceDeallocate
,
80 __CFPlugInInstanceCopyDescription
83 __private_extern__
void __CFPlugInInstanceInitialize(void) {
84 __kCFPlugInInstanceTypeID
= _CFRuntimeRegisterClass(&__CFPlugInInstanceClass
);
87 CFTypeID
CFPlugInInstanceGetTypeID(void) {
88 return __kCFPlugInInstanceTypeID
;
90 CF_EXPORT CFPlugInInstanceRef
CFPlugInInstanceCreateWithInstanceDataSize(CFAllocatorRef allocator
, CFIndex instanceDataSize
, CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceFunction
, CFStringRef factoryName
, CFPlugInInstanceGetInterfaceFunction getInterfaceFunction
) {
91 CFPlugInInstanceRef instance
;
93 size
= sizeof(struct __CFPlugInInstance
) + instanceDataSize
- sizeof(CFRuntimeBase
);
94 instance
= (CFPlugInInstanceRef
)_CFRuntimeCreateInstance(allocator
, __kCFPlugInInstanceTypeID
, size
, NULL
);
95 if (NULL
== instance
) {
99 instance
->factory
= _CFPFactoryFind((CFUUIDRef
)factoryName
, true);
100 if (instance
->factory
) {
101 _CFPFactoryAddInstance(instance
->factory
);
103 instance
->getInterfaceFunction
= getInterfaceFunction
;
104 instance
->deallocateInstanceDataFunction
= deallocateInstanceFunction
;
109 CF_EXPORT Boolean
CFPlugInInstanceGetInterfaceFunctionTable(CFPlugInInstanceRef instance
, CFStringRef interfaceName
, void **ftbl
) {
111 Boolean result
= false;
113 if (instance
->getInterfaceFunction
) {
114 FAULT_CALLBACK((void **)&(instance
->getInterfaceFunction
));
115 result
= INVOKE_CALLBACK3(instance
->getInterfaceFunction
, instance
, interfaceName
, &myFtbl
) ? true : false;
118 *ftbl
= (result
? myFtbl
: NULL
);
123 CF_EXPORT CFStringRef
CFPlugInInstanceGetFactoryName(CFPlugInInstanceRef instance
) {
124 return (CFStringRef
)_CFPFactoryGetFactoryID(instance
->factory
);
127 CF_EXPORT
void *CFPlugInInstanceGetInstanceData(CFPlugInInstanceRef instance
) {
128 return (void *)(&instance
->_instanceData
[0]);