From c443aaa23e079d8ab94942bfefa65b940c1acd01 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Sun, 13 Jan 2013 03:20:15 +0100 Subject: Fixed bugs intriduced by PIMPL --- src/uscxml/Factory.cpp | 6 +++--- src/uscxml/Factory.h | 12 +++++++----- src/uscxml/Interpreter.cpp | 1 + src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp | 8 ++++---- src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h | 2 +- src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp | 4 ++-- src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h | 2 +- .../plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp | 4 ++-- .../plugins/invoker/graphics/openscenegraph/OSGInvoker.h | 2 +- src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp | 4 ++-- src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h | 2 +- src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 10 ++++++---- src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h | 2 +- src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp | 4 ++-- src/uscxml/plugins/invoker/umundo/UmundoInvoker.h | 2 +- .../ioprocessor/basichttp/libevent/EventIOProcessor.cpp | 6 +++--- .../ioprocessor/basichttp/libevent/EventIOProcessor.h | 2 +- test/CMakeLists.txt | 3 +-- test/src/test-arabica-events.cpp | 5 +++++ 19 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index 478d282..3220225 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -175,7 +175,7 @@ boost::shared_ptr Factory::createInvoker(const std::string& type, I if (factory->_invokers.find(canonicalName) == factory->_invokers.end()) return boost::shared_ptr(); - return boost::shared_ptr(factory->_invokers[canonicalName]->create(interpreter)); + return boost::static_pointer_cast(factory->_invokers[canonicalName]->create(interpreter)); } boost::shared_ptr Factory::createDataModel(const std::string& type, Interpreter* interpreter) { @@ -187,7 +187,7 @@ boost::shared_ptr Factory::createDataModel(const std::string& typ if (factory->_dataModels.find(canonicalName) == factory->_dataModels.end()) return boost::shared_ptr(); - return boost::shared_ptr(factory->_dataModels[canonicalName]->create(interpreter)); + return factory->_dataModels[canonicalName]->create(interpreter); } boost::shared_ptr Factory::createIOProcessor(const std::string& type, Interpreter* interpreter) { @@ -199,7 +199,7 @@ boost::shared_ptr Factory::createIOProcessor(const std::string& if (factory->_ioProcessors.find(canonicalName) == factory->_ioProcessors.end()) return boost::shared_ptr(); - return boost::shared_ptr(factory->_ioProcessors[canonicalName]->create(interpreter)); + return factory->_ioProcessors[canonicalName]->create(interpreter); } diff --git a/src/uscxml/Factory.h b/src/uscxml/Factory.h index 09bab7b..29f7f9a 100644 --- a/src/uscxml/Factory.h +++ b/src/uscxml/Factory.h @@ -29,17 +29,19 @@ template T strTo(std::string tmp) { class Interpreter; +#if 0 class ExecutableContent { public: ExecutableContent() {}; - virtual ExecutableContent* create(Interpreter* interpreter) = 0; + virtual boost::shared_ptr* create(Interpreter* interpreter) = 0; }; - +#endif + class IOProcessorImpl { public: IOProcessorImpl() {}; virtual ~IOProcessorImpl() {}; - virtual IOProcessorImpl* create(Interpreter* interpreter) = 0; + virtual boost::shared_ptr create(Interpreter* interpreter) = 0; virtual std::set getNames() = 0; virtual void setInterpreter(Interpreter* interpreter) { @@ -80,7 +82,7 @@ class InvokerImpl : public IOProcessorImpl { public: virtual void invoke(const InvokeRequest& req) = 0; virtual void sendToParent(const SendRequest& req) = 0; - virtual InvokerImpl* create(Interpreter* interpreter) = 0; + virtual boost::shared_ptr create(Interpreter* interpreter) = 0; }; class Invoker : public IOProcessor { @@ -110,7 +112,7 @@ protected: class DataModelImpl { public: virtual ~DataModelImpl() {} - virtual DataModelImpl* create(Interpreter* interpreter) = 0; + virtual boost::shared_ptr create(Interpreter* interpreter) = 0; virtual std::set getNames() = 0; virtual bool validate(const std::string& location, const std::string& schema) = 0; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 5681ff9..45ef4b2 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -120,6 +120,7 @@ Interpreter* Interpreter::fromInputSource(Arabica::SAX::InputSource LOG(ERROR) << source.getSystemId() << ": no such file"; } } + delete interpreter; return NULL; } else { interpreter->_document = interpreter->Arabica::SAX2DOM::Parser::getDocument(); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 5ab9b3e..1aa181e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -23,8 +23,8 @@ V8DataModel::V8DataModel() { // _contexts.push_back(v8::Context::New()); } -DataModelImpl* V8DataModel::create(Interpreter* interpreter) { - V8DataModel* dm = new V8DataModel(); +boost::shared_ptr V8DataModel::create(Interpreter* interpreter) { + boost::shared_ptr dm = boost::shared_ptr(new V8DataModel()); dm->_interpreter = interpreter; v8::Locker locker; v8::HandleScope scope; @@ -38,8 +38,8 @@ DataModelImpl* V8DataModel::create(Interpreter* interpreter) { // some free functions v8::Handle global = v8::ObjectTemplate::New(); - global->Set(v8::String::New("In"), v8::FunctionTemplate::New(jsIn, v8::External::New(reinterpret_cast(dm))), v8::ReadOnly); - global->Set(v8::String::New("print"), v8::FunctionTemplate::New(jsPrint, v8::External::New(reinterpret_cast(dm))), v8::ReadOnly); + global->Set(v8::String::New("In"), v8::FunctionTemplate::New(jsIn, v8::External::New(reinterpret_cast(dm.get()))), v8::ReadOnly); + global->Set(v8::String::New("print"), v8::FunctionTemplate::New(jsPrint, v8::External::New(reinterpret_cast(dm.get()))), v8::ReadOnly); v8::Persistent context = v8::Context::New(0, global); v8::Context::Scope contextScope(context); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index e5c1bc8..7e7bb8d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -21,7 +21,7 @@ class V8DataModel : public DataModelImpl { public: V8DataModel(); virtual ~V8DataModel(); - virtual DataModelImpl* create(Interpreter* interpreter); + virtual boost::shared_ptr create(Interpreter* interpreter); virtual std::set getNames() { std::set names; diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index 3e20867..5a33080 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -20,8 +20,8 @@ bool connect(pluma::Host& host) { SWIDataModel::SWIDataModel() { } -DataModelImpl* SWIDataModel::create(Interpreter* interpreter) { - SWIDataModel* dm = new SWIDataModel(); +boost::shared_ptr SWIDataModel::create(Interpreter* interpreter) { + boost::shared_ptr dm = boost::shared_ptr(new SWIDataModel()); dm->_interpreter = interpreter; const char* swiPath = SWI_LIBRARY_PATH; dm->_plEngine = new PlEngine((char*)swiPath); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index f5f5247..1d5a454 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -15,7 +15,7 @@ class SWIDataModel : public DataModelImpl { public: SWIDataModel(); virtual ~SWIDataModel(); - virtual DataModelImpl* create(Interpreter* interpreter); + virtual boost::shared_ptr create(Interpreter* interpreter); virtual std::set getNames() { std::set names; diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp index 94156c0..08fc1f3 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp @@ -22,8 +22,8 @@ OSGInvoker::OSGInvoker() { OSGInvoker::~OSGInvoker() { }; -InvokerImpl* OSGInvoker::create(Interpreter* interpreter) { - OSGInvoker* invoker = new OSGInvoker(); +boost::shared_ptr OSGInvoker::create(Interpreter* interpreter) { + boost::shared_ptr invoker = boost::shared_ptr (new OSGInvoker()); invoker->_interpreter = interpreter; return invoker; } diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h index 933ee4a..29f950f 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h @@ -20,7 +20,7 @@ class OSGInvoker : public InvokerImpl, public Arabica::DOM::Events::EventListene public: OSGInvoker(); virtual ~OSGInvoker(); - virtual InvokerImpl* create(Interpreter* interpreter); + virtual boost::shared_ptr create(Interpreter* interpreter); virtual std::set getNames() { std::set names; diff --git a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp index eaf5eba..65eed78 100644 --- a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp +++ b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp @@ -21,8 +21,8 @@ HeartbeatInvoker::HeartbeatInvoker() { HeartbeatInvoker::~HeartbeatInvoker() { }; -InvokerImpl* HeartbeatInvoker::create(Interpreter* interpreter) { - HeartbeatInvoker* invoker = new HeartbeatInvoker(); +boost::shared_ptr HeartbeatInvoker::create(Interpreter* interpreter) { + boost::shared_ptr invoker = boost::shared_ptr(new HeartbeatInvoker()); invoker->_interpreter = interpreter; return invoker; } diff --git a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h index 8a90011..bbea7d6 100644 --- a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h +++ b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h @@ -13,7 +13,7 @@ class HeartbeatInvoker : public InvokerImpl { public: HeartbeatInvoker(); virtual ~HeartbeatInvoker(); - virtual InvokerImpl* create(Interpreter* interpreter); + virtual boost::shared_ptr create(Interpreter* interpreter); virtual std::set getNames() { std::set names; diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index c90ef4d..85f2963 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -23,8 +23,8 @@ USCXMLInvoker::~USCXMLInvoker() { delete _invokedInterpreter; }; -InvokerImpl* USCXMLInvoker::create(Interpreter* interpreter) { - USCXMLInvoker* invoker = new USCXMLInvoker(); +boost::shared_ptr USCXMLInvoker::create(Interpreter* interpreter) { + boost::shared_ptr invoker = boost::shared_ptr(new USCXMLInvoker()); invoker->_parentInterpreter = interpreter; return invoker; } @@ -55,8 +55,10 @@ void USCXMLInvoker::invoke(const InvokeRequest& req) { if (dataModel) { } - _invokedInterpreter->setInvoker(boost::static_pointer_cast(shared_from_this())); - _invokedInterpreter->start(); + if (_invokedInterpreter) { + _invokedInterpreter->setInvoker(boost::static_pointer_cast(shared_from_this())); + _invokedInterpreter->start(); + } } } \ No newline at end of file diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index b1579a2..95de9b2 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -16,7 +16,7 @@ class USCXMLInvoker : public InvokerImpl, public boost::enable_shared_from_this< public: USCXMLInvoker(); virtual ~USCXMLInvoker(); - virtual InvokerImpl* create(Interpreter* interpreter); + virtual boost::shared_ptr create(Interpreter* interpreter); virtual std::set getNames() { std::set names; names.insert("uscxml"); diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp index 3ddc14a..2957078 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp @@ -28,8 +28,8 @@ UmundoInvoker::~UmundoInvoker() { } }; -InvokerImpl* UmundoInvoker::create(Interpreter* interpreter) { - UmundoInvoker* invoker = new UmundoInvoker(); +boost::shared_ptr UmundoInvoker::create(Interpreter* interpreter) { + boost::shared_ptr invoker = boost::shared_ptr(new UmundoInvoker()); invoker->_interpreter = interpreter; return invoker; } diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h index 1aa37f2..c5f9656 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h @@ -20,7 +20,7 @@ class UmundoInvoker : public InvokerImpl, public umundo::TypedReceiver, public u public: UmundoInvoker(); virtual ~UmundoInvoker(); - virtual InvokerImpl* create(Interpreter* interpreter); + virtual boost::shared_ptr create(Interpreter* interpreter); virtual std::set getNames() { std::set names; diff --git a/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.cpp index 1607e3e..2b6273c 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.cpp @@ -46,8 +46,8 @@ EventIOProcessor::~EventIOProcessor() { httpServer->unregisterProcessor(this); } -IOProcessorImpl* EventIOProcessor::create(Interpreter* interpreter) { - EventIOProcessor* io = new EventIOProcessor(); +boost::shared_ptr EventIOProcessor::create(Interpreter* interpreter) { + boost::shared_ptr io = boost::shared_ptr(new EventIOProcessor()); io->_interpreter = interpreter; io->_dns = evdns_base_new(io->_asyncQueue._eventLoop, 1); @@ -56,7 +56,7 @@ IOProcessorImpl* EventIOProcessor::create(Interpreter* interpreter) { // register at http server EventIOServer* httpServer = EventIOServer::getInstance(); - httpServer->registerProcessor(io); + httpServer->registerProcessor(io.get()); io->start(); return io; diff --git a/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h b/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h index d3557f4..c90bf79 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h @@ -28,7 +28,7 @@ public: EventIOProcessor(); virtual ~EventIOProcessor(); - virtual IOProcessorImpl* create(uscxml::Interpreter* interpreter); + virtual boost::shared_ptr create(uscxml::Interpreter* interpreter); virtual std::set getNames() { std::set names; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 353faa2..ae6d07f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,7 +30,6 @@ endif() if (OPENSCENEGRAPH_FOUND) add_executable(test-osg src/test-osg.cpp) target_link_libraries(test-osg uscxml) - add_test(test-osg ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-prolog-swi) set_target_properties(test-osg PROPERTIES FOLDER "Tests") endif() @@ -51,7 +50,7 @@ set_target_properties(test-completion PROPERTIES FOLDER "Tests") add_executable(test-arabica-events src/test-arabica-events.cpp) target_link_libraries(test-arabica-events uscxml) -add_test(test-arabica-events ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-arabica-events ${CMAKE_SOURCE_DIR}/test/samples/arabica/test-arabica-events.xml) +add_test(test-arabica-events ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-arabica-events ${CMAKE_SOURCE_DIR}/test/samples/uscxml/arabica/test-arabica-events.xml) set_target_properties(test-arabica-events PROPERTIES FOLDER "Tests") add_executable(test-url src/test-url.cpp) diff --git a/test/src/test-arabica-events.cpp b/test/src/test-arabica-events.cpp index fcf4ea8..13200bb 100644 --- a/test/src/test-arabica-events.cpp +++ b/test/src/test-arabica-events.cpp @@ -22,6 +22,11 @@ public: }; int main(int argc, char** argv) { + if (argc != 2) { + std::cerr << "Expected path to test-arabica-events.xml" << std::endl; + exit(EXIT_FAILURE); + } + Arabica::SAX::InputSource inputSource(argv[1]); Arabica::SAX2DOM::Parser domParser; -- cgit v0.12