2 * Copyright (c) 2005 Apple Computer, 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 1999-2002, 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
;
41 uint8_t _instanceData
[0];
44 static CFStringRef
__CFPlugInInstanceCopyDescription(CFTypeRef cf
) {
45 /* MF:!!! Implement me */
46 return CFSTR("Some CFPlugInInstance");
49 static void __CFPlugInInstanceDeallocate(CFTypeRef cf
) {
50 CFPlugInInstanceRef instance
= (CFPlugInInstanceRef
)cf
;
52 __CFGenericValidateType(cf
, __kCFPlugInInstanceTypeID
);
54 if (instance
->deallocateInstanceDataFunction
) {
55 FAULT_CALLBACK((void **)&(instance
->deallocateInstanceDataFunction
));
56 (void)INVOKE_CALLBACK1(instance
->deallocateInstanceDataFunction
, (void *)(&instance
->_instanceData
[0]));
59 if (instance
->factory
) {
60 _CFPFactoryRemoveInstance(instance
->factory
);
64 static const CFRuntimeClass __CFPlugInInstanceClass
= {
69 __CFPlugInInstanceDeallocate
,
73 __CFPlugInInstanceCopyDescription
76 __private_extern__
void __CFPlugInInstanceInitialize(void) {
77 __kCFPlugInInstanceTypeID
= _CFRuntimeRegisterClass(&__CFPlugInInstanceClass
);
80 CFTypeID
CFPlugInInstanceGetTypeID(void) {
81 return __kCFPlugInInstanceTypeID
;
83 CF_EXPORT CFPlugInInstanceRef
CFPlugInInstanceCreateWithInstanceDataSize(CFAllocatorRef allocator
, CFIndex instanceDataSize
, CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceFunction
, CFStringRef factoryName
, CFPlugInInstanceGetInterfaceFunction getInterfaceFunction
) {
84 CFPlugInInstanceRef instance
;
86 size
= sizeof(struct __CFPlugInInstance
) + instanceDataSize
- sizeof(CFRuntimeBase
);
87 instance
= (CFPlugInInstanceRef
)_CFRuntimeCreateInstance(allocator
, __kCFPlugInInstanceTypeID
, size
, NULL
);
88 if (NULL
== instance
) {
92 instance
->factory
= _CFPFactoryFind((CFUUIDRef
)factoryName
, true);
93 if (instance
->factory
) {
94 _CFPFactoryAddInstance(instance
->factory
);
96 instance
->getInterfaceFunction
= getInterfaceFunction
;
97 instance
->deallocateInstanceDataFunction
= deallocateInstanceFunction
;
102 CF_EXPORT Boolean
CFPlugInInstanceGetInterfaceFunctionTable(CFPlugInInstanceRef instance
, CFStringRef interfaceName
, void **ftbl
) {
104 Boolean result
= false;
106 if (instance
->getInterfaceFunction
) {
107 FAULT_CALLBACK((void **)&(instance
->getInterfaceFunction
));
108 result
= INVOKE_CALLBACK3(instance
->getInterfaceFunction
, instance
, interfaceName
, &myFtbl
) ? true : false;
111 *ftbl
= (result
? myFtbl
: NULL
);
116 CF_EXPORT CFStringRef
CFPlugInInstanceGetFactoryName(CFPlugInInstanceRef instance
) {
117 return (CFStringRef
)_CFPFactoryGetFactoryID(instance
->factory
);
120 CF_EXPORT
void *CFPlugInInstanceGetInstanceData(CFPlugInInstanceRef instance
) {
121 return (void *)(&instance
->_instanceData
[0]);