Exemple #1
0
  bool engine::load_static_adaptor (saga::impl::session *current_session, 
      std::string instance_name, std::string adaptor_name,
      boost::plugin::get_plugins_list_type get_factory)
  {
    if (is_adaptor_loaded(instance_name, adaptor_name))
        return false;

    try {
      // add this adaptor to the list of modules from which to generate logs 
      register_adaptor_logging(instance_name);

      // get the factory
      boost::plugin::static_plugin_factory<saga::adaptor> pf (get_factory);

      // invoke the loader function of the library, so that the 
      // maker function and description table get registered 
      // with the registry 

      // create the adaptor registration object
      TR1::shared_ptr<saga::adaptor> adap (pf.create("adaptor")); 

      // bail out if the name reported by the adaptor set the adaptor name
      if (SAGA_MANGLE_ADAPTOR_NAME_STR(adap->get_name()) != adaptor_name)
      {
//           adaptor_name = adap->get_name();
          SAGA_LOG(SAGA_VERBOSE_LEVEL_WARNING)
              << "adaptor name: " << adaptor_name 
              << " does not match name reported by library: "
              << adap->get_name();
      }

      // call the register function, and store the adaptors it returns
      adaptor_selector::adaptor_info_list_type new_infos = 
          adap->adaptor_register (current_session); 

      // initialize the adaptor instance using the preferences from the ini files
      saga::ini::ini glob_ini;
      if (ini.has_section ("preferences"))
      {
          glob_ini = ini.get_section ("preferences");
      }

      saga::ini::ini adap_ini;
      std::string adaptor_section("saga.adaptors." + instance_name);
      if (ini.has_section_full(adaptor_section))
      {
          adap_ini = ini.get_section (adaptor_section);
      }

      if ( adap_ini.has_entry ("preferences") )
      {
        if ( ini.has_section_full (adap_ini.get_entry ("preferences")) )
        {
          adap_ini = ini.get_section (adap_ini.get_entry ("preferences"));
        }
      }

      if (!adap->init(current_session, glob_ini, adap_ini))
      {
          SAGA_LOG(SAGA_VERBOSE_LEVEL_WARNING)
              << "adaptor name: " << adaptor_name 
              << " static loading has been canceled by the adaptor instance: "
              << instance_name;
          return false;
      }

      // store adaptor description info
      std::copy (new_infos.begin(), new_infos.end(), 
          std::back_inserter(adaptor_infos_));

      // store adaptor instance
      if (!new_infos.empty()) {
        // some adaptors do not register any functions (yes, this happens!)
        saga::uuid id (new_infos.front().get_adaptor_id());
        if (adaptors_.find(id) == adaptors_.end())
        {
          std::pair<adaptor_instance_map_type::iterator, bool> p =
              adaptors_.insert(std::make_pair(id, adaptor_instance_data_type()));
          if (p.second)
          {
              (*p.first).second.adaptor = adap;
              (*p.first).second.instance_name = instance_name;
              (*p.first).second.adaptor_name = adaptor_name;
          }
        }
      }

      SAGA_LOG(SAGA_VERBOSE_LEVEL_INFO)
          << "loaded adaptor: " << adaptor_name << " ("
          << instance_name << ")";
    }
    catch (std::logic_error const& e) 
    {
      // report error, and skip the library
      SAGA_LOG(SAGA_VERBOSE_LEVEL_WARNING)
          << "Could not load adaptor: " << e.what();
      return false;
    }
    return true;    // adaptor got loaded
  }
Exemple #2
0
  bool engine::load_adaptor (saga::impl::session * current_session, 
                             std::string           instance_name, 
                             std::string           adaptor_name, 
                             boost::filesystem::path const & lib, 
                             bool                  load_globally,
                             std::string const   & unmangled_name)
  {
    if (is_adaptor_loaded(instance_name, adaptor_name))
        return false;

    namespace fs = boost::filesystem;
    if (fs::extension(lib) == SAGA_SHARED_LIB_EXTENSION)
    {
      try {
        // add this adaptor to the list of modules from which to generate logs 
        register_adaptor_logging(unmangled_name);

        /* get the handle of the library */
        boost::plugin::dll d (lib.string(), adaptor_name, 
            load_globally ? BOOST_PLUGIN_DLOPEN_FLAGS_GLOBAL : 
                BOOST_PLUGIN_DLOPEN_FLAGS_LOCAL);

        SAGA_LOG(SAGA_VERBOSE_LEVEL_INFO)
            << "loaded module: " << d.get_name() << " (using " 
            << (load_globally ? "global" : "local") << " load flags)";

        // get the factory
        boost::plugin::plugin_factory<saga::adaptor> pf (d);

        // invoke the loader function of the library, so that the 
        // maker function and description table get registered 
        // with the registry 

        // create the adaptor registration object
        TR1::shared_ptr<saga::adaptor> adap (pf.create("adaptor")); 

        // bail out if the name reported by the adaptor set the adaptor name
        if (SAGA_MANGLE_ADAPTOR_NAME_STR(adap->get_name()) != adaptor_name)
        {
//             adaptor_name = adap->get_name();
            SAGA_LOG(SAGA_VERBOSE_LEVEL_WARNING)
                << "adaptor name: " << adaptor_name 
                << " does not match name reported by library: "
                << adap->get_name();
        }

        // call the register function, and store the adaptors it returns
        adaptor_selector::adaptor_info_list_type new_infos = 
            adap->adaptor_register (current_session); 

        // initialize the adaptor instance using a copy of the global
        // preferences
        saga::ini::ini glob_ini;
        glob_ini.merge(ini);

        // Adaptor preferences are read from two different locations: (a) from
        // any section specified via the 'preferences' key for that adaptor, if
        // that is set in the adapotor's ini file, and (b) from a 'preferences'
        // subsection in that file.  Thus, the more specific preferences from
        // the default adaptor preferences section overwrite the previous
        // general preferences, when neccessary.
        // FIXME: About the comment -- Is this so?!


        // read the specific adaptor settings first, as they may contain the
        // pointer to the more general adaptor settings
        saga::ini::ini adap_ini;
        std::string adaptor_section ("saga.adaptors." + instance_name);

        // if such a pointer to more general settings is present, read those.
        adap_ini = glob_ini.get_section (adaptor_section);

        // we now read the default adaptor ini again, to overwrite the global
        // setting with the adaptor specific settings.
        std::string merge_prefs = adap_ini.get_entry ("preferences", "");
        if ( ! merge_prefs.empty ()
            && glob_ini.has_section_full ( merge_prefs ) )
          adap_ini.merge ( glob_ini.get_section ( merge_prefs ) );

        SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_DEBUG) 
        {
            adap_ini.dump(0, 
                ::boost::logging::get_logger_base(saga::impl::logger())->
                    read_msg().gather().out());
        }

        if (!adap->init(current_session, glob_ini, adap_ini))
        {
            SAGA_LOG(SAGA_VERBOSE_LEVEL_WARNING)
                << "adaptor name: " << adaptor_name 
                << " dynamic loading has been canceled by the adaptor instance: "
                << instance_name;
            return false;
        }

        // store adaptor description info
        std::copy (new_infos.begin(), new_infos.end(), 
            std::back_inserter(adaptor_infos_));

        // store adaptor instance
        if (!new_infos.empty()) {
          // some adaptors do not register any functions (yes, this happens!)
          saga::uuid id (new_infos.front().get_adaptor_id());
          if (adaptors_.find(id) == adaptors_.end())
          {
            std::pair<adaptor_instance_map_type::iterator, bool> p =
                adaptors_.insert(std::make_pair(id, adaptor_instance_data_type()));
            if (p.second)
            {
                (*p.first).second.adaptor = adap;
                (*p.first).second.instance_name = instance_name;
                (*p.first).second.adaptor_name = adaptor_name;
            }
          }
        }

        // hold on on to this shared library
        modules_.push_back (d); 

        SAGA_LOG(SAGA_VERBOSE_LEVEL_INFO)
            << "loaded adaptor: " << adaptor_name << " ("
            << instance_name << ") from file: " << lib.string();
      }
      catch ( std::logic_error const & e ) 
      {
        // report error, and skip the library
        SAGA_LOG(SAGA_VERBOSE_LEVEL_WARNING)
            << "Could not load adaptor: " << e.what();
        return false;
      }
      return true;    // adaptor got loaded
    }
    return false;
  }