Exemple #1
0
BOSS::Module * BOSS_Synthesis::load(const string & name) {
  char * errormsg = NULL;
  //load the module library
  cerr << "BOSS_Synthesis: loading " << name << endl;
  lt_dlhandle lib = lt_dlopenext(name.c_str());
  if (!lib) {
    errormsg = dlerrordup (errormsg);
    cerr << "Cannot load library: " << errormsg << endl;
    return 0;
  }
  
  std::cerr << "retrieving library symbols" << std::endl;
  // load the symbols
  create_module * create = (create_module*) lt_dlsym(lib, "create");

  // the destroy function is by current design not so necessary
  //  destroy_module * destroy = (destroy_module*) lt_dlsym(lib, "destroy");
  if (!create ) { //|| !destroy) {
    errormsg = dlerrordup (errormsg);
    cerr << "Cannot load symbols: " << errormsg << endl;
    return 0;
  }
  
  std::cerr << "creating module class instance" << std::endl;
  // create an instance of the class
  BOSS::Module * module = create(cl, data_base);
  return module;
}
Exemple #2
0
//#define Check_Failed_Module 0
exception_t SKY_load_module(const char* module_filename){
	exception_t ret;
	char **module_name;
 	lt_dlhandle * handler;
	const char* err_str = NULL;
	//skyeye_log(Debug_log, __FUNCTION__, "module_filename = %s\n", module_filename);
#ifndef Check_Failed_Module
        handler = lt_dlopenext(module_filename);
#else
        //handler = dlopen(module_filename, RTLD_LAZY);
	handler = dlopen(module_filename, RTLD_NOW);
	if(handler == NULL){
		err_str = dlerror();
		skyeye_log(Error_log, __FUNCTION__, "dll error: %s\n", err_str);
	}
	return Dll_open_exp;
#endif
        if (handler == NULL)
        {
        	err_str = dlerrordup(err_str);
                skyeye_log(Warnning_log, __FUNCTION__, "%s\n", err_str);
		return Dll_open_exp;
        }
	
	module_name = lt_dlsym(handler, "skyeye_module");
	if((err_str = dlerrordup(err_str)) != NULL){
		skyeye_log(Warnning_log, __FUNCTION__, "dll error %s\n", err_str);
		skyeye_log(Warnning_log, __FUNCTION__, "Invalid module in file %s\n", module_filename);
		lt_dlclose(handler);
		return Invmod_exp;
	}
	//skyeye_log(Debug_log, __FUNCTION__, "Load module %s\n", *module_name);
		
	ret = register_skyeye_module(*module_name, module_filename, handler);
	if(ret != No_exp){
		lt_dlclose(handler);
		return ret;
	}
	return No_exp;	
}
int
main (int argc, const char *argv[])
{
    const char modulepath[1+ PATH_MAX];
    const char *errormsg = NULL;
    void *module = NULL;
    entrypoint *run = NULL;
    int errors = 0;

    if (argc != 3)
    {
        fprintf (stderr, "USAGE: main MODULENAME ARGUMENT\n");
        exit (EXIT_FAILURE);
    }

    /* Set the module search path. */
    getcwd (modulepath, PATH_MAX);
    strcat (modulepath, "/");
    strcat (modulepath, argv[1]);

    /* Load the module. */
    module = dlopen (modulepath, RTLD_NOW);
    if (!module)
    {
        strcat (modulepath, ".so");
        module = dlopen (modulepath, RTLD_NOW);
    }
    if (!module)
        errors = 1;

    /* Find the entry point. */
    if (!errors)
    {
        run = dlsym (module, "run");
        /* In principle, run might legitimately be NULL, so
        I don't use `run == NULL' as an error indicator. */
        errormsg = dlerrordup (errormsg);

        if (errormsg != NULL)
            errors = dlclose (module);
    }

    /* Call the entry point function. */
    if (!errors)
    {
        int result = (*run) (argv[2]);
        if (result < 0)
            errormsg = strdup ("module entry point execution failed");
        else
            printf ("\t=> %d\n", result);
    }

    /* Unload the module, now that we are done with it. */
    if (!errors)
        errors = dlclose (module);

    if (errors)
    {
        /* Diagnose the encountered error. */
        errormsg = dlerrordup (errormsg);

        if (!errormsg)
        {
            fprintf (stderr, "%s: dlerror() failed.\n", argv[0]);
            return EXIT_FAILURE;
        }
    }

    if (errormsg)
    {
        fprintf (stderr, "%s: %s.\n", argv[0], errormsg);
        free (errormsg);
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}