2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // module - CSSM Module objects
27 #include <Security/callback.h>
28 #include <Security/modloader.h>
34 // This type represents a loaded plugin module of some kind. For each CssmManager
35 // instance and each one plugin, there is only (at most) one Module object to
38 class Module
: public MdsComponent
{
41 Module(CssmManager
*mgr
, const MdsComponent
&info
, Plugin
*plugin
);
46 bool unload(const ModuleCallback
&callback
);
48 CSSM_HANDLE
attach(const CSSM_VERSION
&version
,
50 CSSM_SERVICE_TYPE subserviceType
,
51 const CSSM_API_MEMORY_FUNCS
&memoryOps
,
52 CSSM_ATTACH_FLAGS attachFlags
,
53 CSSM_KEY_HIERARCHY keyHierarchy
,
54 CSSM_FUNC_NAME_ADDR
*functionTable
,
55 uint32 functionTableSize
);
56 void detach(Attachment
*attachment
);
58 void add(const ModuleCallback
&cb
) { callbackSet
.insert(cb
); }
59 void remove(const ModuleCallback
&cb
) { callbackSet
.erase(cb
); }
61 unsigned int callbackCount() const { return callbackSet
.size(); }
62 unsigned int attachmentCount() const { return attachmentMap
.size(); }
64 void safeLock() { if (!isThreadSafe()) mLock
.lock(); }
65 void safeUnlock() { if (!isThreadSafe()) mLock
.unlock(); }
68 typedef hash_map
<CSSM_HANDLE
, Attachment
*> AttachmentMap
;
70 Plugin
*plugin
; // our loader module
73 void spiEvent(CSSM_MODULE_EVENT event
,
76 CSSM_SERVICE_TYPE serviceType
);
78 static CSSM_RETURN
spiEventRelay(const CSSM_GUID
*ModuleGuid
,
81 CSSM_SERVICE_TYPE ServiceType
,
82 CSSM_MODULE_EVENT EventType
);
85 AttachmentMap attachmentMap
; // map of all outstanding attachment handles
86 ModuleCallbackSet callbackSet
; // set of registered callbacks