From 4ecca617e628e94845dafafbdee46ce57f7bc843 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 23 May 2014 16:14:56 +0200 Subject: Builds as plugins again --- apps/uscxml-browser.cpp | 2 +- apps/uscxml-transform.cpp | 2 +- src/uscxml/Factory.cpp | 33 ++++-- src/uscxml/Factory.h | 13 ++- src/uscxml/Interpreter.cpp | 5 +- src/uscxml/Interpreter.h | 2 +- src/uscxml/plugins/invoker/CMakeLists.txt | 4 +- test/CMakeLists.txt | 3 + test/src/test-datamodel.cpp | 179 ------------------------------ test/src/test-stress.cpp | 2 +- 10 files changed, 49 insertions(+), 196 deletions(-) diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index 037f9a1..cd74154 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -130,7 +130,7 @@ int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); if (options.pluginPath.length() > 0) { - Factory::pluginPath = options.pluginPath; + Factory::setDefaultPluginPath(options.pluginPath); } // setup HTTP server diff --git a/apps/uscxml-transform.cpp b/apps/uscxml-transform.cpp index 09da679..13fc255 100644 --- a/apps/uscxml-transform.cpp +++ b/apps/uscxml-transform.cpp @@ -222,7 +222,7 @@ int main(int argc, char** argv) { // register plugins if (pluginPath.length() > 0) { - Factory::pluginPath = pluginPath; + Factory::setDefaultPluginPath(pluginPath); } // start HTTP server diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index 2c663b2..378f15e 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -126,19 +126,33 @@ namespace uscxml { Factory::Factory(Factory* parentFactory) : _parentFactory(parentFactory) { } -Factory::Factory() { - _parentFactory = NULL; +Factory::Factory(const std::string& pluginPath, Factory* parentFactory) : _parentFactory(parentFactory), _pluginPath(pluginPath) { + registerPlugins(); +} + +Factory::Factory(const std::string& pluginPath) : _parentFactory(NULL), _pluginPath(pluginPath) { + registerPlugins(); +} + +void Factory::setDefaultPluginPath(const std::string& path) { + _defaultPluginPath = path; +} +std::string Factory::getDefaultPluginPath() { + return _defaultPluginPath; +} + +void Factory::registerPlugins() { #ifdef BUILD_AS_PLUGINS - if (pluginPath.length() == 0) { + if (_pluginPath.length() == 0) { // try to read USCXML_PLUGIN_PATH environment variable - pluginPath = (getenv("USCXML_PLUGIN_PATH") != NULL ? getenv("USCXML_PLUGIN_PATH") : ""); + _pluginPath = (getenv("USCXML_PLUGIN_PATH") != NULL ? getenv("USCXML_PLUGIN_PATH") : ""); } - if (pluginPath.length() > 0) { + if (_pluginPath.length() > 0) { pluma.acceptProviderType(); pluma.acceptProviderType(); pluma.acceptProviderType(); pluma.acceptProviderType(); - pluma.loadFromFolder(pluginPath); + pluma.loadFromFolder(_pluginPath); std::vector invokerProviders; pluma.getProviders(invokerProviders); @@ -164,6 +178,9 @@ Factory::Factory() { LOG(WARNING) << "No path to plugins known, export USCXML_PLUGIN_PATH or pass path as parameter"; } #else + if (_pluginPath.length() > 0) + LOG(WARNING) << "Plugin path is given, but uscxml is compiled without support"; + #if 1 # if (defined UMUNDO_FOUND && defined PROTOBUF_FOUND) { @@ -573,7 +590,7 @@ size_t DataModelImpl::replaceExpressions(std::string& content) { Factory* Factory::getInstance() { if (_instance == NULL) { - _instance = new Factory(); + _instance = new Factory(Factory::_defaultPluginPath); } return _instance; } @@ -625,5 +642,5 @@ void DataModelImpl::throwErrorPlatform(const std::string& cause) { Factory* Factory::_instance = NULL; -std::string Factory::pluginPath; +std::string Factory::_defaultPluginPath; } \ No newline at end of file diff --git a/src/uscxml/Factory.h b/src/uscxml/Factory.h index 02ce6b8..3a3080a 100644 --- a/src/uscxml/Factory.h +++ b/src/uscxml/Factory.h @@ -23,6 +23,7 @@ #include "uscxml/Common.h" #include "uscxml/Message.h" #include "uscxml/Convenience.h" +#include #ifdef BUILD_AS_PLUGINS #include "Pluma/Pluma.hpp" @@ -438,6 +439,7 @@ protected: class USCXML_API Factory { public: Factory(Factory* parentFactory); + Factory(const std::string& pluginPath, Factory* parentFactory); void registerIOProcessor(IOProcessorImpl* ioProcessor); void registerDataModel(DataModelImpl* dataModel); @@ -453,6 +455,9 @@ public: static Factory* getInstance(); + static void setDefaultPluginPath(const std::string& path); + static std::string getDefaultPluginPath(); + std::map _dataModels; std::map _dataModelAliases; std::map _ioProcessors; @@ -461,17 +466,19 @@ public: std::map _invokerAliases; std::map, ExecutableContentImpl*> _executableContent; - static std::string pluginPath; - protected: #ifdef BUILD_AS_PLUGINS pluma::Pluma pluma; #endif - Factory(); + void registerPlugins(); + + Factory(const std::string&); ~Factory(); Factory* _parentFactory; + std::string _pluginPath; static Factory* _instance; + static std::string _defaultPluginPath; }; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index e2ee1da..0afdf04 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -104,9 +104,12 @@ void InterpreterOptions::printUsageAndExit(const char* progName) { printf(" \\\n\t\t[URLN [--disable-http] [--optionN=valueN --optionM=valueM]]"); printf("\n"); printf("Options\n"); +#ifdef BUILD_AS_PLUGINS + printf("\t-p : path to the uSCXML plugins (or export USCXML_PLUGIN_PATH)\n"); +#endif printf("\t-v : be verbose\n"); printf("\t-d : enable debugging via HTTP\n"); - printf("\t-lN : Set loglevel to N\n"); + printf("\t-lN : set loglevel to N\n"); printf("\t-tN : port for HTTP server\n"); printf("\t-sN : port for HTTPS server\n"); printf("\t-wN : port for WebSocket server\n"); diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 93062e6..3a02cb7 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -138,7 +138,7 @@ public: }; -class NameSpaceInfo { +class USCXML_API NameSpaceInfo { public: NameSpaceInfo() : nsContext(NULL) { init(std::map()); diff --git a/src/uscxml/plugins/invoker/CMakeLists.txt b/src/uscxml/plugins/invoker/CMakeLists.txt index ceb9c90..301f04a 100644 --- a/src/uscxml/plugins/invoker/CMakeLists.txt +++ b/src/uscxml/plugins/invoker/CMakeLists.txt @@ -474,8 +474,10 @@ if (MILES_FOUND) ${MILES_LIBRARIES} ${OPENAL_LIBRARY} ${JPEG_LIBRARIES} - ${ICONV_LIBRARIES} uscxml) + if (ICONV_FOUND) + target_link_libraries(invoker_miles ${ICONV_LIBRARIES}) + endif() set_target_properties(invoker_miles PROPERTIES FOLDER "Plugin Invoker") else() list (APPEND USCXML_FILES ${MILES_INVOKER}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b655384..03fd22c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -107,6 +107,9 @@ set_target_properties(test-url PROPERTIES FOLDER "Tests") add_executable(test-promela-parser src/test-promela-parser.cpp) target_link_libraries(test-promela-parser uscxml) +if (BUILD_AS_PLUGINS) + target_link_libraries(test-promela-parser datamodel_promela) +endif() add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-promela-parser) set_target_properties(test-promela-parser PROPERTIES FOLDER "Tests") diff --git a/test/src/test-datamodel.cpp b/test/src/test-datamodel.cpp index 58f7030..2dced50 100644 --- a/test/src/test-datamodel.cpp +++ b/test/src/test-datamodel.cpp @@ -12,191 +12,12 @@ using namespace uscxml; using namespace boost; -class TestData { -public: - enum Type { - VERBATIM, - INTERPRETED, - }; - - TestData() : type(INTERPRETED) {} - - // TODO: default INTERPRETED is unfortunate - TestData(const std::string& atom_, Type type_ = INTERPRETED) : atom(atom_), type(type_) {} - TestData(const char* data, size_t size, const std::string& mimeType, bool adopt = false); - - // convenience constructors - TestData(short atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(int atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(unsigned int atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(long atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(unsigned long atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(float atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(double atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - TestData(bool atom_) : type(INTERPRETED) { - if (atom_) { - atom = "true"; - } else { - atom = "false"; - } - } - - template TestData(T value, Type type_) : atom(toStr(value)), type(type_) {} - -#if 0 - // constructor for arbitrary types, skip if type is subclass though (C++11) - // we will have to drop this constructor as it interferes with operator Data() and entails C++11 - template - Data(T value, typename std::enable_if::value>::type* = nullptr) - : atom(toStr(value)), type(INTERPRETED) {} -#endif - - - explicit TestData(const Arabica::DOM::Node& dom); - virtual ~TestData() {} - - explicit operator bool() const { - return (atom.length() > 0 || !compound.empty() || !array.empty() || binary || node); - } - - bool hasKey(const std::string& key) const { - return (!compound.empty() && compound.find(key) != compound.end()); - } - - TestData& operator[](const std::string& key) { - return operator[](key.c_str()); - } - - TestData& operator[](const char* key) { - return compound[key]; - } - - TestData& operator[](const size_t index) { - while(array.size() < index) { - array.push_back(TestData("", TestData::VERBATIM)); - } - std::list::iterator arrayIter = array.begin(); - for (int i = 0; i < index; i++, arrayIter++) {} - return *arrayIter; - } - - const TestData at(const std::string& key) const { - return at(key.c_str()); - } - - const TestData at(const char* key) const { - if (hasKey(key)) - return compound.at(key); - TestData data; - return data; - } - - const TestData item(const size_t index) const { - if (array.size() < index) { - std::list::const_iterator arrayIter; - for (int i = 0; i < index; i++, arrayIter++) {} - return *arrayIter; - } - TestData data; - return data; - } - - bool operator==(const TestData &other) const { - if (other.atom.size() != atom.size()) - return false; - if (other.type != type) - return false; - if (other.binary != binary) - return false; - if (other.array.size() != array.size()) - return false; - if (other.compound.size() != compound.size()) - return false; - - if (other.atom != atom) - return false; - if (other.array != array) - return false; - if (other.compound != compound) - return false; - if (other.node != node) - return false; - - return true; - } - - bool operator!=(const TestData &other) const { - return !(*this == other); - } - - operator std::string() const { - return atom; - } - - operator std::map() { - return compound; - } - - operator std::list() { - return array; - } - - std::map getCompound() { - return compound; - } - void setCompound(const std::map& compound) { - this->compound = compound; - } - - std::list getArray() { - return array; - } - void setArray(const std::list& array) { - this->array = array; - } - - std::string getAtom() { - return atom; - } - void setAtom(const std::string& atom) { - this->atom = atom; - } - - Type getType() { - return type; - } - void setType(const Type type) { - this->type = type; - } - - Arabica::DOM::Node node; - std::map compound; - std::list array; - std::string atom; - boost::shared_ptr binary; - Type type; - -}; - - - -void testConstData(const TestData& data) { -// std::cout << data.at("foo") << std::endl; -} int main(int argc, char** argv) { #ifdef _WIN32 WSADATA wsaData; WSAStartup(MAKEWORD(2, 2), &wsaData); #endif - - { - TestData data; - data["foo"] = "bar"; - testConstData(data); -// std::cout << data << std::endl; - } - exit(0); Interpreter interpreter = Interpreter::fromXML(""); DataModel dm(Factory::getInstance()->createDataModel("ecmascript", interpreter.getImpl().get())); diff --git a/test/src/test-stress.cpp b/test/src/test-stress.cpp index 6cce172..6d28829 100644 --- a/test/src/test-stress.cpp +++ b/test/src/test-stress.cpp @@ -134,7 +134,7 @@ int main(int argc, char** argv) { google::InitGoogleLogging(optarg); break; case 'p': - uscxml::Factory::pluginPath = optarg; + uscxml::Factory::setDefaultPluginPath(optarg); break; case '?': break; -- cgit v0.12