]> git.saurik.com Git - apple/security.git/blob - libsecurity_cssm/lib/modloader.h
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_cssm / lib / modloader.h
1 /*
2 * Copyright (c) 2000-2001,2003-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // modloader.h - CSSM module loader interface
27 //
28 // This is a thin abstraction of plugin module loading/handling for CSSM.
29 // The resulting module ("Plugin") notion is specific to CSSM plugin modules.
30 // This implementation uses MacOS X bundles.
31 //
32 #ifndef _H_MODLOADER
33 #define _H_MODLOADER
34
35 #include <exception>
36 #include <security_utilities/osxcode.h>
37 #include "cssmint.h"
38 #include <map>
39 #include <string>
40
41
42 namespace Security {
43
44
45 //
46 // A collection of canonical plugin entry points (aka CSSM module SPI)
47 //
48 struct PluginFunctions {
49 CSSM_SPI_ModuleLoadFunction *load;
50 CSSM_SPI_ModuleUnloadFunction *unload;
51 CSSM_SPI_ModuleAttachFunction *attach;
52 CSSM_SPI_ModuleDetachFunction *detach;
53 };
54
55
56 //
57 // An abstract representation of a loadable plugin.
58 // Note that "loadable" doesn't mean that actual code loading
59 // is necessarily happening, but let's just assume it might.
60 //
61 class Plugin {
62 NOCOPY(Plugin)
63 public:
64 Plugin() { }
65 virtual ~Plugin() { }
66
67 virtual void load() = 0;
68 virtual void unload() = 0;
69 virtual bool isLoaded() const = 0;
70
71 virtual CSSM_SPI_ModuleLoadFunction load = 0;
72 virtual CSSM_SPI_ModuleUnloadFunction unload = 0;
73 virtual CSSM_SPI_ModuleAttachFunction attach = 0;
74 virtual CSSM_SPI_ModuleDetachFunction detach = 0;
75 };
76
77
78 //
79 // The supervisor class that manages searching and loading.
80 //
81 class ModuleLoader {
82 NOCOPY(ModuleLoader)
83 public:
84 ModuleLoader();
85
86 Plugin *operator () (const string &path);
87
88 private:
89 // the table of all loaded modules
90 typedef map<string, Plugin *> PluginTable;
91 PluginTable mPlugins;
92 };
93
94
95
96 } // end namespace Security
97
98
99 #endif //_H_MODLOADER