// Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) // Copyright (c) 2005-2007 Hartmut Kaiser (hartmut.kaiser@gmail.com) // Copyright (c) 2005 Michel Zandstra (michelzandstra@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef SAGA_IMPL_ENGINE_ENGINE_HPP #define SAGA_IMPL_ENGINE_ENGINE_HPP #include #include #include #include // filesystem will be in TR2 #include #include #include #include #include #include #include #include #include #include #include namespace saga { namespace impl { /** * This class makes the various Saga adaptors available to Saga */ class engine : private boost::noncopyable { // FIXME: add const-ness to the registry hierarchy! private: typedef std::vector module_list_type; typedef std::map > adaptor_instance_map_type; typedef v1_0::preference_type preference_type; typedef v1_0::cpi_info cpi_info; typedef v1_0::cpi cpi; // keep infos from ini files saga::ini::ini ini; /** The global adaptor registry used to create adaptors * * This factory holds, for each cpi interface_, a list of adaptors (maker * function, description table) that implement this class. See definitions * above */ adaptor_selector::adaptor_info_list_type adaptor_infos; module_list_type modules; // loaded shared libraries adaptor_instance_map_type adaptors; // loaded adaptor instances // a selector for finding matching adaptors adaptor_selector selector; /** * Reads all shared library names in the file "adaptorlist", and tries to * open the defined shared libraries. It uses Boost.Plugin to handle the shared * libraries. If it can open a library, it invokes the loader function of * this library to register it's maker function and description table with * the factory. * * @see ltdl * * @throws saga::exception is thrown if file "adaptorlist" could not be * opened, or does not exist */ void init (void); bool load_adaptor(saga::impl::session *current_session, boost::filesystem::path const& lib); public: /** Constructor of engine, loads all adaptors */ engine (void); /** Destructor of engine */ ~engine (void); // load all matching shared libraries // throws saga::exception void load (saga::impl::session *); /** * Creates an adaptor object implementing the interface * * @param cpi_name a string specifying the interface for which an object * is needed * @param op_name a description method wanted from the adaptor * @param prefs a description table describing the adaptor needed * * @return a pointer of type T* to the created object, or NULL of no suitable * adaptor could be found * * @see saga::adaptor_selector::select_adaptor */ SAGA_EXPORT v1_0::cpi* get_adaptor (std::string const& ops_cpi_name, std::string const& op_name, preference_type const& prefs, adaptor_selector::adaptor_info_list_type& no_adaptor_infos, proxy* proxy_) const; /** * Tests, whether a given adaptor object implements the required interface * * @param adaptor a pointer to the adaptor to test * @param cpi_name a string specifying the interface for which an object * is needed * @param op_name a description method wanted from the adaptor * @param prefs a description table describing the adaptor needed * * @return a pointer of type T* to the created object, or NULL of no suitable * adaptor could be found * * @see saga::adaptor_selector::select_adaptor */ SAGA_EXPORT bool test_adaptor (v1_0::cpi const* adaptor, std::string const& cpi_name, std::string const& op_name, preference_type const& prefs) const; // return the name of the adaptor with the given adaptor id std::string get_adaptor_name(saga::uuid id) const { adaptor_instance_map_type::const_iterator it = adaptors.find(id); if (it != adaptors.end()) return (*it).second->get_name(); SAGA_THROW("saga::engine::get_adaptor: could not retrieve adaptor name " "for: " + id.string(), saga::NoSuccess); return ""; } }; // class engine }; // namespace impl }; // namespace saga #endif // SAGA_IMPL_ENGINE_ENGINE_HPP