diff options
author | Michael Haberler <git@mah.priv.at> | 2011-07-21 11:11:29 +0200 |
---|---|---|
committer | Michael Haberler <git@mah.priv.at> | 2011-10-28 08:25:53 +0200 |
commit | 57435cb537afed0619e11ca9125fef29bcf39f40 (patch) | |
tree | 2128e97406e6630474cf1283812cd5f17dadc767 /src/emc/pythonplugin | |
parent | 0e7e01aa0e374570a89e6088895024ad9458528b (diff) | |
download | linuxcnc-57435cb537afed0619e11ca9125fef29bcf39f40.tar.gz linuxcnc-57435cb537afed0619e11ca9125fef29bcf39f40.zip |
python plugin: make it a singleton
Diffstat (limited to 'src/emc/pythonplugin')
-rw-r--r-- | src/emc/pythonplugin/python_plugin.cc | 7 | ||||
-rw-r--r-- | src/emc/pythonplugin/python_plugin.hh | 14 | ||||
-rw-r--r-- | src/emc/pythonplugin/testpp.cc | 4 |
3 files changed, 18 insertions, 7 deletions
diff --git a/src/emc/pythonplugin/python_plugin.cc b/src/emc/pythonplugin/python_plugin.cc index 2e1416113..2c6a8d863 100644 --- a/src/emc/pythonplugin/python_plugin.cc +++ b/src/emc/pythonplugin/python_plugin.cc @@ -3,7 +3,7 @@ #include <stdio.h> #include <stdlib.h> -#define MAX_ERRMSG_SIZE 200 +#define MAX_ERRMSG_SIZE 256 #define ERRMSG(fmt, args...) \ do { \ @@ -278,4 +278,9 @@ std::string PythonPlugin::handle_pyerror() return bp::extract<std::string>(formatted); } +PythonPlugin& PythonPlugin::getInstance() +{ + static PythonPlugin instance; + return instance; +} diff --git a/src/emc/pythonplugin/python_plugin.hh b/src/emc/pythonplugin/python_plugin.hh index 5dbd40a4d..ebf5db728 100644 --- a/src/emc/pythonplugin/python_plugin.hh +++ b/src/emc/pythonplugin/python_plugin.hh @@ -18,10 +18,9 @@ enum pymod_stat {PYMOD_NONE=0, PYMOD_FAILED=1,PYMOD_OK=2}; class PythonPlugin { - public: - PythonPlugin(int loglevel = 0); - ~PythonPlugin(); + static PythonPlugin& getInstance(); + int setup(const char *modpath, const char *module, bool reload_if_changed = false); int add_inittab_entry(const char *mod_name, void (*mod_init)()); int initialize(bool reload = false); @@ -31,10 +30,15 @@ public: bool is_callable(const char *module, const char *funcname); int plugin_status(); - std::string last_exception(); - std::string last_errmsg(); private: + PythonPlugin(int loglevel = 0); // no public constructor + PythonPlugin(const PythonPlugin &) {}; // not copyable + PythonPlugin & operator=(const PythonPlugin&) { return *this; }; // not assignable + ~PythonPlugin(); // no public destructor + + std::string last_exception(); + std::string last_errmsg(); int reload(); std::string handle_pyerror(); diff --git a/src/emc/pythonplugin/testpp.cc b/src/emc/pythonplugin/testpp.cc index 7a0a163f7..8acb7de35 100644 --- a/src/emc/pythonplugin/testpp.cc +++ b/src/emc/pythonplugin/testpp.cc @@ -34,7 +34,9 @@ main (int argc, char **argv) char *callablemod = NULL; char *xcallable = NULL; - PythonPlugin pp; + PythonPlugin &pp = PythonPlugin::getInstance(); // creates a singleton instance + // PythonPlugin two = pp; // this fails since copy constructor is private. + // PythonPlugin &second = PythonPlugin::getInstance(); // returns the singleton instance opterr = 0; |