Skip to content

Commit

Permalink
add method to find SCXML InterpreterImpl by InvokeID
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhornyak committed May 19, 2021
1 parent d0a25ce commit 2130092
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/uscxml/interpreter/InterpreterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ std::map<std::string, std::weak_ptr<InterpreterImpl> > 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> interpreterImpl) {
std::lock_guard<std::recursive_mutex> lock(_instanceMutex);
assert(_instances.find(interpreterImpl->getSessionId()) == _instances.end());
Expand Down
3 changes: 3 additions & 0 deletions src/uscxml/interpreter/InterpreterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<InterpreterImpl> instance);

Expand Down
5 changes: 5 additions & 0 deletions src/uscxml/plugins/Invoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ Data Invoker::serialize() {
return _impl->serialize();
}

std::string Invoker::internalID() const
{
return _impl->internalID();
}


}
4 changes: 4 additions & 0 deletions src/uscxml/plugins/Invoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvokerImpl> _impl;
};
Expand Down
5 changes: 5 additions & 0 deletions src/uscxml/plugins/InvokerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 10 additions & 8 deletions src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class USCXMLInvoker :

USCXMLInvoker();
virtual ~USCXMLInvoker();
virtual std::shared_ptr<InvokerImpl> create(InvokerCallbacks* callbacks);
virtual std::shared_ptr<InvokerImpl> create(InvokerCallbacks* callbacks) override;

virtual std::list<std::string> getNames() {
virtual std::list<std::string> getNames() override {
std::list<std::string> names;
names.push_back("scxml");
names.push_back("uscxml");
Expand All @@ -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:

Expand Down

0 comments on commit 2130092

Please sign in to comment.