]> git.saurik.com Git - apple/security.git/blob - cdsa/cssm/module.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cssm / module.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 //
20 // module - CSSM Module objects
21 //
22 #ifndef _H_MODULE
23 #define _H_MODULE
24
25 #include "cssmint.h"
26 #include "cssmmds.h"
27 #include <Security/callback.h>
28 #include <Security/modloader.h>
29 #include <set>
30
31 #if __GNUC__ > 2
32 #include <ext/hash_map>
33 using __gnu_cxx::hash_map;
34 #else
35 #include <hash_map>
36 #endif
37
38
39 //
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
42 // represent it.
43 //
44 class Module : public MdsComponent {
45 NOCOPY(Module)
46 public:
47 Module(CssmManager *mgr, const MdsComponent &info, Plugin *plugin);
48 virtual ~Module();
49
50 CssmManager &cssm;
51
52 bool unload(const ModuleCallback &callback);
53
54 CSSM_HANDLE attach(const CSSM_VERSION &version,
55 uint32 subserviceId,
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);
63
64 void add(const ModuleCallback &cb) { callbackSet.insert(cb); }
65 void remove(const ModuleCallback &cb) { callbackSet.erase(cb); }
66
67 unsigned int callbackCount() const { return callbackSet.size(); }
68 unsigned int attachmentCount() const { return attachmentMap.size(); }
69
70 void safeLock() { if (!isThreadSafe()) mLock.lock(); }
71 void safeUnlock() { if (!isThreadSafe()) mLock.unlock(); }
72
73 public:
74 typedef hash_map<CSSM_HANDLE, Attachment *> AttachmentMap;
75
76 Plugin *plugin; // our loader module
77
78 private:
79 void spiEvent(CSSM_MODULE_EVENT event,
80 const Guid &guid,
81 uint32 subserviceId,
82 CSSM_SERVICE_TYPE serviceType);
83
84 static CSSM_RETURN spiEventRelay(const CSSM_GUID *ModuleGuid,
85 void *Context,
86 uint32 SubserviceId,
87 CSSM_SERVICE_TYPE ServiceType,
88 CSSM_MODULE_EVENT EventType);
89
90 private:
91 AttachmentMap attachmentMap; // map of all outstanding attachment handles
92 ModuleCallbackSet callbackSet; // set of registered callbacks
93
94 Mutex mLock;
95 };
96
97 #endif //_H_MODULE