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@
26 Copyright 1999-2002, Apple, Inc. All rights reserved.
27 Responsibility: Doug Davidson
30 #include "CFBundle_Internal.h"
31 #include "CFInternal.h"
33 CONST_STRING_DECL(kCFPlugInDynamicRegistrationKey
, "CFPlugInDynamicRegistration")
34 CONST_STRING_DECL(kCFPlugInDynamicRegisterFunctionKey
, "CFPlugInDynamicRegisterFunction")
35 CONST_STRING_DECL(kCFPlugInUnloadFunctionKey
, "CFPlugInUnloadFunction")
36 CONST_STRING_DECL(kCFPlugInFactoriesKey
, "CFPlugInFactories")
37 CONST_STRING_DECL(kCFPlugInTypesKey
, "CFPlugInTypes")
39 __private_extern__
void __CFPlugInInitialize(void) {
42 /* ===================== Finding factories and creating instances ===================== */
43 /* For plugIn hosts. */
44 /* Functions for finding factories to create specific types and actually creating instances of a type. */
46 CF_EXPORT CFArrayRef
CFPlugInFindFactoriesForPlugInType(CFUUIDRef typeID
) {
47 CFArrayRef array
= _CFPFactoryFindForType(typeID
);
48 CFMutableArrayRef result
= NULL
;
51 SInt32 i
, c
= CFArrayGetCount(array
);
53 // Use default allocator
54 result
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
57 CFArrayAppendValue(result
, _CFPFactoryGetFactoryID((_CFPFactory
*)CFArrayGetValueAtIndex(array
, i
)));
63 CF_EXPORT CFArrayRef
CFPlugInFindFactoriesForPlugInTypeInPlugIn(CFUUIDRef typeID
, CFPlugInRef plugIn
) {
64 CFArrayRef array
= _CFPFactoryFindForType(typeID
);
65 CFMutableArrayRef result
= NULL
;
68 SInt32 i
, c
= CFArrayGetCount(array
);
71 // Use default allocator
72 result
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
75 factory
= (_CFPFactory
*)CFArrayGetValueAtIndex(array
, i
);
76 if (_CFPFactoryGetPlugIn(factory
) == plugIn
) {
77 CFArrayAppendValue(result
, _CFPFactoryGetFactoryID(factory
));
84 CF_EXPORT
void *CFPlugInInstanceCreate(CFAllocatorRef allocator
, CFUUIDRef factoryID
, CFUUIDRef typeID
) {
85 _CFPFactory
*factory
= _CFPFactoryFind(factoryID
, true);
88 /* MF:!!! No such factory. */
89 CFLog(__kCFLogPlugIn
, CFSTR("Cannot find factory %@"), factoryID
);
91 if (!_CFPFactorySupportsType(factory
, typeID
)) {
92 /* MF:!!! Factory does not support type. */
93 CFLog(__kCFLogPlugIn
, CFSTR("Factory %@ does not support type %@"), factoryID
, typeID
);
95 result
= _CFPFactoryCreateInstance(allocator
, factory
, typeID
);
101 /* ===================== Registering factories and types ===================== */
102 /* For plugIn writers who must dynamically register things. */
103 /* Functions to register factory functions and to associate factories with types. */
105 CF_EXPORT Boolean
CFPlugInRegisterFactoryFunction(CFUUIDRef factoryID
, CFPlugInFactoryFunction func
) {
106 // Create factories without plugIns from default allocator
107 // MF:!!! Should probably check that this worked, and maybe do some pre-checking to see if it already exists
108 // _CFPFactory *factory =
109 (void)_CFPFactoryCreate(NULL
, factoryID
, func
);
113 CF_EXPORT Boolean
CFPlugInRegisterFactoryFunctionByName(CFUUIDRef factoryID
, CFPlugInRef plugIn
, CFStringRef functionName
) {
114 // Create factories with plugIns from plugIn's allocator
115 // MF:!!! Should probably check that this worked, and maybe do some pre-checking to see if it already exists
116 // _CFPFactory *factory =
117 (void)_CFPFactoryCreateByName(CFGetAllocator(plugIn
), factoryID
, plugIn
, functionName
);
121 CF_EXPORT Boolean
CFPlugInUnregisterFactory(CFUUIDRef factoryID
) {
122 _CFPFactory
*factory
= _CFPFactoryFind(factoryID
, true);
125 /* MF:!!! Error. No factory registered for this ID. */
127 _CFPFactoryDisable(factory
);
132 CF_EXPORT Boolean
CFPlugInRegisterPlugInType(CFUUIDRef factoryID
, CFUUIDRef typeID
) {
133 _CFPFactory
*factory
= _CFPFactoryFind(factoryID
, true);
136 /* MF:!!! Error. Factory must be registered (and not disabled) before types can be associated with it. */
138 _CFPFactoryAddType(factory
, typeID
);
143 CF_EXPORT Boolean
CFPlugInUnregisterPlugInType(CFUUIDRef factoryID
, CFUUIDRef typeID
) {
144 _CFPFactory
*factory
= _CFPFactoryFind(factoryID
, true);
147 /* MF:!!! Error. Could not find factory. */
149 _CFPFactoryRemoveType(factory
, typeID
);
155 /* ================= Registering instances ================= */
156 /* When a new instance of a type is created, the instance is responsible for registering itself with the factory that created it and unregistering when it deallocates. */
157 /* This means that an instance must keep track of the CFUUIDRef of the factory that created it so it can unregister when it goes away. */
159 CF_EXPORT
void CFPlugInAddInstanceForFactory(CFUUIDRef factoryID
) {
160 _CFPFactory
*factory
= _CFPFactoryFind(factoryID
, true);
163 /* MF:!!! Error. Could not find factory. */
165 _CFPFactoryAddInstance(factory
);
169 CF_EXPORT
void CFPlugInRemoveInstanceForFactory(CFUUIDRef factoryID
) {
170 _CFPFactory
*factory
= _CFPFactoryFind(factoryID
, true);
173 /* MF:!!! Error. Could not find factory. */
175 _CFPFactoryRemoveInstance(factory
);