示例#1
0
void
chooser::insert_device (type_id type, const scanner::info& device)
{
  insert (type, device.name (), device.text (), device.udi ());
}
示例#2
0
scanner::ptr
scanner::create (connexion::ptr cnx, const scanner::info& info)
{
  if (!info.is_driver_set ())
    {
      log::error ("driver not known for %1% (%2%)")
        % info.name ()
        % info.udi ()
        ;
      return scanner::ptr ();
    }

  std::string plugin = "libdrv-" + info.driver ();

  lt_dlhandle handle = NULL;
  scanner_factory factory = 0;
  std::string error (_("driver not found"));

  log::brief ("looking for preloaded '%1%' driver")
    % info.driver ();

  lt_dladvise advice;
  lt_dladvise_init (&advice);
  lt_dladvise_preload (&advice);
  lt_dladvise_ext (&advice);

  handle = lt_dlopenadvise (plugin.c_str (), advice);

  if (handle)
    {
      factory = get_scanner_factory (handle);
      if (factory)
        {
          log::brief ("using preloaded '%1%' driver")
            % info.driver ();
        }
      else
        {
          lt_dlclose (handle);
        }
    }
  lt_dladvise_destroy (&advice);

  if (!factory) {               // trawl the file system
    run_time rt;
    run_time::sequence_type search (rt.load_dirs (run_time::pkg, "driver"));

  run_time::sequence_type::const_iterator it;
  for (it = search.begin (); !handle && it != search.end (); ++it)
    {
      path p (*it);

      log::brief ("looking for '%1%' driver in '%2%'")
        % info.driver ()
        % p.string ()
        ;

      p /= plugin;

      handle = lt_dlopenext (p.string ().c_str ());

      if (handle) {
        factory = get_scanner_factory (handle);

        if (factory) {
          log::brief ("using '%1%'") % p.string ();
        } else {
          error = lt_dlerror ();
          lt_dlclose (handle);
          handle = NULL;
        }
      } else {
        error = lt_dlerror ();
      }
    }
  }

  if (!factory) BOOST_THROW_EXCEPTION (runtime_error (error));

  scanner::ptr rv;
  factory (rv, cnx);
  return rv;
}