diff options
Diffstat (limited to 'src/uscxml/plugins/invoker')
8 files changed, 51 insertions, 49 deletions
diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp index 7a0e63a..94156c0 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp @@ -22,7 +22,7 @@ OSGInvoker::OSGInvoker() { OSGInvoker::~OSGInvoker() { }; -Invoker* OSGInvoker::create(Interpreter* interpreter) { +InvokerImpl* OSGInvoker::create(Interpreter* interpreter) { OSGInvoker* invoker = new OSGInvoker(); invoker->_interpreter = interpreter; return invoker; @@ -33,16 +33,16 @@ Data OSGInvoker::getDataModelVariables() { return data; } -void OSGInvoker::send(SendRequest& req) { +void OSGInvoker::send(const SendRequest& req) { } void OSGInvoker::cancel(const std::string sendId) { } -void OSGInvoker::sendToParent(SendRequest& req) { +void OSGInvoker::sendToParent(const SendRequest& req) { } -void OSGInvoker::invoke(InvokeRequest& req) { +void OSGInvoker::invoke(const InvokeRequest& req) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); // register default event handlers diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h index 90dda31..933ee4a 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h @@ -16,11 +16,11 @@ namespace uscxml { -class OSGInvoker : public Invoker, public Arabica::DOM::Events::EventListener<std::string> { +class OSGInvoker : public InvokerImpl, public Arabica::DOM::Events::EventListener<std::string> { public: OSGInvoker(); virtual ~OSGInvoker(); - virtual Invoker* create(Interpreter* interpreter); + virtual InvokerImpl* create(Interpreter* interpreter); virtual std::set<std::string> getNames() { std::set<std::string> names; @@ -31,10 +31,10 @@ public: } virtual Data getDataModelVariables(); - virtual void send(SendRequest& req); + virtual void send(const SendRequest& req); virtual void cancel(const std::string sendId); - virtual void invoke(InvokeRequest& req); - virtual void sendToParent(SendRequest& req); + virtual void invoke(const InvokeRequest& req); + virtual void sendToParent(const SendRequest& req); virtual void handleEvent(Arabica::DOM::Events::Event<std::string>& event); virtual void runOnMainThread(); diff --git a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp index 6bc06d9..eaf5eba 100644 --- a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp +++ b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp @@ -21,7 +21,7 @@ HeartbeatInvoker::HeartbeatInvoker() { HeartbeatInvoker::~HeartbeatInvoker() { }; -Invoker* HeartbeatInvoker::create(Interpreter* interpreter) { +InvokerImpl* HeartbeatInvoker::create(Interpreter* interpreter) { HeartbeatInvoker* invoker = new HeartbeatInvoker(); invoker->_interpreter = interpreter; return invoker; @@ -32,23 +32,23 @@ Data HeartbeatInvoker::getDataModelVariables() { return data; } -void HeartbeatInvoker::send(SendRequest& req) { +void HeartbeatInvoker::send(const SendRequest& req) { } void HeartbeatInvoker::cancel(const std::string sendId) { HeartbeatDispatcher::getInstance()->cancelEvent(toStr(this)); } -void HeartbeatInvoker::sendToParent(SendRequest& req) { +void HeartbeatInvoker::sendToParent(const SendRequest& req) { } -void HeartbeatInvoker::invoke(InvokeRequest& req) { +void HeartbeatInvoker::invoke(const InvokeRequest& req) { _invokeId = req.invokeid; _event.invokeid = _invokeId; std::string intervalStr; double interval = 0; unsigned long intervalMs = 0; - InvokeRequest::params_t::iterator paramIter = req.params.begin(); + InvokeRequest::params_t::const_iterator paramIter = req.params.begin(); while(paramIter != req.params.end()) { if (boost::iequals(paramIter->first, "interval")) { intervalStr = paramIter->second; diff --git a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h index 9a6cb47..8a90011 100644 --- a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h +++ b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h @@ -9,11 +9,11 @@ namespace uscxml { -class HeartbeatInvoker : public Invoker { +class HeartbeatInvoker : public InvokerImpl { public: HeartbeatInvoker(); virtual ~HeartbeatInvoker(); - virtual Invoker* create(Interpreter* interpreter); + virtual InvokerImpl* create(Interpreter* interpreter); virtual std::set<std::string> getNames() { std::set<std::string> names; @@ -23,10 +23,10 @@ public: } virtual Data getDataModelVariables(); - virtual void send(SendRequest& req); + virtual void send(const SendRequest& req); virtual void cancel(const std::string sendId); - virtual void invoke(InvokeRequest& req); - virtual void sendToParent(SendRequest& req); + virtual void invoke(const InvokeRequest& req); + virtual void sendToParent(const SendRequest& req); static void dispatch(void* instance, std::string name); diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index b4ee3eb..c90ef4d 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -23,7 +23,7 @@ USCXMLInvoker::~USCXMLInvoker() { delete _invokedInterpreter; }; -Invoker* USCXMLInvoker::create(Interpreter* interpreter) { +InvokerImpl* USCXMLInvoker::create(Interpreter* interpreter) { USCXMLInvoker* invoker = new USCXMLInvoker(); invoker->_parentInterpreter = interpreter; return invoker; @@ -34,7 +34,7 @@ Data USCXMLInvoker::getDataModelVariables() { return data; } -void USCXMLInvoker::send(SendRequest& req) { +void USCXMLInvoker::send(const SendRequest& req) { assert(false); } @@ -42,19 +42,20 @@ void USCXMLInvoker::cancel(const std::string sendId) { assert(false); } -void USCXMLInvoker::sendToParent(SendRequest& req) { - req.invokeid = _invokeId; - _parentInterpreter->receive(req); +void USCXMLInvoker::sendToParent(const SendRequest& req) { + SendRequest parentReq = req; + parentReq.invokeid = _invokeId; + _parentInterpreter->receive(parentReq); } -void USCXMLInvoker::invoke(InvokeRequest& req) { +void USCXMLInvoker::invoke(const InvokeRequest& req) { _invokeId = req.invokeid; _invokedInterpreter = Interpreter::fromURI(req.src); - DataModel* dataModel = _invokedInterpreter->getDataModel(); - if (dataModel != NULL) { + DataModel dataModel(_invokedInterpreter->getDataModel()); + if (dataModel) { } - _invokedInterpreter->setInvoker(this); + _invokedInterpreter->setInvoker(boost::static_pointer_cast<InvokerImpl>(shared_from_this())); _invokedInterpreter->start(); } diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index 907df41..b1579a2 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -2,6 +2,7 @@ #define USCXMLINVOKER_H_OQFA21IO #include <uscxml/Interpreter.h> +#include <boost//enable_shared_from_this.hpp> #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" @@ -11,11 +12,11 @@ namespace uscxml { class Interpreter; -class USCXMLInvoker : public Invoker { +class USCXMLInvoker : public InvokerImpl, public boost::enable_shared_from_this<USCXMLInvoker> { public: USCXMLInvoker(); virtual ~USCXMLInvoker(); - virtual Invoker* create(Interpreter* interpreter); + virtual InvokerImpl* create(Interpreter* interpreter); virtual std::set<std::string> getNames() { std::set<std::string> names; names.insert("uscxml"); @@ -25,10 +26,10 @@ public: } virtual Data getDataModelVariables(); - virtual void send(SendRequest& req); + virtual void send(const SendRequest& req); virtual void cancel(const std::string sendId); - virtual void invoke(InvokeRequest& req); - virtual void sendToParent(SendRequest& req); + virtual void invoke(const InvokeRequest& req); + virtual void sendToParent(const SendRequest& req); protected: std::string _invokeId; diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp index 9957bfa..3ddc14a 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp @@ -28,7 +28,7 @@ UmundoInvoker::~UmundoInvoker() { } }; -Invoker* UmundoInvoker::create(Interpreter* interpreter) { +InvokerImpl* UmundoInvoker::create(Interpreter* interpreter) { UmundoInvoker* invoker = new UmundoInvoker(); invoker->_interpreter = interpreter; return invoker; @@ -39,7 +39,7 @@ Data UmundoInvoker::getDataModelVariables() { return data; } -void UmundoInvoker::send(SendRequest& req) { +void UmundoInvoker::send(const SendRequest& req) { umundo::Message* msg = new umundo::Message(); if (req.name.length() > 0) { @@ -50,9 +50,9 @@ void UmundoInvoker::send(SendRequest& req) { if (req.params.find("type") != req.params.end()) { // assume JSON in content to transform to protobuf object - if (req.content.length() > 0 && _interpreter->getDataModel() != NULL) { + if (req.content.length() > 0 && _interpreter->getDataModel()) { std::string type; - std::multimap<std::string, std::string>::iterator typeIter = req.params.find("type"); + std::multimap<std::string, std::string>::const_iterator typeIter = req.params.find("type"); if (typeIter != req.params.end()) type = typeIter->second; const google::protobuf::Message* protoMsg = umundo::PBSerializer::getProto(type); @@ -61,7 +61,7 @@ void UmundoInvoker::send(SendRequest& req) { return; } try { - Data data = _interpreter->getDataModel()->getStringAsData(req.content); + Data data = _interpreter->getDataModel().getStringAsData(req.content); google::protobuf::Message* pbMsg = protoMsg->New(); if (!dataToProtobuf(pbMsg, data)) { LOG(ERROR) << "Cannot create message from JSON - not sending"; @@ -105,11 +105,11 @@ void UmundoInvoker::cancel(const std::string sendId) { assert(false); } -void UmundoInvoker::sendToParent(SendRequest& req) { +void UmundoInvoker::sendToParent(const SendRequest& req) { assert(false); } -void UmundoInvoker::invoke(InvokeRequest& req) { +void UmundoInvoker::invoke(const InvokeRequest& req) { _invokeId = req.invokeid; std::string domain; @@ -133,8 +133,8 @@ void UmundoInvoker::invoke(InvokeRequest& req) { // add type from .proto or .desc files if (req.params.find("type") != req.params.end()) { - std::pair<InvokeRequest::params_t::iterator, InvokeRequest::params_t::iterator> typeRange = req.params.equal_range("types"); - for (InvokeRequest::params_t::iterator it = typeRange.first; it != typeRange.second; it++) { + std::pair<InvokeRequest::params_t::const_iterator, InvokeRequest::params_t::const_iterator> typeRange = req.params.equal_range("types"); + for (InvokeRequest::params_t::const_iterator it = typeRange.first; it != typeRange.second; it++) { URL typeURI(it->second); if (typeURI.toAbsolute(_interpreter->getBaseURI())) { std::string filename = typeURI.asLocalFile(".proto"); @@ -147,8 +147,8 @@ void UmundoInvoker::invoke(InvokeRequest& req) { // add directory with .proto or .desc files if (req.params.find("types") != req.params.end()) { - std::pair<InvokeRequest::params_t::iterator, InvokeRequest::params_t::iterator> typeRange = req.params.equal_range("types"); - for (InvokeRequest::params_t::iterator it = typeRange.first; it != typeRange.second; it++) { + std::pair<InvokeRequest::params_t::const_iterator, InvokeRequest::params_t::const_iterator> typeRange = req.params.equal_range("types"); + for (InvokeRequest::params_t::const_iterator it = typeRange.first; it != typeRange.second; it++) { URL typeURI(it->second); if (typeURI.toAbsolute(_interpreter->getBaseURI()) && typeURI.scheme().compare("file") == 0) { umundo::PBSerializer::addProto(typeURI.path()); diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h index 09d07bf..1aa37f2 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h @@ -16,11 +16,11 @@ namespace uscxml { class Interpreter; -class UmundoInvoker : public Invoker, public umundo::TypedReceiver, public umundo::ResultSet<umundo::ServiceDescription> { +class UmundoInvoker : public InvokerImpl, public umundo::TypedReceiver, public umundo::ResultSet<umundo::ServiceDescription> { public: UmundoInvoker(); virtual ~UmundoInvoker(); - virtual Invoker* create(Interpreter* interpreter); + virtual InvokerImpl* create(Interpreter* interpreter); virtual std::set<std::string> getNames() { std::set<std::string> names; @@ -31,10 +31,10 @@ public: } virtual Data getDataModelVariables(); - virtual void send(SendRequest& req); + virtual void send(const SendRequest& req); virtual void cancel(const std::string sendId); - virtual void invoke(InvokeRequest& req); - virtual void sendToParent(SendRequest& req); + virtual void invoke(const InvokeRequest& req); + virtual void sendToParent(const SendRequest& req); virtual void receive(void* object, umundo::Message* msg); |