Exemplo n.º 1
0
bool Plugin::loadPlugin(const std::string name, const std::string file)
{
  LIBRARY_HANDLE lhandle = NULL;
  void (*fhandle)(mineserver_pointer_struct*) = NULL;

  if (!file.empty())
  {
    LOG(INFO, "Plugin", "Loading plugin `" + name + "' (`" + file + "')...");

    struct stat st;
    int statr = stat(file.c_str(), &st);
    if ((statr == 0) && !(st.st_mode & S_IFDIR))
    {
      lhandle = LIBRARY_LOAD(file.c_str());
    }
    else
    {
      LOG(INFO, "Plugin", "Could not find `" + file + "', trying `" + file + LIBRARY_EXTENSION + "'.");

      statr = stat((file + LIBRARY_EXTENSION).c_str(), &st);
      if ((statr == 0) && !(st.st_mode & S_IFDIR))
      {
        lhandle = LIBRARY_LOAD((file + LIBRARY_EXTENSION).c_str());
      }
      else
      {
        LOG(INFO, "Plugin", "Could not find `" + file + LIBRARY_EXTENSION + "'!");
        return false;
      }
    }

  }
  else
  {
    LOG(INFO, "Plugin", "Loading plugin `" + name + "' (built in)...");
    lhandle = LIBRARY_SELF();
  }

  if (lhandle == NULL)
  {
    LOG(INFO, "Plugin", "Could not load plugin `" + name + "'!");
    LOG(INFO, "Plugin", LIBRARY_ERROR());
    return false;
  }

  m_libraryHandles[name] = lhandle;

  fhandle = (void (*)(mineserver_pointer_struct*)) LIBRARY_SYMBOL(lhandle, (name + "_init").c_str());
  if (fhandle == NULL)
  {
    LOG(INFO, "Plugin", "Could not get init function handle!");
    unloadPlugin(name);
    return false;
  }
  fhandle(&plugin_api_pointers);

  return true;
}
Exemplo n.º 2
0
void Plugin::unloadPlugin(const std::string name)
{
  LIBRARY_HANDLE lhandle = NULL;
#ifdef FADOR_PLUGIN
  void (*fhandle)(void) = NULL;
#else
  void (*fhandle)(Mineserver*) = NULL;
#endif

  if (m_pluginVersions.find(name) != m_pluginVersions.end())
  {
    LOG(INFO, "Plugin", "Unloading plugin `"+name+"'...");

    if (m_libraryHandles[name] != NULL)
    {
      lhandle = m_libraryHandles[name];
      m_libraryHandles.erase(name);
    }
    else
    {
      lhandle = LIBRARY_SELF();
    }

#ifdef FADOR_PLUGIN
    fhandle = (void (*)(void)) LIBRARY_SYMBOL(lhandle, (name+"_shutdown").c_str());
#else
    fhandle = (void (*)(Mineserver*)) LIBRARY_SYMBOL(lhandle, (name+"_shutdown").c_str());
#endif

    if (fhandle == NULL)
    {
      LOG(INFO, "Plugin","Could not get shutdown function handle!");
    }
    else
    {
      LOG(INFO, "Plugin","Calling shutdown function for `"+name+"'.");
      
#ifdef FADOR_PLUGIN  
      fhandle();
#else
      fhandle(Mineserver::get());
#endif
    }

    LIBRARY_CLOSE(m_libraryHandles[name]);
  }
  else
  {
    LOG(INFO, "Plugin", "Plugin `"+name+"' not loaded!");
  }
}
Exemplo n.º 3
0
void Plugin::unloadPlugin(const std::string& name)
{
  LIBRARY_HANDLE lhandle = NULL;
  pfv fhandle = NULL;

  if (m_pluginVersions.find(name) != m_pluginVersions.end())
  {
    LOG(INFO, "Plugin", "Unloading: " + name);

    if (m_libraryHandles[name] != NULL)
    {
      lhandle = m_libraryHandles[name];
      m_libraryHandles.erase(name);
    }
    else
    {
      lhandle = LIBRARY_SELF();
    }

    *reinterpret_cast<void**>(&fhandle) = (void*)LIBRARY_SYMBOL(lhandle, (name + "_shutdown").c_str());
    if (fhandle == NULL)
    {
      LOG(INFO, "Plugin", "Could not get shutdown function handle!");
    }
    else
    {
      LOG(INFO, "Plugin", "Calling shutdown function for: " + name);
      fhandle();
    }

    LIBRARY_CLOSE(m_libraryHandles[name]);
  }
  else
  {
    LOG(WARNING, "Plugin", name + " is not loaded!");
  }
}
Exemplo n.º 4
0
bool Plugin::loadPlugin(const std::string& name, const std::string& path, std::string alias)
{
  LIBRARY_HANDLE lhandle = NULL;
  pfms fhandle = NULL;

  if (name.empty()
      || (name.find('/')  != std::string::npos)
      || (name.find('\\') != std::string::npos))
  {
    LOG(INFO, "Plugin", "Invalid name: " + name);
    return false;
  }

  if (alias.empty())
  {
    alias = name;
  }

  if (!path.empty())
  {
    std::string file;
    file = path + '/' + name + LIBRARY_EXTENSION;

    struct stat st;
    int statr = stat(file.c_str(), &st);
    if ((statr == 0) && !(st.st_mode & S_IFDIR))
    {
      LOG(INFO, "Plugin", "Loading: " + file);
      lhandle = LIBRARY_LOAD(file.c_str());
    }
    else
    {
      LOG(INFO, "Plugin", "Could not find: " + file);
      return false;
    }
  }
  else
  {
    LOG(INFO, "Plugin", "Loading built-in: " + name);
    lhandle = LIBRARY_SELF();
  }

  if (lhandle == NULL)
  {
    LOG(INFO, "Plugin", "Could not load: " + name);
    LOG(INFO, "Plugin", LIBRARY_ERROR());
    return false;
  }

  m_libraryHandles[alias] = lhandle;

  *reinterpret_cast<void**>(&fhandle) = (void*)LIBRARY_SYMBOL(lhandle, (name + "_init").c_str());
  if (fhandle == NULL)
  {
    LOG(INFO, "Plugin", "Could not get init function handle!");
    unloadPlugin(alias);
    return false;
  }
  fhandle(&plugin_api_pointers);

  return true;
}