2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* CFPlugIn_Instance.c
26 Copyright 1999-2002, Apple, Inc. All rights reserved.
27 Responsibility: Doug Davidson
30 #include "CFBundle_Internal.h"
31 #include "CFInternal.h"
33 static CFTypeID __kCFPlugInInstanceTypeID
= _kCFRuntimeNotATypeID
;
35 struct __CFPlugInInstance
{
40 CFPlugInInstanceGetInterfaceFunction getInterfaceFunction
;
41 CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceDataFunction
;
43 uint8_t _instanceData
[0];
46 static CFStringRef
__CFPlugInInstanceCopyDescription(CFTypeRef cf
) {
47 /* MF:!!! Implement me */
48 return CFSTR("Some CFPlugInInstance");
51 static void __CFPlugInInstanceDeallocate(CFTypeRef cf
) {
52 CFPlugInInstanceRef instance
= (CFPlugInInstanceRef
)cf
;
54 __CFGenericValidateType(cf
, __kCFPlugInInstanceTypeID
);
56 if (instance
->deallocateInstanceDataFunction
) {
57 FAULT_CALLBACK((void **)&(instance
->deallocateInstanceDataFunction
));
58 (void)INVOKE_CALLBACK1(instance
->deallocateInstanceDataFunction
, (void *)(&instance
->_instanceData
[0]));
61 if (instance
->factory
) {
62 _CFPFactoryRemoveInstance(instance
->factory
);
66 static const CFRuntimeClass __CFPlugInInstanceClass
= {
71 __CFPlugInInstanceDeallocate
,
75 __CFPlugInInstanceCopyDescription
78 __private_extern__
void __CFPlugInInstanceInitialize(void) {
79 __kCFPlugInInstanceTypeID
= _CFRuntimeRegisterClass(&__CFPlugInInstanceClass
);
82 CFTypeID
CFPlugInInstanceGetTypeID(void) {
83 return __kCFPlugInInstanceTypeID
;
85 CF_EXPORT CFPlugInInstanceRef
CFPlugInInstanceCreateWithInstanceDataSize(CFAllocatorRef allocator
, CFIndex instanceDataSize
, CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceFunction
, CFStringRef factoryName
, CFPlugInInstanceGetInterfaceFunction getInterfaceFunction
) {
86 CFPlugInInstanceRef instance
;
88 size
= sizeof(struct __CFPlugInInstance
) + instanceDataSize
- sizeof(CFRuntimeBase
);
89 instance
= (CFPlugInInstanceRef
)_CFRuntimeCreateInstance(allocator
, __kCFPlugInInstanceTypeID
, size
, NULL
);
90 if (NULL
== instance
) {
94 instance
->factory
= _CFPFactoryFind((CFUUIDRef
)factoryName
, true);
95 if (instance
->factory
) {
96 _CFPFactoryAddInstance(instance
->factory
);
98 instance
->getInterfaceFunction
= getInterfaceFunction
;
99 instance
->deallocateInstanceDataFunction
= deallocateInstanceFunction
;
104 CF_EXPORT Boolean
CFPlugInInstanceGetInterfaceFunctionTable(CFPlugInInstanceRef instance
, CFStringRef interfaceName
, void **ftbl
) {
106 Boolean result
= false;
108 if (instance
->getInterfaceFunction
) {
109 FAULT_CALLBACK((void **)&(instance
->getInterfaceFunction
));
110 result
= INVOKE_CALLBACK3(instance
->getInterfaceFunction
, instance
, interfaceName
, &myFtbl
) ? true : false;
113 *ftbl
= (result
? myFtbl
: NULL
);
118 CF_EXPORT CFStringRef
CFPlugInInstanceGetFactoryName(CFPlugInInstanceRef instance
) {
119 return (CFStringRef
)_CFPFactoryGetFactoryID(instance
->factory
);
122 CF_EXPORT
void *CFPlugInInstanceGetInstanceData(CFPlugInInstanceRef instance
) {
123 return (void *)(&instance
->_instanceData
[0]);