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>
32 #include <ext/hash_map>
33 using __gnu_cxx::hash_map
;
40 // This type represents a loaded plugin module of some kind. For each CssmManager
41 // instance and each one plugin, there is only (at most) one Module object to
44 class Module
: public MdsComponent
{
47 Module(CssmManager
*mgr
, const MdsComponent
&info
, Plugin
*plugin
);
52 bool unload(const ModuleCallback
&callback
);
54 CSSM_HANDLE
attach(const CSSM_VERSION
&version
,
56 CSSM_SERVICE_TYPE subserviceType
,
57 const CSSM_API_MEMORY_FUNCS
&memoryOps
,
58 CSSM_ATTACH_FLAGS attachFlags
,
59 CSSM_KEY_HIERARCHY keyHierarchy
,
60 CSSM_FUNC_NAME_ADDR
*functionTable
,
61 uint32 functionTableSize
);
62 void detach(Attachment
*attachment
);
64 void add(const ModuleCallback
&cb
) { callbackSet
.insert(cb
); }
65 void remove(const ModuleCallback
&cb
) { callbackSet
.erase(cb
); }
67 unsigned int callbackCount() const { return callbackSet
.size(); }
68 unsigned int attachmentCount() const { return attachmentMap
.size(); }
70 void safeLock() { if (!isThreadSafe()) mLock
.lock(); }
71 void safeUnlock() { if (!isThreadSafe()) mLock
.unlock(); }
74 typedef hash_map
<CSSM_HANDLE
, Attachment
*> AttachmentMap
;
76 Plugin
*plugin
; // our loader module
79 void spiEvent(CSSM_MODULE_EVENT event
,
82 CSSM_SERVICE_TYPE serviceType
);
84 static CSSM_RETURN
spiEventRelay(const CSSM_GUID
*ModuleGuid
,
87 CSSM_SERVICE_TYPE ServiceType
,
88 CSSM_MODULE_EVENT EventType
);
91 AttachmentMap attachmentMap
; // map of all outstanding attachment handles
92 ModuleCallbackSet callbackSet
; // set of registered callbacks