Exemple #1
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!");
  }
}
Exemple #2
0
void Plugin::unloadExternal(const std::string name)
{
    LIBRARY_HANDLE lhandle = NULL;
    void (*fhandle)(Mineserver*) = NULL;

    if (m_libraryHandles[name] != NULL)
    {
        Mineserver::get()->screen()->log("Unloading plugin "+name+"...");

        lhandle = m_libraryHandles[name];
        fhandle = (void (*)(Mineserver*)) LIBRARY_SYMBOL(lhandle, (name+"_shutdown").c_str());
        if (fhandle == NULL)
        {
            Mineserver::get()->screen()->log("Could not get shutdown function handle!");
        }
        else
        {
            Mineserver::get()->screen()->log("Calling shutdown function for "+name+".");
            fhandle(Mineserver::get());
        }

        LIBRARY_CLOSE(m_libraryHandles[name]);
        m_libraryHandles.erase(name);
    }
    else
    {
        Mineserver::get()->screen()->log("Plugin "+name+" not loaded!");
    }
}
Exemple #3
0
//writes file in format:
//x_1   y_m     z_1_m
//x_2   y_m     z_1_m
//x_3   y_m     z_1_m
//      .
//      .
//x_n   y_m     z_1_(m-1)
//x_1   y_(m_1) z_1_(m-1)
//      .
//      .
//x_n   y_1     z_n_1
bool XYZ_Writer::writeToFile(const VEC &x,
                             const VEC &y, 
                             const vector<VEC> &z)
{
    ofstream fhandle(m_fileName.c_str(), ios::out);

    //get size from vectors
    size_t n = x.size();
    size_t m = y.size();

    double xVal, yVal, zVal;
    size_t xIdx, yIdx;
    for(size_t i = 0; i != m*n; ++i)
    {
        //write x value
        xIdx = i % n;
        xVal = x[xIdx];
        fhandle << xVal << " ";

        //write y value
        yIdx = m - 1 - (i - (i%n))/n;
        yVal = y[yIdx];
        fhandle << yVal << " ";

        //write z value
        zVal = isnan(z[yIdx][xIdx]) ? 0.0 : z[yIdx][xIdx];


        fhandle << zVal << endl;
    }

    return true;
}
Exemple #4
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;
}
static void forkTheFLTData(vector <float> &arrayReal,GA_Attribute *attrib,fpreal maxPt,fpreal startPt)
{
    GA_RWHandleF fhandle(attrib);
    arrayReal.clear();
    for(int i=0+startPt; i<maxPt+startPt; i++)
    {

        float value = fhandle.get(i);
        arrayReal.push_back(value);
    }

}
Exemple #6
0
void Engine::evalFile(const std::string& file)
{
    bool errFlag = true;
    onBeforeEval();
    try {
        ContextHandle handle = m_ctx.handle();

        base::FileHandle fhandle(base::open_file(file, "rb"));
        FILE* f = fhandle.get();
        if (!f)
            return;

        if (fseek(f, 0, SEEK_END) < 0)
            return;

        int sz = ftell(f);
        if (sz < 0)
            return;

        if (fseek(f, 0, SEEK_SET) < 0)
            return;

        char* buf = (char*)duk_push_fixed_buffer(handle, sz);
        ASSERT(buf != nullptr);
        if (fread(buf, 1, sz, f) != sz)
            return;

        fclose(f);
        f = nullptr;

        duk_push_string(handle, duk_to_string(handle, -1));
        duk_eval_raw(handle, nullptr, 0, DUK_COMPILE_EVAL);

        if (m_printLastResult &&
                !duk_is_null_or_undefined(handle, -1)) {
            m_delegate->onConsolePrint(duk_safe_to_string(handle, -1));
        }

        duk_pop(handle);
        errFlag = false;
    }
    catch (const std::exception& ex) {
        std::string err = "Error: ";
        err += ex.what();
        m_delegate->onConsolePrint(err.c_str());
    }
    onAfterEval(errFlag);
}
Exemple #7
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!");
  }
}
Exemple #8
0
bool Plugin::loadExternal(const std::string name, const std::string file)
{
    LIBRARY_HANDLE lhandle = NULL;
    void (*fhandle)(Mineserver*) = NULL;

    Mineserver::get()->screen()->log("Loading plugin "+name+" ("+file+")...");

    struct stat st;
    if(stat(file.c_str(), &st) != 0)
    {
        Mineserver::get()->screen()->log("Could not find "+file+"!");
        return false;
    }

    lhandle = LIBRARY_LOAD(file.c_str());
    if (lhandle == NULL)
    {
        Mineserver::get()->screen()->log("Could not load "+file+"!");
        Mineserver::get()->screen()->log(LIBRARY_ERROR());
        return false;
    }

    m_libraryHandles[name] = lhandle;

    fhandle = (void (*)(Mineserver*)) LIBRARY_SYMBOL(lhandle, (name+"_init").c_str());
    if (fhandle == NULL)
    {
        Mineserver::get()->screen()->log("Could not get init function handle!");
        unloadExternal(name);
        return false;
    }

    fhandle(Mineserver::get());

    return true;
}
Exemple #9
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;
}