summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@unpythonic.net>2010-11-16 21:25:37 -0600
committerJeff Epler <jepler@dsndata.com>2012-03-09 15:03:18 -0600
commit48f8ad0397abcd32ad318f8e3dfa9d19a8641531 (patch)
treec440eeb8567d723403ac18a161c343070501d532
parent20cb3efccc87d424342ff1177ec9e6234c5139e4 (diff)
downloadlinuxcnc-48f8ad0397abcd32ad318f8e3dfa9d19a8641531.tar.gz
linuxcnc-48f8ad0397abcd32ad318f8e3dfa9d19a8641531.zip
interp: allow creation of pluggable interpreters
-rw-r--r--src/emc/rs274ngc/Submakefile2
-rw-r--r--src/emc/rs274ngc/interp_base.cc34
-rw-r--r--src/emc/rs274ngc/interp_base.hh3
3 files changed, 38 insertions, 1 deletions
diff --git a/src/emc/rs274ngc/Submakefile b/src/emc/rs274ngc/Submakefile
index 72a74f9e8..2145bfbde 100644
--- a/src/emc/rs274ngc/Submakefile
+++ b/src/emc/rs274ngc/Submakefile
@@ -36,7 +36,7 @@ TARGETS += ../lib/librs274.so ../lib/librs274.so.0
$(ECHO) Linking $(notdir $@)
@mkdir -p ../lib
@rm -f $@
- $(CXX) -g $(LDFLAGS) -Wl,-soname,$(notdir $@) -shared -o $@ $^ -lstdc++ $(BOOST_PYTHON_LIBS) -l$(LIBPYTHON)
+ $(CXX) -g $(LDFLAGS) -Wl,-soname,$(notdir $@) -shared -o $@ $^ -lstdc++ $(BOOST_PYTHON_LIBS) -l$(LIBPYTHON) -ldl
../include/%.h: ./emc/rs274ngc/%.h
cp $^ $@
diff --git a/src/emc/rs274ngc/interp_base.cc b/src/emc/rs274ngc/interp_base.cc
index 4697bba4d..f19880bb2 100644
--- a/src/emc/rs274ngc/interp_base.cc
+++ b/src/emc/rs274ngc/interp_base.cc
@@ -1,2 +1,36 @@
#include "interp_base.hh"
+#include <dlfcn.h>
+#include <limits.h>
+#include <config.h>
+#include <stdio.h>
+
InterpBase::~InterpBase() {}
+
+InterpBase *interp_from_shlib(const char *shlib) {
+ fprintf(stderr, "interp_from_shlib(%s)\n", shlib);
+ dlopen(NULL, RTLD_GLOBAL);
+ void *interp_lib = dlopen(shlib, RTLD_NOW);
+ if(!interp_lib) {
+ fprintf(stderr, "emcTaskInit: could not open interpreter '%s': %s\n", shlib, dlerror());
+ char relative_interp[PATH_MAX];
+ snprintf(relative_interp, sizeof(relative_interp), "%s/%s",
+ EMC2_HOME "/lib/emc2", shlib);
+ interp_lib = dlopen(relative_interp, RTLD_NOW);
+ }
+ if(!interp_lib) {
+ fprintf(stderr, "emcTaskInit: could not open interpreter '%s': %s\n", shlib, dlerror());
+ return 0;
+ }
+ typedef InterpBase* (*Constructor)();
+ Constructor constructor = (Constructor)dlsym(interp_lib, "makeInterp");
+ if(!constructor) {
+ fprintf(stderr, "emcTaskInit: could not get symbol makeInterp from interpreter '%s': %s\n", shlib, dlerror());
+ return 0;
+ }
+ InterpBase *pinterp = constructor();
+ if(!pinterp) {
+ fprintf(stderr, "emcTaskInit: makeInterp() returned NULL from interpreter '%s'\n", shlib);
+ return 0;
+ }
+ return pinterp;
+}
diff --git a/src/emc/rs274ngc/interp_base.hh b/src/emc/rs274ngc/interp_base.hh
index 8c8952e22..24496121f 100644
--- a/src/emc/rs274ngc/interp_base.hh
+++ b/src/emc/rs274ngc/interp_base.hh
@@ -36,3 +36,6 @@ public:
virtual void active_settings(double active_settings[ACTIVE_SETTINGS]) = 0;
virtual void set_loglevel(int level) = 0;
};
+
+InterpBase *interp_from_shlib(const char *shlib);
+extern "C" InterpBase *makeInterp();