29 #include <ArmarXCore/interface/observers/VariantContainers.h>
38 #include <SimoxUtility/algorithm/string.h>
49 std::vector<LibEntryPtr> libs;
50 if (packagePaths.find(packagePath) != packagePaths.end())
52 ARMARX_DEBUG_S <<
"path '" << packagePath <<
"' already in there.";
56 packagePaths[(packagePath)] = packageName;
61 this->libs.push_back(lib);
66 variantToLibMap.insert(std::make_pair(e->baseTypeName, lib));
67 variantMap.insert(std::make_pair(e->baseTypeName, e));
68 humanNameToVariantMap.insert(std::make_pair(e->humanName, e));
73 proxyMap.insert(std::make_pair(lib->name +
"." + p->memberName, p));
81 std::map<std::string, LibEntryPtr>::const_iterator it = variantToLibMap.find(variantTypeName);
83 if (it == variantToLibMap.end())
97 std::string libName = lib->getName();
100 if (proxy->getMemberName() == proxyTypeName)
112 Ice::StringSeq result;
117 result.push_back(lib->getName());
123 std::set<VariantInfo::LibEntryPtr>
VariantInfo::findLibs(
const Ice::StringSeq& variantTypeNames,
const Ice::StringSeq& proxyTypeNames)
const
125 std::set<VariantInfo::LibEntryPtr> result;
126 for (
auto& var : variantTypeNames)
134 for (
auto& proxy : proxyTypeNames)
147 std::map<std::string, VariantEntryPtr>::const_iterator it = variantMap.find(variantBaseTypeName);
149 if (it == variantMap.end())
155 return it->second->dataTypeName;
161 std::map<std::string, VariantEntryPtr>::const_iterator it = variantMap.find(variantBaseTypeName);
163 if (it == variantMap.end())
172 return e->basic ? e->dataTypeName : e->dataTypeName +
"Ptr";
178 std::map<std::string, VariantEntryPtr>::const_iterator it = variantMap.find(variantBaseTypeName);
180 if (it == variantMap.end())
198 std::map<std::string, ProxyEntryPtr>::const_iterator it = proxyMap.find(proxyId);
200 if (it == proxyMap.end())
212 std::map<std::string, VariantEntryPtr>::const_iterator it = variantMap.find(variantBaseTypeName);
214 if (it == variantMap.end())
226 std::map<std::string, VariantEntryPtr>::const_iterator it = humanNameToVariantMap.find(humanName);
228 if (it == humanNameToVariantMap.end())
241 std::stringstream containers;
242 std::stringstream parenthesis;
244 while (containerInfo->subType)
248 containers <<
"List(";
252 containers <<
"Map(";
260 containerInfo = containerInfo->subType;
270 return containers.str() + entry->humanName + parenthesis.str();
276 std::stringstream containers;
277 std::stringstream parenthesis;
279 while (containerInfo->subType)
281 if (containerInfo->typeId ==
"List")
285 else if (containerInfo->typeId ==
"Map")
295 containerInfo = containerInfo->subType;
305 return containers.str() + entry->baseTypeName + parenthesis.str();
315 for (
const auto& p : packagePaths)
317 if (p.second == packageName)
327 std::stringstream ss;
331 ss << e->getName() <<
"\n";
335 ss <<
" " <<
v->getHumanName() <<
": " <<
v->dataTypeName <<
"\n";
340 ss <<
" " << p->getHumanName() <<
": " << p->getIncludePath() <<
"\n";
354 const std::string cmakePackageName =
355 simox::alg::replace_all(eventuallyNamespacedPackage,
"::",
"_");
359 ARMARX_CHECK_EXPRESSION(finder.packageFound()) << cmakePackageName <<
" at " <<
"'" << rootPackagePath <<
"'\n";
361 std::filesystem::path variantInfoFile(finder.getDataDir().c_str());
362 variantInfoFile /= cmakePackageName;
363 variantInfoFile /=
"VariantInfo-" + cmakePackageName +
".xml";
365 if (std::filesystem::exists(variantInfoFile))
367 if (!variantInfo->isPackageLoaded(cmakePackageName))
372 variantInfo->readVariantInfo(xmlReader, rootPackagePath, cmakePackageName);
375 catch (std::exception& e)
377 ARMARX_ERROR_S <<
"Reading " << variantInfoFile.string() <<
" failed: " << e.what();
383 ARMARX_WARNING_S <<
"VariantInfo File not found for project " << cmakePackageName <<
": " << variantInfoFile.string();
386 if (finder.packageFound())
388 auto depPaths = finder.getDependencyPaths();
390 for (
auto& depPath : depPaths)
392 if (variantInfo->getPackagePaths().find(depPath.second) != variantInfo->getPackagePaths().end())
397 if (!depPath.first.empty() && !depPath.second.empty())
399 std::string packagePath;
401 if (!depPath.second.empty() && std::filesystem::exists(depPath.second))
403 packagePath = depPath.second;
418 for (std::string package : packages)
425 std::filesystem::path variantInfoFile(finder.getDataDir().c_str());
426 variantInfoFile /= package;
427 variantInfoFile /=
"VariantInfo-" +
package + ".xml";
429 if (std::filesystem::exists(variantInfoFile))
434 std::vector<LibEntryPtr> libs = variantInfo->readVariantInfo(xmlReader, finder.getConfigDir(), package);
436 std::stringstream ss;
439 ss <<
"Lib " << e->getName() <<
"\n";
443 ss <<
" Variant " <<
v->getHumanName() <<
": " <<
v->dataTypeName <<
"\n";
448 ss <<
" Proxy " << p->getHumanName() <<
": " << p->getIncludePath() <<
"\n";
451 ARMARX_DEBUG_S <<
"VariantInfo for " <<
package << ":\n" << ss.str();
453 catch (std::exception& e)
455 ARMARX_ERROR_S <<
"Reading " << variantInfoFile.string() <<
" failed: " << e.what();
460 ARMARX_WARNING_S <<
"VariantInfo File not found for project " <<
package << ": " << variantInfoFile.string();
473 ARMARX_WARNING <<
"Could not find lib for variant " << variantTypeName;
476 ARMARX_INFO_S <<
"Loading lib " << lib->getAbsoluteLibPath();
477 result->load(lib->getAbsoluteLibPath());
478 if (result->isLibraryLoaded())
492 packageName(packageName)
498 factoryIncludes.push_back(includeNode.attribute_value(
"include"));
504 variants.push_back(entry);
509 if (proxyNode.name() ==
"Proxy" || proxyNode.name() ==
"Topic")
512 proxies.push_back(proxy);
519 return factoryIncludes;
524 auto it = std::find_if(variants.begin(), variants.end(), [&](
const VariantEntryPtr & entry)
526 return entry->getBaseTypeName() == variantBaseTypeName;
528 if (it != variants.end() && (*it)->getIncludePath())
530 return {*(*it)->getIncludePath()};
534 return factoryIncludes;
548 throw LocalException() <<
"Could not find package '" << packageName <<
"'!";
552 throw LocalException() <<
"Library path for package '" << packageName <<
"' is empty!";
556 if (!std::filesystem::exists(path))
558 throw LocalException() <<
"Library path '" << path.string() <<
"' does not exist!";
560 return path.string();
611 void VariantInfo::ProxyEntry::readVector(
RapidXmlReaderNode node,
const char* name, std::vector<std::string>& vec)
615 vec.push_back(n.value());
631 readVector(node,
"include", includes);
632 readVector(node,
"library", libraries);
633 readVector(node,
"member", members);
634 readVector(node,
"onInit", onInit);
635 readVector(node,
"onConnect", onConnect);
639 methods.push_back(std::make_pair(n.attribute_value(
"header"), n.value()));
644 stateMethods.push_back(std::make_pair(n.attribute_value(
"header"), n.value()));