Skip to content
Snippets Groups Projects
Commit f1a481eb authored by Jean-François Remacle's avatar Jean-François Remacle
Browse files

Gmsh Plugin's

parent eac29927
No related branches found
No related tags found
No related merge requests found
# $Id: Makefile,v 1.1 2001-03-04 19:55:25 remacle Exp $
#
# Makefile for "libAdapt.a"
#
.IGNORE:
CC = c++
AR = ar ruvs
RM = rm
RANLIB = ranlib
LIB = ../lib/libPlugin.a
INCLUDE = -I../Common -I../DataStr
C_FLAGS = -g -Wall
OS_FLAGS =
VERSION_FLAGS =
RMFLAGS = -f
CFLAGS = $(C_FLAGS) $(OS_FLAGS) $(VERSION_FLAGS) $(INCLUDE)
SRC = Plugin.cpp
OBJ = $(SRC:.cpp=.o)
.SUFFIXES: .o .cpp
$(LIB): $(OBJ)
$(AR) $(LIB) $(OBJ)
$(RANLIB) $(LIB)
.cpp.o:
$(CC) $(CFLAGS) -c $<
clean:
$(RM) $(RMFLAGS) *.o
lint:
$(LINT) $(CFLAGS) $(SRC)
depend:
(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
$(CC) -MM $(CFLAGS) ${SRC} \
) >Makefile.new
cp Makefile Makefile.bak
cp Makefile.new Makefile
$(RM) $(RMFLAGS) Makefile.new
# DO NOT DELETE THIS LINE
#include <stdio.h>
#include <dlfcn.h>
#include <map>
#include "Plugin.h"
using namespace std;
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
class PluginContainer
{
public :
typedef map<char*,GMSH_Plugin*,ltstr>::iterator iter;
map<char*,GMSH_Plugin*,ltstr> m;
iter begin() {return m.begin();}
iter end() {return m.end();}
iter find(char *c) {return m.find(c);}
};
GMSH_PluginManager *GMSH_PluginManager::instance = 0;
GMSH_PluginManager::GMSH_PluginManager()
{
allPlugins = new PluginContainer;
}
GMSH_PluginManager::~GMSH_PluginManager()
{
for(PluginContainer::iter it = allPlugins->begin();
it != allPlugins->end();
++it)delete (*it).second;
delete allPlugins;
}
GMSH_PluginManager* GMSH_PluginManager::Instance()
{
if(!instance)
{
instance = new GMSH_PluginManager;
}
return instance;
}
void GMSH_PluginManager::RegisterDefaultPlugins()
{
char *homeplugins = getenv ("GMSHPLUGINSHOME");
if(!homeplugins)return;
}
void GMSH_PluginManager::AddPlugin( char *dirName, char *pluginName)
{
char dynamic_lib[1024];
char plugin_name[256];
class GMSH_Plugin* (*RegisterPlugin)(void);
sprintf(dynamic_lib,"%s/%s.so",dirName,pluginName);
void *hlib = dlopen (dynamic_lib,RTLD_NOW);
if(hlib == NULL)
{
throw dynamic_lib;
}
RegisterPlugin = (class GMSH_Plugin* (*)(void)) dlsym(hlib,GMSH_PluginEntry);
char *err = dlerror();
if(err != NULL)
{
return;
}
GMSH_Plugin *p = RegisterPlugin();
p->hlib = hlib;
p->getName(plugin_name);
if(allPlugins->find(plugin_name) != allPlugins->end())
{
return;
}
allPlugins->m[plugin_name] = p;
}
#ifndef _PLUGIN_H_
#define _PLUGIN_H_
/*
The one who intend to create a plugin for gmsh have to
-) Create a dynamin lib (.so) containing 1 symbols
GMSH_Plugin * GMSH_RegisterPlugin ();
-) When there is an unacceptable error in the plugin,
just throw this, the plugin manager will be able to
catch the exception.
*/
const char *GMSH_PluginEntry = "GMSH_RegisterPlugin";
class PluginContainer;
class GMSH_Plugin
{
public :
/*this is there for internal use, this variable will be
used by the PluginManager, just forget it*/
void *hlib;
/* 3 kind of plugins, one for cad, one for mesh, one for postpro*/
typedef enum GMSH_PLUGIN_TYPE {GMSH_CAD_PLUGIN, GMSH_MESH_PLUGIN, GMSH_POSTPRO_PLUGIN};
/* returns the type of plugin for downcasting GMSH_Plugin into
GMSH_CAD_Plugin, GMSH_Mesh_Plugin and GMSH_Post_Plugin */
virtual GMSH_PLUGIN_TYPE getType() const = 0;
virtual void getName (char *name);
virtual void getInfos (char *author,
char *copyright,
char *help_text) const = 0;
/* When an error is thrown by the plugin, the plugin manager
will show the message and hopefully continue */
virtual void CatchErrorMessage (char *errorMessage) const = 0;
/* gmsh style option, ca be loaded, saved and set*/
virtual void SetOption (char *optionName, void *optionValue) = 0;
virtual int getNbOptions() const;
virtual void GetOption (char *optionName, void *optionValue) const = 0;
};
class GMSH_PluginManager
{
/**
Registering all default plugins that are in $(GMSHPLUGINSHOME)
In fact, we will load all .so files in dir $(GMSHPLUGINSHOME)
*/
void RegisterDefaultPlugins();
GMSH_PluginManager();
~GMSH_PluginManager();
static GMSH_PluginManager *instance;
PluginContainer* allPlugins;
public :
static GMSH_PluginManager *Instance();
/** Dynamically add a plugin pluginName.so in dirName*/
void AddPlugin(char *dirName, char *pluginName);
void CallPlugin (char *name);
void DestroyPlugin (char *name);
void SetPluginOption (char *pluginName, char *option, void *value);
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment