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