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