34 for (
const auto& arg : inputArguments)
36 ContainerTypePtr type = checkIfLibraryNeedsToBeLoaded(arg.second);
39 ARMARX_DEBUG <<
"Loading lib for variant: " << type->typeId;
40 _loadedDynamicLibraries[type->typeId] = variantInfo->loadLibraryOfVariant(type->typeId);
48 for (
const auto& arg : inputArguments)
50 if (checkIfLibraryNeedsToBeLoaded(arg.second))
52 ARMARX_ERROR <<
"DynamicLibrary for argument '" << arg.first <<
"' is not loaded! Statechart will not be started.";
59 ARMARX_WARNING <<
"SimpleStatechartExecutor is not ready. Cannot start statechart";
63 RemoteStateOffererIceBasePrx prx;
66 prx = getProxy<RemoteStateOffererIceBasePrx>(proxyName,
false);
68 catch (::Ice::NotRegisteredException& e)
70 ARMARX_WARNING <<
"RemoteStateOfferer '" << proxyName <<
"' not available!";
76 ARMARX_WARNING <<
"RemoteStateOfferer '" << proxyName <<
"' not available!";
80 StateBasePtr stateBasePtr = StateBasePtr::dynamicCast(prx->getStatechart(stateName));
83 ARMARX_WARNING <<
"RemoteStateOfferer '" << proxyName <<
"' does not have an available state with name: '" << stateName <<
"'!";
87 _prx = RemoteStateOffererInterfacePrx::checkedCast(prx);
88 _currentStateId = _prx->createRemoteStateInstance(stateName,
nullptr, stateName, stateName + IceUtil::generateUUID());
91 _prx->callRemoteState(_currentStateId,
input);
94 std::unique_lock lock(_finishedMutex);
101 _runningTask->stop(
false);
104 _runningTask->start();
110 std::unique_lock lock(_finishedMutex);
111 if (!_finished && _prx && isCurrentStateIdValid())
113 _prx->breakActiveSubstateRemotely(_currentStateId,
nullptr);
114 _prx->breakRemoteState(_currentStateId,
nullptr);
116 _finishedCondition.wait(lock);
121 _finishedCondition.notify_all();
123 _currentStateId = -1;
133 std::unique_lock lock(_finishedMutex);
137 _finishedCondition.wait(lock);
145 std::unique_lock lock(_finishedMutex);
152 return StringVariantContainerBaseMap();
158 std::unique_lock lock(_finishedMutex);
161 return _lastOutputParameters;
171 for (
const auto& typeName : typeNames)
173 ARMARX_INFO <<
"Loading library for type '" << typeName <<
"'";
174 _loadedDynamicLibraries[typeName] = variantInfo->loadLibraryOfVariant(typeName);
181 std::string packagesString = getProperty<std::string>(
"PackagesForVariantLibraries").getValue();
194 for (
const auto& it : _loadedDynamicLibraries)
204 std::unique_lock lock(_finishedMutex);
206 _finishedCondition.notify_all();
208 _runningTask->stop();
219 void SimpleStatechartExecutor::statechartTask()
221 while (_prx && isCurrentStateIdValid() && !_prx->isRemoteStateFinished(_currentStateId))
227 _lastResult = (_aborted ? eAborted : eSuccess);
229 _lastOutputParameters = _prx->getStatechartInstance(_currentStateId)->outputParameters;
231 _lastOutputParameters = _prx->getStatechartInstance(_currentStateId)->outputParameters;
233 std::unique_lock lock(_finishedMutex);
235 _finishedCondition.notify_all();
240 ContainerTypePtr SimpleStatechartExecutor::checkIfLibraryNeedsToBeLoaded(
const StateParameterIceBasePtr parameter)
const
242 bool loadLib =
false;
243 ContainerTypePtr containerType = parameter->value->getContainerType();
244 if (containerType->typeId ==
"::armarx::SingleTypeVariantListBase" || containerType->typeId ==
"::armarx::StringValueMapBase")
246 while (containerType->subType)
248 containerType = containerType->subType;
250 loadLib = _loadedDynamicLibraries.count(containerType->typeId) == 0;
255 if (variant && variant->get()->data->ice_id() ==
"::armarx::VariantData")
257 loadLib = _loadedDynamicLibraries.count(containerType->typeId) == 0;
261 return loadLib ? containerType : ContainerTypePtr();
264 bool SimpleStatechartExecutor::isCurrentStateIdValid()
const
266 for (
const auto& it : _prx->getAvailableStateInstances())
268 if (it.first == _currentStateId)