PluginRef* load_plugin_ref (std::string const& plugin_path)
  {
      // NOTE: This does not check if a plugin has already been loaded

      try {
          ModulePtr module = Module::load (plugin_path);

          int* plugin_version = static_cast<int*> (module->get_symbol (VISUAL_PLUGIN_VERSION_TAG));

          if (!plugin_version || *plugin_version != VISUAL_PLUGIN_API_VERSION) {
              visual_log (VISUAL_LOG_ERROR, _("Plugin %s is not compatible with version %s of libvisual"),
                          plugin_path.c_str (), visual_get_version ());
              return NULL;
          }

          VisPluginGetInfoFunc get_plugin_info =
              reinterpret_cast<VisPluginGetInfoFunc> (module->get_symbol ("get_plugin_info"));

          if (!get_plugin_info) {
              visual_log (VISUAL_LOG_ERROR, _("Cannot get function that returns plugin info"));
              return NULL;
          }

          VisPluginInfo const* plugin_info = get_plugin_info ();

          if (!plugin_info) {
              visual_log (VISUAL_LOG_ERROR, _("Cannot get plugin info"));
              return NULL;
          }

          PluginRef* ref = new PluginRef;

          ref->info   = plugin_info;
          ref->file   = plugin_path;
          ref->module = module;

          return ref;
      }
      catch (LV::Error& error) {
          visual_log (VISUAL_LOG_ERROR, "Cannot load plugin (%s): %s", plugin_path.c_str (), error.what());
          return NULL;
      }
  }
Esempio n. 2
0
static gboolean
spi_regist (PE_image *pe)
{
   gchar buf[256];
   gboolean success;
   GetPluginInfoFunc get_plugin_info;
   SusiePlugin *plugin;

   g_return_val_if_fail (pe, FALSE);

   get_plugin_info = peimage_resolve (pe, "GetPluginInfo");
   if (!get_plugin_info) {
      g_print ("Cannot resolve GetPluginInfo.\n");
      goto ERROR;
   }

   success = get_plugin_info (0, buf, 256);
   if (!success) {
      g_print ("GetPluginInfo returns 0\n");
      goto ERROR;
   }

   switch (buf[2]) {
   case 'I':
      g_print ("Detected as Import filter.\n");
      plugin = spi_regist_import_filter (pe);
      break;

   case 'X':
      g_print ("Export filter is not supported yet.\n");
      plugin = spi_regist_export_filter (pe);
      break;

   case 'A':
      g_print ("Archiver extractor is not supported yet.\n");
      plugin = spi_regist_archive_extractor (pe);
      break;

   default:
      g_print ("Unknown susie plugin type %c.\n", buf[2]);
      plugin = NULL;
      break;
   }

   if (!plugin) goto ERROR;

   plugin->pe = pe;
   plugin->get_plugin_info = get_plugin_info;
   success = plugin->get_plugin_info (1, buf, 256);
   if (success) {
      plugin->description = g_strdup (buf);
      g_print ("description: %s\n\n", plugin->description);
   } else {
      plugin->description = NULL;
   }

   /* FIXME */
   plugin->formats = NULL;


   return TRUE;

ERROR:
   return FALSE;
}