// 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 // job LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef SAGA_IMPL_ENGINE_PROXY_HPP #define SAGA_IMPL_ENGINE_PROXY_HPP #include #include #include #include #include // include CPI's #include #include #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// namespace saga { namespace impl { /** * The base class of all proxy classes * * Contains functions to handle the shared adaptor data objects, * and a pointer to the session handle */ class proxy : public saga::impl::object { protected: typedef v1_0::preference_type preference_type; typedef v1_0::cpi cpi; typedef TR1::shared_ptr cpi_type; private: saga::session session_; public: typedef boost::recursive_mutex mutex_type; cpi_list cpis_; mutex_type cpis_mtx_; protected: // instance data mutex_type instance_data_mtx_; TR1::shared_ptr instance_data_; public: /** constructor */ explicit proxy (saga::object::type type, saga::session const& session) : object(type), session_(session) { } /** destructor */ virtual ~proxy (void) { release_cpis(); } void release_cpis() { mutex_type::scoped_lock lock(cpis_mtx_); cpis_.clear(); } saga::session get_session (void) const { return session_; } std::string get_cpi_name() const { return saga::adaptors::get_cpi_name(this->get_type()); } /** * Asks Saga engine for a new adaptor of type CpiType, that * matches the description table. If file was already bound to an * adaptor, it is destroyed first. UNLESS this adaptor has fixed * itself. In that case, instead of creating a new adaptor, file * simply uses this fixed one. * * @param table a description table describing the adaptor needed */ SAGA_EXPORT bool get_adaptor (std::string const& cpi_name, std::string const& op_name, preference_type const& prefs, adaptor_selector::adaptor_info_list_type &no_no_list); /** * Asks the Saga engine, whether the given adaptor supports a certain * operation. */ SAGA_EXPORT bool test_adaptor (cpi_type cpi, std::string const& cpi_name, std::string const& op_name, preference_type const& prefs); // find out, which execution type a given adaptor prefers to be used SAGA_EXPORT run_mode test_adaptor_helper(cpi_type cpi, std::string const& cpi_name, std::string const& call_name, preference_type const& prefs, bool is_sync); ///////////////////////////////////////////////////////////////////////// // Helper function to be called from inside the implementation object's // constructor. It creates and initializes a new CPI instance SAGA_EXPORT bool initcpi (std::string const& cpi_name, preference_type const& prefs = preference_type()); // create a new CPI instance, and figure out what execution preferences // this CPI has for the given function. // // This function gets called for every CPI function to be called, // whenever the CPI was newly created for this CPI call. SAGA_EXPORT run_mode get_adaptor_helper(std::string const& cpi_name, std::string const& call_name, preference_type const& prefs, bool is_sync, adaptor_selector::adaptor_info_list_type &no_no_list); // create a new CPI instance, and figure out what execution preferences // this CPI has for the given function SAGA_EXPORT run_mode get_adaptor_for_init( std::string const& cpi_name, preference_type const& prefs, adaptor_selector::adaptor_info_list_type &no_no_list); ///////////////////////////////////////////////////////////////////////// // This is the main 'API' function for adaptor selection and // preparation. // // select_run_mode() is called for every API function to bind an // appropriate cpi instance claiming to be able to handle the request. SAGA_EXPORT run_mode select_run_mode (std::string const& cpi_name, std::string const& call_name, preference_type const& prefs, bool is_sync, adaptor_selector::adaptor_info_list_type &no_no_list); /////////////////////////////////////////////////////////////////////// // handle API object instance data SAGA_EXPORT TR1::shared_ptr register_instance_data (TR1::shared_ptr o); SAGA_EXPORT void release_instance_data(); SAGA_EXPORT TR1::shared_ptr check_out_instance_data(); SAGA_EXPORT void check_in_instance_data(); ///////////////////////////////////////////////////////////////////////// // helper for enable_shared_from_this support SAGA_EXPORT TR1::shared_ptr shared_from_this(); SAGA_EXPORT TR1::shared_ptr shared_from_this() const; }; // class proxy ///////////////////////////////////////////////////////////////////////////// }} // namespace saga::impl #include #endif // SAGA_IMPL_ENGINE_PROXY_HPP