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
17 namespace 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;
33  class PoolDriverFactory;
34  class PoolManager;
35  class PoolManagerFactory;
36  class SecurityContext;
37  class SecurityCredentials;
38 
39  class StackInstance;
40 
41  /// CatalogInterface can only be instantiated through this class.
42  class PluginManager {
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) throw (DmException);
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) throw (DmException);
61 
62  /// Load a configuration file, with plugins and parameters.
63  /// @param file The configuration file.
64  void loadConfiguration(const std::string& file) throw (DmException);
65 
66  /// Return an entry from the loaded configuration.
67  /// @param key The configuration parameter.
68  std::string getConfiguration(const std::string& key) throw (DmException);
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.
74  void registerAuthnFactory(AuthnFactory* factory) throw (DmException);
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.
80  void registerINodeFactory(INodeFactory* factory) throw (DmException);
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.
86  void registerCatalogFactory(CatalogFactory* factory) throw (DmException);
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.
110  void registerConfigureFactory(BaseFactory* factory) throw (DmException);
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) throw (DmException);
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.
135  std::list<AuthnFactory*> authn_plugins_;
136  std::list<INodeFactory*> inode_plugins_;
137  std::list<CatalogFactory*> catalog_plugins_;
138  std::list<PoolManagerFactory*> pool_plugins_;
139  std::list<IODriverFactory*> io_plugins_;
140  std::list<PoolDriverFactory*> pool_driver_plugins_;
141  std::list<BaseFactory*> configure_factory_;
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 
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.
167  ~StackInstance();
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) throw (DmException);
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 throw (DmException);
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) throw (DmException);
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.
195  void setSecurityCredentials(const SecurityCredentials& cred) throw (DmException);
196 
197  /// Set the security context.
198  void setSecurityContext(const SecurityContext& ctx) throw (DmException);
199 
200  /// Return the security context.
201  const SecurityContext* getSecurityContext(void) const throw ();
202 
203  /// Get the UsersDb interface.
204  Authn* getAuthn() throw (DmException);
205 
206  /// Get the INode.
207  INode* getINode() throw (DmException);
208 
209  /// Get the catalog.
210  Catalog* getCatalog() throw (DmException);
211 
212  // Check if there is a PoolManager available
213  bool isTherePoolManager() throw ();
214 
215  /// Get the PoolManager.
217 
218  /// Get a pool driver.
219  PoolDriver* getPoolDriver(const std::string& poolType) throw (DmException);
220 
221  /// Get the IO driver.
222  IODriver* getIODriver() throw (DmException);
223 
224  private:
226 
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
243  struct PluginIdCard {
244  /// Used to make sure API is consistent.
245  unsigned const ApiVersion;
246  /// Let the plug-in register itself and its concrete factories
248  };
249 
250  /// Macro intended to allow future expansions of the PluginIdCard header
251  /// easily.
252  #define PLUGIN_ID_HEADER dmlite::API_VERSION
253 
254 };
255 
256 #endif // DMLITE_CPP_DMLITE_H
Authn * authn_
Definition: dmlite.h:227
Logger::bitmask stackinstancelogmask
void registerINodeFactory(INodeFactory *factory)
void eraseAll(void)
Erase all the values set previously.
Plug-ins must implement a concrete factory to be instantiated.
Definition: poolmanager.h:76
Plug-ins must implement a concrete factory to be instantiated.
Definition: catalog.h:216
std::list< IODriverFactory * > io_plugins_
Definition: dmlite.h:139
Catalog * catalog_
Definition: dmlite.h:229
const unsigned API_VERSION
API Version.
Definition: dmlite.h:20
Definition: dmlite.h:161
const SecurityContext * getSecurityContext(void) const
Return the security context.
void setSecurityContext(const SecurityContext &ctx)
Set the security context.
Security context. To be created by the Authn.
Definition: authn.h:64
CatalogFactory * getCatalogFactory()
Get the CatalogFactory implementation on top of the plugin stack.
INode * inode_
Definition: dmlite.h:228
Header generated by CMake with the build configuration used.
PoolManagerFactory * getPoolManagerFactory()
Get the PoolFactory implementation on top of the plugin stack.
Base exception class.
Definition: exceptions.h:17
void registerAuthnFactory(AuthnFactory *factory)
PluginManager * getPluginManager()
Get the plugin manager.
void registerConfigureFactory(BaseFactory *factory)
PoolManager * getPoolManager()
Get the PoolManager.
~PluginManager()
Destructor.
CatalogInterface can only be instantiated through this class.
Definition: dmlite.h:42
Interface for pool types.
Definition: poolmanager.h:33
Definition: authn.h:87
Interface for Catalog (Namespaces).
Definition: catalog.h:29
PluginManager * pluginManager_
Definition: dmlite.h:225
StackInstance(PluginManager *pm)
Constructor.
void set(const std::string &key, const boost::any &value)
std::list< AuthnFactory * > authn_plugins_
Internal list of loaded plug-ins.
Definition: dmlite.h:135
void setSecurityCredentials(const SecurityCredentials &cred)
Set the security credentials.
PoolDriver * getPoolDriver(const std::string &poolType)
Get a pool driver.
void configure(const std::string &key, const std::string &value)
unsigned long long bitmask
typedef for a bitmask (long long)
Definition: logger.h:38
IODriver * ioDriver_
Definition: dmlite.h:231
AuthnFactory.
Definition: authn.h:177
void loadPlugin(const std::string &lib, const std::string &id)
INodeFactory.
Definition: inode.h:282
IODriverFactory * getIODriverFactory()
Get the IOFactory implementation on top of the plugin stack.
void loadConfiguration(const std::string &file)
Exceptions used by the API.
unsigned const ApiVersion
Used to make sure API is consistent.
Definition: dmlite.h:245
std::map< std::string, PoolDriver * > poolDrivers_
Definition: dmlite.h:235
Plug-ins must implement a concrete factory to be instantiated.
Definition: io.h:153
std::string component
typedef for a component name (std:string)
Definition: logger.h:40
Authn * getAuthn()
Get the UsersDb interface.
std::list< void * > dlHandles_
Keep pointers returned by dlopen at hand to free on destruction.
Definition: dmlite.h:144
PoolDriverFactory * getPoolDriverFactory(const std::string &pooltype)
Get the appropiate pool driver factory for the pool.
Base class for factories.
Definition: base.h:48
PoolDriver factory.
Definition: pooldriver.h:117
INode * getINode()
Get the INode.
SecurityContext * secCtx_
Definition: dmlite.h:233
void registerPoolDriverFactory(PoolDriverFactory *factory)
Definition: inode.h:118
INodeFactory * getINodeFactory()
std::list< INodeFactory * > inode_plugins_
Definition: dmlite.h:136
Catalog * getCatalog()
Get the catalog.
std::list< PoolDriverFactory * > pool_driver_plugins_
Definition: dmlite.h:140
PoolManager * poolManager_
Definition: dmlite.h:230
std::list< BaseFactory * > configure_factory_
Definition: dmlite.h:141
std::string getConfiguration(const std::string &key)
Joint between plugins and plugin-manager.
Definition: dmlite.h:243
void registerCatalogFactory(CatalogFactory *factory)
PluginManager()
Constructor.
std::list< CatalogFactory * > catalog_plugins_
Definition: dmlite.h:137
void(* registerPlugin)(PluginManager *pm)
Let the plug-in register itself and its concrete factories.
Definition: dmlite.h:247
std::map< std::string, std::string > confValues_
Configuration key/value.
Definition: dmlite.h:132
Security credentials. To be filled by the front-end.
Definition: authn.h:22
AuthnFactory * getAuthnFactory()
Get the AuthnFactory implementation on top of the plugin stack.
IO Driver.
Definition: io.h:111
Interface for a pool driver.
Definition: pooldriver.h:92
Logger::component stackinstancelogname
std::list< PoolManagerFactory * > pool_plugins_
Definition: dmlite.h:138
IODriver * getIODriver()
Get the IO driver.
void setSecurityContextImpl_(void)
~StackInstance()
Destructor.
void erase(const std::string &key)
void registerIODriverFactory(IODriverFactory *factory)
bool contains(const std::string &key)
std::map< std::string, boost::any > stackMsg_
Definition: dmlite.h:237
void registerPoolManagerFactory(PoolManagerFactory *factory)