29 std::optional<crow::response> FileModelController::TryGetFileArchive(
30 const std::string& designName,
31 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive>& pFileArchive)
const
37 catch (
const std::exception& e)
44 return crow::response(crow::status::INTERNAL_SERVER_ERROR,
45 "failed to load design \"" + designName +
"\": could not extract or parse archive");
48 if (pFileArchive ==
nullptr)
51 ss <<
"design: \"" << designName <<
"\" not found";
52 return crow::response(crow::status::NOT_FOUND, ss.str());
85 ([&](
const crow::request& req)
89 if (authResp.code != crow::status::OK)
94 return this->filemodels_list_route_handler(req);
98 ([&](
const crow::request& req, std::string designName)
102 if (authResp.code != crow::status::OK)
107 return this->filemodels_get_route_handler(designName, req);
111 ([&](
const crow::request& req, std::string designName)
115 if (authResp.code != crow::status::OK)
120 return this->filemodels_post_route_handler(designName, req);
124 ([&](
const crow::request& req, std::string designName, std::string stepName)
128 if (authResp.code != crow::status::OK)
133 return this->steps_route_handler(designName, stepName, req);
137 ([&](
const crow::request& req, std::string designName)
141 if (authResp.code != crow::status::OK)
146 return this->steps_list_route_handler(designName, req);
150 ([&](
const crow::request& req, std::string designName, std::string stepName)
154 if (authResp.code != crow::status::OK)
159 return this->steps_edadata_route_handler(designName, stepName, req);
163 ([&](
const crow::request& req, std::string designName, std::string stepName)
167 if (authResp.code != crow::status::OK)
172 return this->steps_attrlist_route_handler(designName, stepName, req);
176 ([&](
const crow::request& req, std::string designName, std::string stepName)
180 if (authResp.code != crow::status::OK)
185 return this->steps_profile_route_handler(designName, stepName, req);
189 ([&](
const crow::request& req, std::string designName, std::string stepName)
193 if (authResp.code != crow::status::OK)
198 return this->steps_stephdr_route_handler(designName, stepName, req);
201 CROW_ROUTE(
m_serverApp.
crow_app(),
"/filemodels/<string>/steps/<string>/netlists/<string>")
202 ([&](
const crow::request& req, std::string designName, std::string stepName, std::string netlistName)
206 if (authResp.code != crow::status::OK)
211 return this->steps_netlists_route_handler(designName, stepName, netlistName, req);
215 ([&](
const crow::request& req, std::string designName, std::string stepName)
219 if (authResp.code != crow::status::OK)
224 return this->steps_netlists_list_route_handler(designName, stepName, req);
228 ([&](
const crow::request& req, std::string designName, std::string stepName, std::string layerName)
232 if (authResp.code != crow::status::OK)
237 return this->steps_layers_route_handler(designName, stepName, layerName, req);
241 ([&](
const crow::request& req, std::string designName, std::string stepName)
245 if (authResp.code != crow::status::OK)
250 return this->steps_layers_list_route_handler(designName, stepName, req);
253 CROW_ROUTE(
m_serverApp.
crow_app(),
"/filemodels/<string>/steps/<string>/diagnostics/symbol_units")
254 ([&](
const crow::request& req, std::string designName, std::string stepName)
258 if (authResp.code != crow::status::OK)
263 return this->steps_diagnostics_symbol_units_route_handler(designName, stepName, req);
266 CROW_ROUTE(
m_serverApp.
crow_app(),
"/filemodels/<string>/steps/<string>/layers/<string>/components")
267 ([&](
const crow::request& req, std::string designName, std::string stepName, std::string layerName)
271 if (authResp.code != crow::status::OK)
276 return this->steps_layers_components_route_handler(designName, stepName, layerName, req);
279 CROW_ROUTE(
m_serverApp.
crow_app(),
"/filemodels/<string>/steps/<string>/layers/<string>/features")
280 ([&](
const crow::request& req, std::string designName, std::string stepName, std::string layerName)
284 if (authResp.code != crow::status::OK)
289 return this->steps_layers_features_route_handler(designName, stepName, layerName, req);
292 CROW_ROUTE(
m_serverApp.
crow_app(),
"/filemodels/<string>/steps/<string>/layers/<string>/attrlist")
293 ([&](
const crow::request& req, std::string designName, std::string stepName, std::string layerName)
297 if (authResp.code != crow::status::OK)
302 return this->steps_layers_attrlist_route_handler(designName, stepName, layerName, req);
306 ([&](
const crow::request& req, std::string designName, std::string symbolName)
310 if (authResp.code != crow::status::OK)
315 return this->symbols_route_handler(designName, symbolName, req);
319 ([&](
const crow::request& req, std::string designName, std::string symbolName)
323 if (authResp.code != crow::status::OK)
328 return this->symbols_features_route_handler(designName, symbolName, req);
332 ([&](
const crow::request& req, std::string designName, std::string symbolName)
336 if (authResp.code != crow::status::OK)
341 return this->symbols_attrlist_route_handler(designName, symbolName, req);
345 ([&](
const crow::request& req, std::string designName)
349 if (authResp.code != crow::status::OK)
354 return this->symbols_list_route_handler(designName, req);
362 ([&](
const crow::request& req, std::string designName)
366 if (authResp.code != crow::status::OK)
371 return this->misc_attrlist_route_handler(designName, req);
375 ([&](
const crow::request& req, std::string designName)
379 if (authResp.code != crow::status::OK)
384 return this->matrix_matrix_route_handler(designName, req);
388 ([&](
const crow::request& req, std::string designName)
392 if (authResp.code != crow::status::OK)
397 return this->misc_info_route_handler(designName, req);
401 ([&](
const crow::request& req, std::string designName)
405 if (authResp.code != crow::status::OK)
410 return this->fonts_standard_route_handler(designName, req);
414 crow::response FileModelController::filemodels_get_route_handler(
const std::string& designName,
const crow::request& req)
417 if (designNameDecoded.empty())
419 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
423 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>", etag))
return std::move(*notModified);
424 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
425 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
427 return std::move(*errorResponse);
433 crow::response FileModelController::filemodels_post_route_handler(
const std::string& designName,
const crow::request& req)
436 if (designNameDecoded.empty())
438 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
441 const auto& json = req.body;
444 return crow::response(crow::status::BAD_REQUEST,
"no data provided in POST body");
447 auto fileArchive = std::make_shared<FileArchive>();
448 fileArchive->from_json(json);
454 static_cast<std::uint64_t
>(req.body.size()));
456 return crow::response();
459 crow::response FileModelController::steps_edadata_route_handler(
const std::string& designName,
460 const std::string& stepName,
461 const crow::request& req)
464 if (designNameDecoded.empty())
466 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
470 if (stepNameDecoded.empty())
472 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
476 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/eda_data", etag))
return std::move(*notModified);
477 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
478 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
480 return std::move(*errorResponse);
483 auto& stepsByName = pFileArchive->GetStepsByName();
484 auto findIt = stepsByName.find(stepNameDecoded);
485 if (findIt == stepsByName.end())
487 std::stringstream ss;
488 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
489 return crow::response(crow::status::NOT_FOUND, ss.str());
492 auto& step = findIt->second;
493 auto& edaDataFile = step->GetEdaDataFile();
497 crow::response FileModelController::steps_attrlist_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
500 if (designNameDecoded.empty())
502 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
506 if (stepNameDecoded.empty())
508 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
512 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/attrlist", etag))
return std::move(*notModified);
513 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
514 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
516 return std::move(*errorResponse);
519 auto& stepsByName = pFileArchive->GetStepsByName();
520 auto findIt = stepsByName.find(stepNameDecoded);
521 if (findIt == stepsByName.end())
523 std::stringstream ss;
524 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
525 return crow::response(crow::status::NOT_FOUND, ss.str());
528 auto& step = findIt->second;
529 auto& attrListFile = step->GetAttrListFile();
533 crow::response FileModelController::steps_profile_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
536 if (designNameDecoded.empty())
538 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
542 if (stepNameDecoded.empty())
544 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
548 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/profile", etag))
return std::move(*notModified);
549 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
550 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
552 return std::move(*errorResponse);
555 auto& stepsByName = pFileArchive->GetStepsByName();
556 auto findIt = stepsByName.find(stepNameDecoded);
557 if (findIt == stepsByName.end())
559 std::stringstream ss;
560 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
561 return crow::response(crow::status::NOT_FOUND, ss.str());
564 auto& step = findIt->second;
565 auto& profileFile = step->GetProfileFile();
569 crow::response FileModelController::steps_stephdr_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
572 if (designNameDecoded.empty())
574 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
578 if (stepNameDecoded.empty())
580 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
584 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/stephdr", etag))
return std::move(*notModified);
585 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
586 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
588 return std::move(*errorResponse);
591 auto& stepsByName = pFileArchive->GetStepsByName();
592 auto findIt = stepsByName.find(stepNameDecoded);
593 if (findIt == stepsByName.end())
595 std::stringstream ss;
596 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
597 return crow::response(crow::status::NOT_FOUND, ss.str());
600 auto& step = findIt->second;
601 auto& stepHdrFile = step->GetStepHdrFile();
605 crow::response FileModelController::steps_netlists_route_handler(
const std::string& designName,
const std::string& stepName,
const std::string& netlistName,
const crow::request& req)
608 if (designNameDecoded.empty())
610 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
614 if (stepNameDecoded.empty())
616 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
620 if (stepNameDecoded.empty())
622 return crow::response(crow::status::BAD_REQUEST,
"netlist name not specified");
626 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/netlists/<string>", etag))
return std::move(*notModified);
627 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
628 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
630 return std::move(*errorResponse);
633 auto& stepsByName = pFileArchive->GetStepsByName();
634 auto findIt = stepsByName.find(stepNameDecoded);
635 if (findIt == stepsByName.end())
637 std::stringstream ss;
638 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
639 return crow::response(crow::status::NOT_FOUND, ss.str());
641 auto& step = findIt->second;
643 auto& netlistsByName = step->GetNetlistsByName();
644 auto findIt2 = netlistsByName.find(netlistNameDecoded);
645 if (findIt2 == netlistsByName.end())
647 std::stringstream ss;
648 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\"" <<
" netlist: \"" << netlistNameDecoded <<
"\"" <<
" not found";
649 return crow::response(crow::status::NOT_FOUND, ss.str());
651 auto& netlist = findIt2->second;
656 crow::response FileModelController::steps_netlists_list_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
659 if (designNameDecoded.empty())
661 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
665 if (stepNameDecoded.empty())
667 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
670 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
671 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
673 return std::move(*errorResponse);
676 auto& stepsByName = pFileArchive->GetStepsByName();
677 auto findIt = stepsByName.find(stepNameDecoded);
678 if (findIt == stepsByName.end())
680 std::stringstream ss;
681 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
682 return crow::response(crow::status::NOT_FOUND, ss.str());
684 auto& step = findIt->second;
686 auto& netlistsByName = step->GetNetlistsByName();
687 crow::json::wvalue::list netlistNames;
688 for (
const auto& kvNetlists : netlistsByName)
690 netlistNames.push_back(kvNetlists.first);
693 crow::json::wvalue jsonResponse;
694 jsonResponse[
"netlists"] = std::move(netlistNames);
695 return crow::response(jsonResponse);
698 crow::response FileModelController::steps_list_route_handler(
const std::string& designName,
const crow::request& req)
701 if (designNameDecoded.empty())
703 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
706 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
707 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
709 return std::move(*errorResponse);
712 auto& stepsByName = pFileArchive->GetStepsByName();
713 crow::json::wvalue::list stepNames;
714 for (
const auto& kvSteps : stepsByName)
716 stepNames.push_back(kvSteps.first);
719 crow::json::wvalue jsonResponse;
720 jsonResponse[
"steps"] = std::move(stepNames);
721 return crow::response(jsonResponse);
724 crow::response FileModelController::steps_layers_route_handler(
const std::string& designName,
const std::string& stepName,
const std::string& layerName,
const crow::request& req)
727 if (designNameDecoded.empty())
729 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
733 if (stepNameDecoded.empty())
735 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
739 if (layerNameDecoded.empty())
741 return crow::response(crow::status::BAD_REQUEST,
"layer name not specified");
745 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/layers/<string>", etag))
return std::move(*notModified);
746 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
747 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
749 return std::move(*errorResponse);
752 auto& stepsByName = pFileArchive->GetStepsByName();
753 auto findIt = stepsByName.find(stepNameDecoded);
754 if (findIt == stepsByName.end())
756 std::stringstream ss;
757 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
758 return crow::response(crow::status::NOT_FOUND, ss.str());
760 auto& step = findIt->second;
762 auto& layersByName = step->GetLayersByName();
763 auto findIt2 = layersByName.find(layerNameDecoded);
764 if (findIt2 == layersByName.end())
766 std::stringstream ss;
767 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\"" <<
" layer: \"" << layerNameDecoded <<
"\"" <<
" not found";
768 return crow::response(crow::status::NOT_FOUND, ss.str());
770 auto& layer = findIt2->second;
775 crow::response FileModelController::steps_layers_components_route_handler(
const std::string& designName,
const std::string& stepName,
const std::string& layerName,
const crow::request& req)
778 if (designNameDecoded.empty())
780 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
784 if (stepNameDecoded.empty())
786 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
790 if (layerNameDecoded.empty())
792 return crow::response(crow::status::BAD_REQUEST,
"layer name not specified");
796 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/layers/<string>/components", etag))
return std::move(*notModified);
797 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
798 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
800 return std::move(*errorResponse);
803 auto& stepsByName = pFileArchive->GetStepsByName();
804 auto findIt = stepsByName.find(stepNameDecoded);
805 if (findIt == stepsByName.end())
807 std::stringstream ss;
808 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
809 return crow::response(crow::status::NOT_FOUND, ss.str());
811 auto& step = findIt->second;
813 auto& layersByName = step->GetLayersByName();
814 auto findIt2 = layersByName.find(layerNameDecoded);
815 if (findIt2 == layersByName.end())
817 std::stringstream ss;
818 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\"" <<
" layer: \"" << layerNameDecoded <<
"\"" <<
" not found";
819 return crow::response(crow::status::NOT_FOUND, ss.str());
821 auto& layer = findIt2->second;
823 auto& componentsFile = layer->GetComponentsFile();
826 const auto &attributeNames = componentsFile.GetAttributeNames();
827 for (
const auto &pComponentRecord : componentsFile.GetComponentRecords())
830 pComponentRecord->compName,
831 pComponentRecord->pkgRef,
832 pComponentRecord->GetAttributeLookupTable(),
838 crow::response FileModelController::steps_layers_features_route_handler(
const std::string& designName,
const std::string& stepName,
const std::string& layerName,
const crow::request& req)
841 if (designNameDecoded.empty())
843 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
847 if (stepNameDecoded.empty())
849 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
853 if (layerNameDecoded.empty())
855 return crow::response(crow::status::BAD_REQUEST,
"layer name not specified");
859 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/layers/<string>/features", etag))
return std::move(*notModified);
860 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
861 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
863 return std::move(*errorResponse);
866 auto& stepsByName = pFileArchive->GetStepsByName();
867 auto findIt = stepsByName.find(stepNameDecoded);
868 if (findIt == stepsByName.end())
870 std::stringstream ss;
871 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
872 return crow::response(crow::status::NOT_FOUND, ss.str());
874 auto& step = findIt->second;
876 auto& layersByName = step->GetLayersByName();
877 auto findIt2 = layersByName.find(layerNameDecoded);
878 if (findIt2 == layersByName.end())
880 std::stringstream ss;
881 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\"" <<
" layer: \"" << layerNameDecoded <<
"\"" <<
" not found";
882 return crow::response(crow::status::NOT_FOUND, ss.str());
884 auto& layer = findIt2->second;
886 auto& featuresFile = layer->GetFeaturesFile();
890 crow::response FileModelController::steps_layers_attrlist_route_handler(
const std::string& designName,
const std::string& stepName,
const std::string& layerName,
const crow::request& req)
893 if (designNameDecoded.empty())
895 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
899 if (stepNameDecoded.empty())
901 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
905 if (layerNameDecoded.empty())
907 return crow::response(crow::status::BAD_REQUEST,
"layer name not specified");
911 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/layers/<string>/attrlist", etag))
return std::move(*notModified);
912 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
913 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
915 return std::move(*errorResponse);
918 auto& stepsByName = pFileArchive->GetStepsByName();
919 auto findIt = stepsByName.find(stepNameDecoded);
920 if (findIt == stepsByName.end())
922 std::stringstream ss;
923 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
924 return crow::response(crow::status::NOT_FOUND, ss.str());
926 auto& step = findIt->second;
928 auto& layersByName = step->GetLayersByName();
929 auto findIt2 = layersByName.find(layerNameDecoded);
930 if (findIt2 == layersByName.end())
932 std::stringstream ss;
933 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\"" <<
" layer: \"" << layerNameDecoded <<
"\"" <<
" not found";
934 return crow::response(crow::status::NOT_FOUND, ss.str());
936 auto& layer = findIt2->second;
938 auto& attrlistFile = layer->GetAttrListFile();
942 crow::response FileModelController::steps_layers_list_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
945 if (designNameDecoded.empty())
947 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
951 if (stepNameDecoded.empty())
953 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
956 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
957 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
959 return std::move(*errorResponse);
962 auto& stepsByName = pFileArchive->GetStepsByName();
963 auto findIt = stepsByName.find(stepNameDecoded);
964 if (findIt == stepsByName.end())
966 std::stringstream ss;
967 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
968 return crow::response(crow::status::NOT_FOUND, ss.str());
970 auto& step = findIt->second;
972 auto& layersByName = step->GetLayersByName();
973 crow::json::wvalue::list layerNames;
974 for (
const auto& kvLayers : layersByName)
976 layerNames.push_back(kvLayers.first);
979 crow::json::wvalue jsonResponse;
980 jsonResponse[
"layers"] = std::move(layerNames);
981 return crow::response(jsonResponse);
984 crow::response FileModelController::steps_diagnostics_symbol_units_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
987 if (designNameDecoded.empty())
989 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
993 if (stepNameDecoded.empty())
995 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
999 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>/diagnostics/symbol_units", etag))
return std::move(*notModified);
1000 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1001 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1003 return std::move(*errorResponse);
1006 auto& stepsByName = pFileArchive->GetStepsByName();
1007 auto findIt = stepsByName.find(stepNameDecoded);
1008 if (findIt == stepsByName.end())
1010 std::stringstream ss;
1011 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
1012 return crow::response(crow::status::NOT_FOUND, ss.str());
1014 auto& step = findIt->second;
1016 const auto& layersByName = step->GetLayersByName();
1017 crow::json::wvalue::list layers;
1018 for (
const auto& kv : layersByName)
1020 const auto& layerName = kv.first;
1021 auto pLayer = kv.second;
1022 if (!pLayer)
continue;
1024 const auto& featuresFile = pLayer->GetFeaturesFile();
1027 int metricCount = 0;
1028 int imperialCount = 0;
1030 for (
const auto& sym : symbols)
1033 switch (sym->GetUnitType())
1041 const auto rawUnits = featuresFile.GetUnits();
1043 const auto hasMixed = (metricCount > 0 && imperialCount > 0);
1044 const auto hasMismatch =
1048 crow::json::wvalue layer;
1049 layer[
"layer"] = layerName;
1050 layer[
"features_units_raw"] = rawUnits;
1051 layer[
"symbols_total"] =
static_cast<int>(symbols.size());
1052 layer[
"symbol_unit_counts"][
"metric"] = metricCount;
1053 layer[
"symbol_unit_counts"][
"imperial"] = imperialCount;
1054 layer[
"symbol_unit_counts"][
"none"] = noneCount;
1055 layer[
"has_mixed_symbol_unit_types"] = hasMixed;
1056 layer[
"has_mismatch_vs_features_units"] = hasMismatch;
1057 layers.push_back(layer);
1060 crow::json::wvalue result;
1061 result[
"design"] = designNameDecoded;
1062 result[
"step"] = stepNameDecoded;
1063 result[
"layers"] = std::move(layers);
1067 crow::response FileModelController::steps_route_handler(
const std::string& designName,
const std::string& stepName,
const crow::request& req)
1070 if (designNameDecoded.empty())
1072 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1076 if (stepNameDecoded.empty())
1078 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
1082 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/steps/<string>", etag))
return std::move(*notModified);
1083 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1084 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1086 return std::move(*errorResponse);
1089 auto& stepsByName = pFileArchive->GetStepsByName();
1090 auto findIt = stepsByName.find(stepNameDecoded);
1091 if (findIt == stepsByName.end())
1093 std::stringstream ss;
1094 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" step: \"" << stepNameDecoded <<
"\" not found";
1095 return crow::response(crow::status::NOT_FOUND, ss.str());
1098 auto& step = findIt->second;
1102 crow::response FileModelController::symbols_route_handler(
const std::string& designName,
const std::string& symbolName,
const crow::request& req)
1105 if (designNameDecoded.empty())
1107 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1111 if (symbolNameDecoded.empty())
1113 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
1117 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/symbols/<string>", etag))
return std::move(*notModified);
1118 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1119 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1121 return std::move(*errorResponse);
1124 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1125 auto findIt = symbolsByName.find(symbolNameDecoded);
1126 if (findIt == symbolsByName.end())
1128 std::stringstream ss;
1129 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" symbol: \"" << symbolNameDecoded <<
"\" not found";
1130 return crow::response(crow::status::NOT_FOUND, ss.str());
1133 auto& symbol = findIt->second;
1137 crow::response FileModelController::symbols_features_route_handler(
const std::string& designName,
const std::string& symbolName,
const crow::request& req)
1140 if (designNameDecoded.empty())
1142 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1146 if (symbolNameDecoded.empty())
1148 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
1152 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/symbols/<string>/features", etag))
return std::move(*notModified);
1153 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1154 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1156 return std::move(*errorResponse);
1159 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1160 auto findIt = symbolsByName.find(symbolNameDecoded);
1161 if (findIt == symbolsByName.end())
1163 std::stringstream ss;
1164 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" symbol: \"" << symbolNameDecoded <<
"\" not found";
1165 return crow::response(crow::status::NOT_FOUND, ss.str());
1167 auto& symbol = findIt->second;
1169 auto& featuresFile = symbol->GetFeaturesFile();
1173 crow::response FileModelController::symbols_attrlist_route_handler(
const std::string& designName,
const std::string& symbolName,
const crow::request& req)
1176 if (designNameDecoded.empty())
1178 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1182 if (symbolNameDecoded.empty())
1184 return crow::response(crow::status::BAD_REQUEST,
"step name not specified");
1188 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/symbols/<string>/attrlist", etag))
return std::move(*notModified);
1189 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1190 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1192 return std::move(*errorResponse);
1195 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1196 auto findIt = symbolsByName.find(symbolNameDecoded);
1197 if (findIt == symbolsByName.end())
1199 std::stringstream ss;
1200 ss <<
"(design: \"" << designNameDecoded <<
"\")" <<
" symbol: \"" << symbolNameDecoded <<
"\" not found";
1201 return crow::response(crow::status::NOT_FOUND, ss.str());
1203 auto& symbol = findIt->second;
1205 auto& attrlistFile = symbol->GetAttrListFile();
1209 crow::response FileModelController::symbols_list_route_handler(
const std::string& designName,
const crow::request& req)
1212 if (designNameDecoded.empty())
1214 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1217 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1218 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1220 return std::move(*errorResponse);
1223 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1224 crow::json::wvalue::list symbolNames;
1225 for (
const auto& kvSymbols : symbolsByName)
1227 symbolNames.push_back(kvSymbols.first);
1230 crow::json::wvalue jsonResponse;
1231 jsonResponse[
"symbols"] = std::move(symbolNames);
1232 return crow::response(jsonResponse);
1235 crow::response FileModelController::filemodels_list_route_handler(
const crow::request& req)
1240 crow::response FileModelController::misc_attrlist_route_handler(
const std::string& designName,
const crow::request& req)
1243 if (designNameDecoded.empty())
1245 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1249 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/misc/attrlist", etag))
return std::move(*notModified);
1250 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1251 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1253 return std::move(*errorResponse);
1256 auto& miscAttrListFile = pFileArchive->GetMiscAttrListFile();
1260 crow::response FileModelController::matrix_matrix_route_handler(
const std::string& designName,
const crow::request& req)
1263 if (designNameDecoded.empty())
1265 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1269 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/matrix/matrix", etag))
return std::move(*notModified);
1270 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1271 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1273 return std::move(*errorResponse);
1276 auto& matrixFile = pFileArchive->GetMatrixFile();
1280 crow::response FileModelController::misc_info_route_handler(
const std::string& designName,
const crow::request& req)
1283 if (designNameDecoded.empty())
1285 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1289 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/misc/info", etag))
return std::move(*notModified);
1290 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1291 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1293 return std::move(*errorResponse);
1296 auto& miscInfoFile = pFileArchive->GetMiscInfoFile();
1300 crow::response FileModelController::fonts_standard_route_handler(
const std::string& designName,
const crow::request& req)
1303 if (designNameDecoded.empty())
1305 return crow::response(crow::status::BAD_REQUEST,
"design name not specified");
1309 if (
auto notModified =
checkConditionalGet(req, designNameDecoded,
"/filemodels/<string>/fonts/standard", etag))
return std::move(*notModified);
1310 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1311 if (
auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1313 return std::move(*errorResponse);
1316 auto& standardFontsFile = pFileArchive->GetStandardFontsFile();
#define logexception_msg(e, m)
void register_routes() override
FileModelController(Odb::Lib::App::IOdbServerApp &serverApp)
void AddFileArchive(const std::string &designName, std::shared_ptr< FileModel::Design::FileArchive > fileArchive, bool save, std::uint64_t injectedBytes=0)
std::shared_ptr< FileModel::Design::FileArchive > GetFileArchive(const std::string &designName)
virtual DesignCache & designs()=0
virtual RequestAuthenticationBase & request_auth()=0
virtual CrowApp & crow_app()=0
virtual crow::response AuthenticateRequest(const crow::request &req)
std::optional< crow::response > checkConditionalGet(const crow::request &req, const std::string &designName, const std::string &endpointPath, std::string &etag) const
crow::response withCacheHeaders(crow::response response, const std::string &etag) const
IOdbServerApp & m_serverApp
crow::response makeLoadedFileModelsResponse(bool) const
static ComponentHeightTracer & instance()
void logRestResponse(const std::string &compName, unsigned int pkgRef, const std::map< std::string, std::string > &lookupTable, const std::vector< std::string > &attributeNames) const
static std::string decode(const std::string &encoded)
SymbolName::Vector collect_symbols(const FeaturesFile &featuresFile)
UnitType inferred_unit_type_from_features_units(const std::string &rawUnits)