]> git.saurik.com Git - apple/security.git/blob - cdsa/cssm/module.h
Security-28.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 <hash_map>
30 #include <set>
31
32
33 //
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
36 // represent it.
37 //
38 class Module : public MdsComponent {
39 NOCOPY(Module)
40 public:
41 Module(CssmManager *mgr, const MdsComponent &info, Plugin *plugin);
42 virtual ~Module();
43
44 CssmManager &cssm;
45
46 bool unload(const ModuleCallback &callback);
47
48 CSSM_HANDLE attach(const CSSM_VERSION &version,
49 uint32 subserviceId,
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);
57
58 void add(const ModuleCallback &cb) { callbackSet.insert(cb); }
59 void remove(const ModuleCallback &cb) { callbackSet.erase(cb); }
60
61 unsigned int callbackCount() const { return callbackSet.size(); }
62 unsigned int attachmentCount() const { return attachmentMap.size(); }
63
64 void safeLock() { if (!isThreadSafe()) mLock.lock(); }
65 void safeUnlock() { if (!isThreadSafe()) mLock.unlock(); }
66
67 public:
68 typedef hash_map<CSSM_HANDLE, Attachment *> AttachmentMap;
69
70 Plugin *plugin; // our loader module
71
72 private:
73 void spiEvent(CSSM_MODULE_EVENT event,
74 const Guid &guid,
75 uint32 subserviceId,
76 CSSM_SERVICE_TYPE serviceType);
77
78 static CSSM_RETURN spiEventRelay(const CSSM_GUID *ModuleGuid,
79 void *Context,
80 uint32 SubserviceId,
81 CSSM_SERVICE_TYPE ServiceType,
82 CSSM_MODULE_EVENT EventType);
83
84 private:
85 AttachmentMap attachmentMap; // map of all outstanding attachment handles
86 ModuleCallbackSet callbackSet; // set of registered callbacks
87
88 Mutex mLock;
89 };
90
91 #endif //_H_MODULE