include/dmlite/cpp/dmlite.h

Go to the documentation of this file.
00001 /// @file   include/dmlite/cpp/dmlite.h
00002 /// @brief  Entry point for DMLite.
00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
00004 #ifndef DMLITE_CPP_DMLITE_H
00005 #define DMLITE_CPP_DMLITE_H
00006 
00007 #include "dmlite/common/config.h"
00008 #include "exceptions.h"
00009 
00010 #include <boost/any.hpp>
00011 #include <list>
00012 #include <map>
00013 #include <string>
00014 #include "utils/logger.h"
00015 
00016 /// Namespace for the dmlite C++ API
00017 namespace dmlite {
00018 
00019   /// API Version.
00020   const unsigned API_VERSION = 20121218;
00021 
00022   // Forward declarations.
00023   class Authn;
00024   class AuthnFactory;
00025   class BaseFactory;
00026   class Catalog;
00027   class CatalogFactory;
00028   class INode;
00029   class INodeFactory;
00030   class IODriver;
00031   class IODriverFactory;
00032   class PoolDriver;
00033   class PoolDriverFactory;
00034   class PoolManager;
00035   class PoolManagerFactory;
00036   class SecurityContext;  
00037   class SecurityCredentials;
00038   
00039   class StackInstance;
00040 
00041   /// CatalogInterface can only be instantiated through this class.
00042   class PluginManager {
00043    public:
00044     /// Constructor
00045     PluginManager() throw ();
00046 
00047     /// Destructor
00048     ~PluginManager();
00049 
00050     /// Load a plugin. Previously instantiated interfaces won't be affected.
00051     /// @param lib     The .so file. Usually, (path)/plugin_name.so.
00052     /// @param id      The plugin ID. Usually, plugin_name.
00053     void loadPlugin(const std::string& lib,
00054                     const std::string& id) throw (DmException);
00055 
00056     /// Set a configuration parameter. It will be passed to the loaded plugins.
00057     /// @param key   The configuration parameter.
00058     /// @param value The value for the configuration parameter.
00059     void configure(const std::string& key,
00060                    const std::string& value) throw (DmException);
00061 
00062     /// Load a configuration file, with plugins and parameters.
00063     /// @param file The configuration file.
00064     void loadConfiguration(const std::string& file) throw (DmException);
00065 
00066     /// Return an entry from the loaded configuration.
00067     /// @param key The configuration parameter.
00068     std::string getConfiguration(const std::string& key) throw (DmException);
00069 
00070     /// Register a Authn factory. To be used by concrete implementations
00071     /// @param factory The UserDbGroup concrete factory.
00072     /// @note  The same object can be passed to other register functions.
00073     ///        DMLite will take care of freeing it only once.
00074     void registerAuthnFactory(AuthnFactory* factory) throw (DmException);
00075 
00076     /// Register a INode factory. To be used by concrete implementations (i.e. Plugins)
00077     /// @param factory The INode concrete factory.
00078     /// @note  The same object can be passed to other register functions.
00079     ///        DMLite will take care of freeing it only once.
00080     void registerINodeFactory(INodeFactory* factory) throw (DmException);
00081 
00082     /// Register a catalog factory. To be used by concrete implementations (i.e. Plugins)
00083     /// @param factory The catalog concrete factory.
00084     /// @note  The same object can be passed to other register functions.
00085     ///        DMLite will take care of freeing it only once.
00086     void registerCatalogFactory(CatalogFactory* factory) throw (DmException);
00087 
00088     /// Register a pool factory.
00089     /// @param factory The pool concrete factory.
00090     /// @note  The same object can be passed to other register functions.
00091     ///        DMLite will take care of freeing it only once.
00092     void registerPoolManagerFactory(PoolManagerFactory* factory) throw (DmException);
00093 
00094     /// Register a IODriver factory.
00095     /// @param factory The IO concrete factory.
00096     /// @note  The same object can be passed to other register functions.
00097     ///        DMLite will take care of freeing it only once.
00098     void registerIODriverFactory(IODriverFactory* factory) throw (DmException);
00099 
00100     /// Register a PoolDriver factory.
00101     /// @param factory The PoolDriver factory.
00102     /// @note  The same object can be passed to other register functions.
00103     ///        DMLite will take care of freeing it only once.
00104     void registerPoolDriverFactory(PoolDriverFactory* factory) throw (DmException);
00105     
00106     /// Register a bare BaseFactory. Only the configure method will be called.
00107     /// @param factory The BaseFactory.
00108     /// @note  The same object can be passed to other register functions.
00109     ///        DMLite will take care of freeing it only once.
00110     void registerConfigureFactory(BaseFactory* factory) throw (DmException);
00111     
00112     /// Get the AuthnFactory implementation on top of the plugin stack.
00113     AuthnFactory* getAuthnFactory() throw (DmException);
00114 
00115     // Get the INodeFactory implementation on top of the plugin stack.
00116     INodeFactory* getINodeFactory() throw (DmException);
00117 
00118     /// Get the CatalogFactory implementation on top of the plugin stack.
00119     CatalogFactory* getCatalogFactory() throw (DmException);
00120 
00121     /// Get the PoolFactory implementation on top of the plugin stack.
00122     PoolManagerFactory* getPoolManagerFactory() throw (DmException);
00123 
00124     /// Get the appropiate pool driver factory for the pool.
00125     PoolDriverFactory* getPoolDriverFactory(const std::string& pooltype) throw (DmException);
00126 
00127     /// Get the IOFactory implementation on top of the plugin stack.
00128     IODriverFactory* getIODriverFactory() throw (DmException);
00129 
00130    private:
00131     /// Configuration key/value
00132     std::map<std::string, std::string> confValues_;
00133 
00134     /// Internal list of loaded plug-ins.
00135     std::list<AuthnFactory*>       authn_plugins_;
00136     std::list<INodeFactory*>       inode_plugins_;
00137     std::list<CatalogFactory*>     catalog_plugins_;
00138     std::list<PoolManagerFactory*> pool_plugins_;
00139     std::list<IODriverFactory*>    io_plugins_;
00140     std::list<PoolDriverFactory*>  pool_driver_plugins_;
00141     std::list<BaseFactory*>        configure_factory_;
00142 
00143     /// Keep pointers returned by dlopen at hand to free on destruction
00144     std::list<void*> dlHandles_;
00145 
00146     /// Can not be copied
00147     PluginManager(const PluginManager&);
00148   };
00149 
00150   extern Logger::bitmask stackinstancelogmask;
00151   extern Logger::component stackinstancelogname;
00152   
00153   /// We need to have something that allows one plugin stack to access
00154   /// another plugin stack, so this represents a instantiation
00155   /// of each plugin stack.
00156   /// It also keeps common state: user credentials, security context,
00157   /// and run-time parameters (see set)
00158   /// @note Assume a StackInstance (and every instantiated interface under it)
00159   ///       is NOT thread-safe. This means, a StackInstance must be used by only
00160   ///       one thread at the same time.
00161   class StackInstance {
00162    public:
00163     /// Constructor.
00164     StackInstance(PluginManager* pm) throw(DmException);
00165 
00166     /// Destructor.
00167     ~StackInstance();
00168 
00169     /// Set a key-value pair associated with this context.
00170     /// This can be used to pass advanced parameters to and from the plugins.
00171     /// @param key   The key.
00172     /// @param value The value.
00173     void set(const std::string& key, const boost::any& value) throw (DmException);
00174 
00175     /// Get a value associated to a key.
00176     /// This can be used to pass advanced parameters to and from the plugins.
00177     /// @param key The key parameter.
00178     boost::any get(const std::string& key) const throw (DmException);
00179 
00180     /// Erase a key,value pair from.
00181     /// @param key The key of the pair to be erased.
00182     void erase(const std::string& key) throw (DmException);
00183 
00184     /// Erase all the values set previously.
00185     void eraseAll(void) throw ();
00186 
00187     /// Checks if the stack instance contains a value associated with
00188     /// the given key.
00189     bool contains(const std::string& key) throw ();
00190 
00191     /// Get the plugin manager.
00192     PluginManager* getPluginManager() throw (DmException);
00193 
00194     /// Set the security credentials.
00195     void setSecurityCredentials(const SecurityCredentials& cred) throw (DmException);
00196 
00197     /// Set the security context.
00198     void setSecurityContext(const SecurityContext& ctx) throw (DmException);
00199 
00200     /// Return the security context.
00201     const SecurityContext* getSecurityContext(void) const throw ();
00202 
00203     /// Get the UsersDb interface.
00204     Authn* getAuthn() throw (DmException);
00205 
00206     /// Get the INode.
00207     INode* getINode() throw (DmException);
00208 
00209     /// Get the catalog.
00210     Catalog* getCatalog() throw (DmException);
00211 
00212     // Check if there is a PoolManager available
00213     bool isTherePoolManager() throw ();
00214 
00215     /// Get the PoolManager.
00216     PoolManager* getPoolManager() throw (DmException);
00217 
00218     /// Get a pool driver.
00219     PoolDriver* getPoolDriver(const std::string& poolType) throw (DmException);
00220 
00221     /// Get the IO driver.
00222     IODriver* getIODriver() throw (DmException);
00223 
00224   private:
00225     PluginManager* pluginManager_;
00226 
00227     Authn*       authn_;
00228     INode*       inode_;
00229     Catalog*     catalog_;
00230     PoolManager* poolManager_;
00231     IODriver*    ioDriver_;
00232 
00233     SecurityContext* secCtx_;
00234 
00235     std::map<std::string, PoolDriver*> poolDrivers_;
00236 
00237     std::map<std::string, boost::any> stackMsg_;
00238 
00239     void setSecurityContextImpl_(void);
00240   };
00241 
00242   /// Joint between plugins and plugin-manager
00243   struct PluginIdCard {
00244     /// Used to make sure API is consistent.
00245     unsigned const  ApiVersion;
00246     /// Let the plug-in register itself and its concrete factories
00247     void (*registerPlugin)(PluginManager* pm) throw (DmException);
00248   };
00249 
00250   /// Macro intended to allow future expansions of the PluginIdCard header
00251   /// easily.
00252   #define PLUGIN_ID_HEADER dmlite::API_VERSION
00253 
00254 };
00255 
00256 #endif // DMLITE_CPP_DMLITE_H

Generated on 18 Nov 2014 for dmlite by  doxygen 1.4.7