dmlite 0.6
dmlite.h
Go to the documentation of this file.
1/// @file include/dmlite/cpp/dmlite.h
2/// @brief Entry point for DMLite.
3/// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4#ifndef DMLITE_CPP_DMLITE_H
5#define DMLITE_CPP_DMLITE_H
6
7#include "dmlite/common/config.h"
8#include "exceptions.h"
9
10#include <boost/any.hpp>
11#include <list>
12#include <map>
13#include <string>
14#include "utils/logger.h"
15
16/// Namespace for the dmlite C++ API
17namespace dmlite {
18
19 /// API Version.
20 const unsigned API_VERSION = 20121218;
21
22 // Forward declarations.
23 class Authn;
24 class AuthnFactory;
25 class BaseFactory;
26 class Catalog;
27 class CatalogFactory;
28 class INode;
29 class INodeFactory;
30 class IODriver;
31 class IODriverFactory;
32 class PoolDriver;
34 class PoolManager;
36 class SecurityContext;
38
39 class StackInstance;
40
41 /// CatalogInterface can only be instantiated through this class.
43 public:
44 /// Constructor
45 PluginManager() throw ();
46
47 /// Destructor
49
50 /// Load a plugin. Previously instantiated interfaces won't be affected.
51 /// @param lib The .so file. Usually, (path)/plugin_name.so.
52 /// @param id The plugin ID. Usually, plugin_name.
53 void loadPlugin(const std::string& lib,
54 const std::string& id) ;
55
56 /// Set a configuration parameter. It will be passed to the loaded plugins.
57 /// @param key The configuration parameter.
58 /// @param value The value for the configuration parameter.
59 void configure(const std::string& key,
60 const std::string& value) ;
61
62 /// Load a configuration file, with plugins and parameters.
63 /// @param file The configuration file.
64 void loadConfiguration(const std::string& file) ;
65
66 /// Return an entry from the loaded configuration.
67 /// @param key The configuration parameter.
68 std::string getConfiguration(const std::string& key) ;
69
70 /// Register a Authn factory. To be used by concrete implementations
71 /// @param factory The UserDbGroup concrete factory.
72 /// @note The same object can be passed to other register functions.
73 /// DMLite will take care of freeing it only once.
75
76 /// Register a INode factory. To be used by concrete implementations (i.e. Plugins)
77 /// @param factory The INode concrete factory.
78 /// @note The same object can be passed to other register functions.
79 /// DMLite will take care of freeing it only once.
81
82 /// Register a catalog factory. To be used by concrete implementations (i.e. Plugins)
83 /// @param factory The catalog concrete factory.
84 /// @note The same object can be passed to other register functions.
85 /// DMLite will take care of freeing it only once.
87
88 /// Register a pool factory.
89 /// @param factory The pool concrete factory.
90 /// @note The same object can be passed to other register functions.
91 /// DMLite will take care of freeing it only once.
93
94 /// Register a IODriver factory.
95 /// @param factory The IO concrete factory.
96 /// @note The same object can be passed to other register functions.
97 /// DMLite will take care of freeing it only once.
99
100 /// Register a PoolDriver factory.
101 /// @param factory The PoolDriver factory.
102 /// @note The same object can be passed to other register functions.
103 /// DMLite will take care of freeing it only once.
105
106 /// Register a bare BaseFactory. Only the configure method will be called.
107 /// @param factory The BaseFactory.
108 /// @note The same object can be passed to other register functions.
109 /// DMLite will take care of freeing it only once.
111
112 /// Get the AuthnFactory implementation on top of the plugin stack.
114
115 // Get the INodeFactory implementation on top of the plugin stack.
117
118 /// Get the CatalogFactory implementation on top of the plugin stack.
120
121 /// Get the PoolFactory implementation on top of the plugin stack.
123
124 /// Get the appropiate pool driver factory for the pool.
125 PoolDriverFactory* getPoolDriverFactory(const std::string& pooltype) ;
126
127 /// Get the IOFactory implementation on top of the plugin stack.
129
130 private:
131 /// Configuration key/value
132 std::map<std::string, std::string> confValues_;
133
134 /// Internal list of loaded plug-ins.
142
143 /// Keep pointers returned by dlopen at hand to free on destruction
144 std::list<void*> dlHandles_;
145
146 /// Can not be copied
148 };
149
150 extern Logger::bitmask stackinstancelogmask;
151 extern Logger::component stackinstancelogname;
152
153 /// We need to have something that allows one plugin stack to access
154 /// another plugin stack, so this represents a instantiation
155 /// of each plugin stack.
156 /// It also keeps common state: user credentials, security context,
157 /// and run-time parameters (see set)
158 /// @note Assume a StackInstance (and every instantiated interface under it)
159 /// is NOT thread-safe. This means, a StackInstance must be used by only
160 /// one thread at the same time.
162 public:
163 /// Constructor.
165
166 /// Destructor.
168
169 /// Set a key-value pair associated with this context.
170 /// This can be used to pass advanced parameters to and from the plugins.
171 /// @param key The key.
172 /// @param value The value.
173 void set(const std::string& key, const boost::any& value) ;
174
175 /// Get a value associated to a key.
176 /// This can be used to pass advanced parameters to and from the plugins.
177 /// @param key The key parameter.
178 boost::any get(const std::string& key) const ;
179
180 /// Erase a key,value pair from.
181 /// @param key The key of the pair to be erased.
182 void erase(const std::string& key) ;
183
184 /// Erase all the values set previously.
185 void eraseAll(void) throw ();
186
187 /// Checks if the stack instance contains a value associated with
188 /// the given key.
189 bool contains(const std::string& key) throw ();
190
191 /// Get the plugin manager.
193
194 /// Set the security credentials.
196
197 /// Set the security context.
199
200 /// Return the security context.
202
203 /// Get the UsersDb interface.
205
206 /// Get the INode.
208
209 /// Get the catalog.
211
212 // Check if there is a PoolManager available
213 bool isTherePoolManager() throw ();
214
215 /// Get the PoolManager.
216 PoolManager* getPoolManager() ;
217
218 /// Get a pool driver.
219 PoolDriver* getPoolDriver(const std::string& poolType) ;
220
221 /// Get the IO driver.
222 IODriver* getIODriver() ;
223
224 private:
225 PluginManager* pluginManager_;
226
227 Authn* authn_;
228 INode* inode_;
229 Catalog* catalog_;
230 PoolManager* poolManager_;
231 IODriver* ioDriver_;
232
234
235 std::map<std::string, PoolDriver*> poolDrivers_;
236
237 std::map<std::string, boost::any> stackMsg_;
238
239 void setSecurityContextImpl_(void);
240 };
241
242 /// Joint between plugins and plugin-manager
244 public:
245 /// Used to make sure API is consistent.
246 unsigned ApiVersion;
247 /// Let the plug-in register itself and its concrete factories
248 void (*registerPlugin)(PluginManager* pm) ;
249
250 };
251
252 /// Macro intended to allow future expansions of the PluginIdCard header
253 /// easily.
254 #define PLUGIN_ID_HEADER dmlite::API_VERSION
255
256};
257
258#endif // DMLITE_CPP_DMLITE_H
Definition logger.h:75
AuthnFactory.
Definition authn.h:217
Definition authn.h:127
Base class for factories.
Definition base.h:48
Plug-ins must implement a concrete factory to be instantiated.
Definition catalog.h:237
Interface for Catalog (Namespaces).
Definition catalog.h:30
INodeFactory.
Definition inode.h:292
Definition inode.h:113
Plug-ins must implement a concrete factory to be instantiated.
Definition io.h:153
IO Driver.
Definition io.h:111
Joint between plugins and plugin-manager.
Definition dmlite.h:243
unsigned ApiVersion
Used to make sure API is consistent.
Definition dmlite.h:246
CatalogInterface can only be instantiated through this class.
Definition dmlite.h:42
std::list< IODriverFactory * > io_plugins_
Definition dmlite.h:139
PoolDriverFactory * getPoolDriverFactory(const std::string &pooltype)
Get the appropiate pool driver factory for the pool.
void configure(const std::string &key, const std::string &value)
CatalogFactory * getCatalogFactory()
Get the CatalogFactory implementation on top of the plugin stack.
void registerINodeFactory(INodeFactory *factory)
void registerCatalogFactory(CatalogFactory *factory)
std::string getConfiguration(const std::string &key)
void registerConfigureFactory(BaseFactory *factory)
std::list< void * > dlHandles_
Keep pointers returned by dlopen at hand to free on destruction.
Definition dmlite.h:144
INodeFactory * getINodeFactory()
AuthnFactory * getAuthnFactory()
Get the AuthnFactory implementation on top of the plugin stack.
std::list< PoolManagerFactory * > pool_plugins_
Definition dmlite.h:138
void loadPlugin(const std::string &lib, const std::string &id)
PoolManagerFactory * getPoolManagerFactory()
Get the PoolFactory implementation on top of the plugin stack.
void loadConfiguration(const std::string &file)
std::map< std::string, std::string > confValues_
Configuration key/value.
Definition dmlite.h:132
std::list< INodeFactory * > inode_plugins_
Definition dmlite.h:136
std::list< AuthnFactory * > authn_plugins_
Internal list of loaded plug-ins.
Definition dmlite.h:135
IODriverFactory * getIODriverFactory()
Get the IOFactory implementation on top of the plugin stack.
std::list< PoolDriverFactory * > pool_driver_plugins_
Definition dmlite.h:140
std::list< BaseFactory * > configure_factory_
Definition dmlite.h:141
PluginManager()
Constructor.
void registerAuthnFactory(AuthnFactory *factory)
void registerPoolDriverFactory(PoolDriverFactory *factory)
void registerIODriverFactory(IODriverFactory *factory)
std::list< CatalogFactory * > catalog_plugins_
Definition dmlite.h:137
void registerPoolManagerFactory(PoolManagerFactory *factory)
PoolDriver factory.
Definition pooldriver.h:126
Interface for a pool driver.
Definition pooldriver.h:101
Plug-ins must implement a concrete factory to be instantiated.
Definition poolmanager.h:109
Interface for pool types.
Definition poolmanager.h:41
Security context. To be created by the Authn.
Definition authn.h:73
Security credentials. To be filled by the front-end.
Definition authn.h:23
Definition dmlite.h:161
void eraseAll(void)
Erase all the values set previously.
const SecurityContext * getSecurityContext(void) const
Return the security context.
boost::any get(const std::string &key) const
bool contains(const std::string &key)
void erase(const std::string &key)
void setSecurityCredentials(const SecurityCredentials &cred)
Set the security credentials.
~StackInstance()
Destructor.
Catalog * getCatalog()
Get the catalog.
StackInstance(PluginManager *pm)
Constructor.
Authn * getAuthn()
Get the UsersDb interface.
PluginManager * getPluginManager()
Get the plugin manager.
void set(const std::string &key, const boost::any &value)
void setSecurityContext(const SecurityContext &ctx)
Set the security context.
INode * getINode()
Get the INode.
Exceptions used by the API.
Namespace for the dmlite C++ API.
Definition authn.h:16
const unsigned API_VERSION
API Version.
Definition dmlite.h:20
Logger::bitmask stackinstancelogmask
Logger::component stackinstancelogname