auto root = getVisibleRoot();
if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
ASSERT(root->getObject());
+ if (target.isString())
+ {
+ target = this->convertToUIElement(target.convertToString());
+ }
auto dest = target.convertToUIElement();
auto sleep_until = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds{ 400 };
variables["gui"] = EvaluationValueFunction{ std::move(waitGui), { { "name", "" }, { "timeout", 5.0 } } };
}
+void BatchExecutor::callActivity(const std::string &activityName, const EvaluationValueFunction::Args &args)
+{
+ auto activity = executeOnMainThread([&]() {
+ return ActivityFactory::getInstance()->createActivity(activityName);
+ });
+ if (!activity)
+ throw EvaluationFailure{} << "failed to construct '" << activityName << "' activity";
+ auto numOfArgs = activity->getRequiredNumberOfArgumentsIfAllowedInBatchProcessing();
+ if (!numOfArgs)
+ throw EvaluationFailure{} << "activity '" << activityName << "' is not supported";
+ if (*numOfArgs != args.size())
+ throw EvaluationFailure{} << "invalid number of arguments for activity '" << activityName <<
+ "', got " << args.size() << ", expected " << *numOfArgs;
+ auto uiActivity = std::dynamic_pointer_cast<UIActivity>(activity);
+
+ // activity must inherit from UIActivity if it returns non zero expected arguments
+ ASSERT(args.empty() || uiActivity);
+
+ std::vector<std::shared_ptr<UIElement>> uiArgs(args.size());
+ for (size_t i = 0; i < args.size(); ++i) {
+ ASSERT(uiActivity);
+ uiArgs[i] = args[i].convertToUIElement();
+ if (!uiArgs[i])
+ throw EvaluationFailure{} << "can't convert argument " << (i + 1) <<
+ " of kind " << args[i].typeName() << " to UIElement";
+ }
+ Monitor<BatchValueOrError<bool>> monitor;
+ {
+ executeOnMainThread([&]() {
+ DEBUG("calling activity %s", activityName.c_str());
+ for (auto &arg : uiArgs) {
+ ASSERT(uiActivity);
+ uiActivity->update(std::move(arg));
+ }
+ activity->process(DoneCallback{ [ = ] {
+ auto h = monitor.lock();
+ h->setValue(true);
+ } });
+ DEBUG("calling activity %s done", activityName.c_str());
+ }, monitor);
+ if (!activity->isCompleted())
+ throw EvaluationFailure{} << "activity '" << activityName << "' is not marked as completed!";
+ auto h = monitor.lock();
+ ASSERT(*h); // sanity check, must be set, otherwise an exception was thrown
+ }
+}
+
void BatchExecutor::insertActivities()
{
for (auto activityName : ActivityFactory::getInstance()->getAllActivityTypes()) {
if (variables.find(activityName) != variables.end())
continue;
variables[activityName] = [ = ](EvaluationValueFunction::Args args) -> EvaluationValue {
- auto activity = executeOnMainThread([&]()
- {
- return ActivityFactory::getInstance()->createActivity(activityName);
- });
- if (!activity)
- throw EvaluationFailure{} << "failed to construct '" << activityName << "' activity";
- auto numOfArgs = activity->getRequiredNumberOfArgumentsIfAllowedInBatchProcessing();
- if (!numOfArgs)
- throw EvaluationFailure{} << "activity '" << activityName << "' is not supported";
- if (*numOfArgs != args.size())
- throw EvaluationFailure{} << "invalid number of arguments for activity '" << activityName <<
- "', got " << args.size() << ", expected " << *numOfArgs;
- auto uiActivity = std::dynamic_pointer_cast<UIActivity>(activity);
-
- // activity must inherit from UIActivity if it returns non zero expected arguments
- ASSERT(args.empty() || uiActivity);
-
- std::vector<std::shared_ptr<UIElement>> uiArgs(args.size());
- for (size_t i = 0; i < args.size(); ++i)
- {
- ASSERT(uiActivity);
- uiArgs[i] = args[i].convertToUIElement();
- if (!uiArgs[i])
- throw EvaluationFailure{} << "can't convert argument " << (i + 1) <<
- " of kind " << args[i].typeName() << " to UIElement";
- }
- Monitor<BatchValueOrError<bool>> monitor;
- {
- executeOnMainThread([&]()
- {
- DEBUG("calling activity %s", activityName.c_str());
- for (auto &arg : uiArgs) {
- ASSERT(uiActivity);
- uiActivity->update(std::move(arg));
- }
- activity->process(DoneCallback{ [ = ] {
- auto h = monitor.lock();
- h->setValue(true);
- } });
- DEBUG("calling activity %s done", activityName.c_str());
- }, monitor);
- if (!activity->isCompleted())
- throw EvaluationFailure{} << "activity '" << activityName << "' is not marked as completed!";
- auto h = monitor.lock();
- ASSERT(*h); // sanity check, must be set, otherwise an exception was thrown
- }
+ callActivity(activityName, args);
return {};
};
}