diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index a7dbf0b9..ccff01da 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -65,6 +65,21 @@ std::map > InterpreterImpl::getInsta return _instances; } +std::string InterpreterImpl::getInvokedScxmlName(const std::string &invokeid) const { + auto itInv = _invokers.find(invokeid); + if (itInv != _invokers.end()) { + auto sessionID = itInv->second.internalID(); + + auto instances = getInstances(); + auto instance = instances.find(sessionID); + if (auto session = instance->second.lock()) { + return session->getName(); + } + } + + return ""; +} + void InterpreterImpl::addInstance(std::shared_ptr interpreterImpl) { std::lock_guard lock(_instanceMutex); assert(_instances.find(interpreterImpl->getSessionId()) == _instances.end()); diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index 68aa7ef1..47d96224 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -282,6 +282,9 @@ class USCXML_API InterpreterImpl : return _document; } + /* valid only for USCXMLInvoker */ + std::string getInvokedScxmlName(const std::string &invokeid) const; + protected: static void addInstance(std::shared_ptr instance); diff --git a/src/uscxml/plugins/Invoker.cpp b/src/uscxml/plugins/Invoker.cpp index 4015a7dc..b2a68ac8 100644 --- a/src/uscxml/plugins/Invoker.cpp +++ b/src/uscxml/plugins/Invoker.cpp @@ -44,5 +44,10 @@ Data Invoker::serialize() { return _impl->serialize(); } +std::string Invoker::internalID() const +{ + return _impl->internalID(); +} + } diff --git a/src/uscxml/plugins/Invoker.h b/src/uscxml/plugins/Invoker.h index e6672fe2..94b4da6b 100644 --- a/src/uscxml/plugins/Invoker.h +++ b/src/uscxml/plugins/Invoker.h @@ -58,6 +58,10 @@ class USCXML_API Invoker : public EventHandler { /// @copydoc InvokerImpl::serialize virtual Data serialize(); + + /// @copydoc InvokerImpl::internalID + virtual std::string internalID() const; + protected: std::shared_ptr _impl; }; diff --git a/src/uscxml/plugins/InvokerImpl.h b/src/uscxml/plugins/InvokerImpl.h index cd5a38ac..fb5ff4b8 100644 --- a/src/uscxml/plugins/InvokerImpl.h +++ b/src/uscxml/plugins/InvokerImpl.h @@ -109,6 +109,11 @@ class USCXML_API InvokerImpl : public EventHandlerImpl { return Data(); } + /** + * Internal identifier of the invoked service. For example: internal session id for USCXMLInvoker + */ + virtual std::string internalID() const { return ""; } + protected: /** * Return an event to the SCXML Interpreter instance. diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index 3c7d16f5..00fdd4c5 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -98,6 +98,16 @@ Data USCXMLInvoker::serialize() { return encodedState; } +std::string USCXMLInvoker::internalID() const { + if (_invokedInterpreter) { + auto impl = _invokedInterpreter.getImpl(); + if (impl) { + return impl->getSessionId(); + } + } + return ""; +} + void USCXMLInvoker::uninvoke() { _isActive = false; stop(); diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index b030d8b4..ed0cd33e 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -52,9 +52,9 @@ class USCXMLInvoker : USCXMLInvoker(); virtual ~USCXMLInvoker(); - virtual std::shared_ptr create(InvokerCallbacks* callbacks); + virtual std::shared_ptr create(InvokerCallbacks* callbacks) override; - virtual std::list getNames() { + virtual std::list getNames() override { std::list names; names.push_back("scxml"); names.push_back("uscxml"); @@ -63,14 +63,16 @@ class USCXMLInvoker : return names; } - virtual void eventFromSCXML(const Event& event); + virtual void eventFromSCXML(const Event& event) override; - virtual Data getDataModelVariables(); - virtual void invoke(const std::string& source, const Event& invokeEvent); - virtual void uninvoke(); + virtual Data getDataModelVariables() override; + virtual void invoke(const std::string& source, const Event& invokeEvent) override; + virtual void uninvoke() override; - virtual void deserialize(const Data& encodedState); - virtual Data serialize(); + virtual void deserialize(const Data& encodedState) override; + virtual Data serialize() override; + + virtual std::string internalID() const override; protected: