OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
FileModelController.cpp
Go to the documentation of this file.
3#include "UrlEncoding.h"
4#include <memory>
7#include <Logger.h>
8#include <sstream>
9#include <string>
10#include <algorithm>
11#include <cctype>
12#include "crow_win.h"
13#include "App/RouteController.h"
14
15
16using namespace Odb::Lib::App;
17using namespace Odb::Lib::FileModel::Design;
18using namespace Utils;
19
20namespace Odb::App::Server
21{
22
23
28
29 std::optional<crow::response> FileModelController::TryGetFileArchive(
30 const std::string& designName,
31 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive>& pFileArchive) const
32 {
33 try
34 {
35 pFileArchive = m_serverApp.designs().GetFileArchive(designName);
36 }
37 catch (const std::exception& e)
38 {
39 // Corrupt / unloadable archive: DesignCache::LoadFileArchive throws so
40 // callers can distinguish this from a missing design. Translate to
41 // INTERNAL/500. The exception details (which may contain server
42 // filesystem paths) are logged server-side only, never sent to the client.
43 logexception_msg(e, "failed to load design \"" + designName + "\"");
44 return crow::response(crow::status::INTERNAL_SERVER_ERROR,
45 "failed to load design \"" + designName + "\": could not extract or parse archive");
46 }
47
48 if (pFileArchive == nullptr)
49 {
50 std::stringstream ss;
51 ss << "design: \"" << designName << "\" not found";
52 return crow::response(crow::status::NOT_FOUND, ss.str());
53 }
54
55 return std::nullopt;
56 }
57
65
70
74
79
80 // * need endpoints to list of keys of maps, i.e. available names to fetch
81
83 {
84 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels")
85 ([&](const crow::request& req)
86 {
87 // authenticate request before sending to handler
88 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
89 if (authResp.code != crow::status::OK)
90 {
91 return authResp;
92 }
93
94 return this->filemodels_list_route_handler(req);
95 });
96
97 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>").methods(crow::HTTPMethod::GET)
98 ([&](const crow::request& req, std::string designName)
99 {
100 // authenticate request before sending to handler
101 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
102 if (authResp.code != crow::status::OK)
103 {
104 return authResp;
105 }
106
107 return this->filemodels_get_route_handler(designName, req);
108 });
109
110 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>").methods(crow::HTTPMethod::POST)
111 ([&](const crow::request& req, std::string designName)
112 {
113 // authenticate request before sending to handler
114 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
115 if (authResp.code != crow::status::OK)
116 {
117 return authResp;
118 }
119
120 return this->filemodels_post_route_handler(designName, req);
121 });
122
123 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>")
124 ([&](const crow::request& req, std::string designName, std::string stepName)
125 {
126 // authenticate request before sending to handler
127 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
128 if (authResp.code != crow::status::OK)
129 {
130 return authResp;
131 }
132
133 return this->steps_route_handler(designName, stepName, req);
134 });
135
136 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps")
137 ([&](const crow::request& req, std::string designName)
138 {
139 // authenticate request before sending to handler
140 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
141 if (authResp.code != crow::status::OK)
142 {
143 return authResp;
144 }
145
146 return this->steps_list_route_handler(designName, req);
147 });
148
149 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/eda_data")
150 ([&](const crow::request& req, std::string designName, std::string stepName)
151 {
152 // authenticate request before sending to handler
153 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
154 if (authResp.code != crow::status::OK)
155 {
156 return authResp;
157 }
158
159 return this->steps_edadata_route_handler(designName, stepName, req);
160 });
161
162 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/attrlist")
163 ([&](const crow::request& req, std::string designName, std::string stepName)
164 {
165 // authenticate request before sending to handler
166 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
167 if (authResp.code != crow::status::OK)
168 {
169 return authResp;
170 }
171
172 return this->steps_attrlist_route_handler(designName, stepName, req);
173 });
174
175 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/profile")
176 ([&](const crow::request& req, std::string designName, std::string stepName)
177 {
178 // authenticate request before sending to handler
179 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
180 if (authResp.code != crow::status::OK)
181 {
182 return authResp;
183 }
184
185 return this->steps_profile_route_handler(designName, stepName, req);
186 });
187
188 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/stephdr")
189 ([&](const crow::request& req, std::string designName, std::string stepName)
190 {
191 // authenticate request before sending to handler
192 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
193 if (authResp.code != crow::status::OK)
194 {
195 return authResp;
196 }
197
198 return this->steps_stephdr_route_handler(designName, stepName, req);
199 });
200
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)
203 {
204 // authenticate request before sending to handler
205 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
206 if (authResp.code != crow::status::OK)
207 {
208 return authResp;
209 }
210
211 return this->steps_netlists_route_handler(designName, stepName, netlistName, req);
212 });
213
214 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/netlists")
215 ([&](const crow::request& req, std::string designName, std::string stepName)
216 {
217 // authenticate request before sending to handler
218 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
219 if (authResp.code != crow::status::OK)
220 {
221 return authResp;
222 }
223
224 return this->steps_netlists_list_route_handler(designName, stepName, req);
225 });
226
227 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/layers/<string>")
228 ([&](const crow::request& req, std::string designName, std::string stepName, std::string layerName)
229 {
230 // authenticate request before sending to handler
231 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
232 if (authResp.code != crow::status::OK)
233 {
234 return authResp;
235 }
236
237 return this->steps_layers_route_handler(designName, stepName, layerName, req);
238 });
239
240 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/steps/<string>/layers")
241 ([&](const crow::request& req, std::string designName, std::string stepName)
242 {
243 // authenticate request before sending to handler
244 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
245 if (authResp.code != crow::status::OK)
246 {
247 return authResp;
248 }
249
250 return this->steps_layers_list_route_handler(designName, stepName, req);
251 });
252
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)
255 {
256 // authenticate request before sending to handler
257 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
258 if (authResp.code != crow::status::OK)
259 {
260 return authResp;
261 }
262
263 return this->steps_diagnostics_symbol_units_route_handler(designName, stepName, req);
264 });
265
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)
268 {
269 // authenticate request before sending to handler
270 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
271 if (authResp.code != crow::status::OK)
272 {
273 return authResp;
274 }
275
276 return this->steps_layers_components_route_handler(designName, stepName, layerName, req);
277 });
278
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)
281 {
282 // authenticate request before sending to handler
283 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
284 if (authResp.code != crow::status::OK)
285 {
286 return authResp;
287 }
288
289 return this->steps_layers_features_route_handler(designName, stepName, layerName, req);
290 });
291
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)
294 {
295 // authenticate request before sending to handler
296 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
297 if (authResp.code != crow::status::OK)
298 {
299 return authResp;
300 }
301
302 return this->steps_layers_attrlist_route_handler(designName, stepName, layerName, req);
303 });
304
305 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/symbols/<string>")
306 ([&](const crow::request& req, std::string designName, std::string symbolName)
307 {
308 // authenticate request before sending to handler
309 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
310 if (authResp.code != crow::status::OK)
311 {
312 return authResp;
313 }
314
315 return this->symbols_route_handler(designName, symbolName, req);
316 });
317
318 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/symbols/<string>/features")
319 ([&](const crow::request& req, std::string designName, std::string symbolName)
320 {
321 // authenticate request before sending to handler
322 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
323 if (authResp.code != crow::status::OK)
324 {
325 return authResp;
326 }
327
328 return this->symbols_features_route_handler(designName, symbolName, req);
329 });
330
331 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/symbols/<string>/attrlist")
332 ([&](const crow::request& req, std::string designName, std::string symbolName)
333 {
334 // authenticate request before sending to handler
335 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
336 if (authResp.code != crow::status::OK)
337 {
338 return authResp;
339 }
340
341 return this->symbols_attrlist_route_handler(designName, symbolName, req);
342 });
343
344 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/symbols")
345 ([&](const crow::request& req, std::string designName)
346 {
347 // authenticate request before sending to handler
348 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
349 if (authResp.code != crow::status::OK)
350 {
351 return authResp;
352 }
353
354 return this->symbols_list_route_handler(designName, req);
355 });
356
357 //register_route_handler("/filemodels/misc/attrlist", std::bind(&FileModelController::misc_attrlist_route_handler, this, std::placeholders::_1));
358 //register_route_handler("/filemodels/matrix/matrix", std::bind(&FileModelController::matrix_matrix_route_handler, this, std::placeholders::_1));
359 //register_route_handler("/filemodels/misc/info", std::bind(&FileModelController::misc_info_route_handler, this, std::placeholders::_1));
360
361 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/misc/attrlist")
362 ([&](const crow::request& req, std::string designName)
363 {
364 // authenticate request before sending to handler
365 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
366 if (authResp.code != crow::status::OK)
367 {
368 return authResp;
369 }
370
371 return this->misc_attrlist_route_handler(designName, req);
372 });
373
374 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/matrix/matrix")
375 ([&](const crow::request& req, std::string designName)
376 {
377 // authenticate request before sending to handler
378 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
379 if (authResp.code != crow::status::OK)
380 {
381 return authResp;
382 }
383
384 return this->matrix_matrix_route_handler(designName, req);
385 });
386
387 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/misc/info")
388 ([&](const crow::request& req, std::string designName)
389 {
390 // authenticate request before sending to handler
391 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
392 if (authResp.code != crow::status::OK)
393 {
394 return authResp;
395 }
396
397 return this->misc_info_route_handler(designName, req);
398 });
399
400 CROW_ROUTE(m_serverApp.crow_app(), "/filemodels/<string>/fonts/standard")
401 ([&](const crow::request& req, std::string designName)
402 {
403 // authenticate request before sending to handler
404 auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
405 if (authResp.code != crow::status::OK)
406 {
407 return authResp;
408 }
409
410 return this->fonts_standard_route_handler(designName, req);
411 });
412 }
413
414 crow::response FileModelController::filemodels_get_route_handler(const std::string& designName, const crow::request& req)
415 {
416 auto designNameDecoded = UrlEncoding::decode(designName);
417 if (designNameDecoded.empty())
418 {
419 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
420 }
421
422 std::string etag;
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))
426 {
427 return std::move(*errorResponse);
428 }
429
430 return withCacheHeaders(crow::response(JsonCrowReturnable(*pFileArchive)), etag);
431 }
432
433 crow::response FileModelController::filemodels_post_route_handler(const std::string& designName, const crow::request& req)
434 {
435 auto designNameDecoded = UrlEncoding::decode(designName);
436 if (designNameDecoded.empty())
437 {
438 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
439 }
440
441 const auto& json = req.body;
442 if (json.empty())
443 {
444 return crow::response(crow::status::BAD_REQUEST, "no data provided in POST body");
445 }
446
447 auto fileArchive = std::make_shared<FileArchive>();
448 fileArchive->from_json(json);
449 // designNameDecoded (not the raw route parameter) so the cache key
450 // matches every other handler, and the request body size as the
451 // in-memory byte estimate (save=false writes nothing to disk, so the
452 // LRU budget would otherwise charge only the flat 4 KiB overhead).
453 m_serverApp.designs().AddFileArchive(designNameDecoded, fileArchive, false,
454 static_cast<std::uint64_t>(req.body.size()));
455
456 return crow::response();
457 }
458
459 crow::response FileModelController::steps_edadata_route_handler(const std::string& designName,
460 const std::string& stepName,
461 const crow::request& req)
462 {
463 auto designNameDecoded = UrlEncoding::decode(designName);
464 if (designNameDecoded.empty())
465 {
466 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
467 }
468
469 auto stepNameDecoded = UrlEncoding::decode(stepName);
470 if (stepNameDecoded.empty())
471 {
472 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
473 }
474
475 std::string etag;
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))
479 {
480 return std::move(*errorResponse);
481 }
482
483 auto& stepsByName = pFileArchive->GetStepsByName();
484 auto findIt = stepsByName.find(stepNameDecoded);
485 if (findIt == stepsByName.end())
486 {
487 std::stringstream ss;
488 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
489 return crow::response(crow::status::NOT_FOUND, ss.str());
490 }
491
492 auto& step = findIt->second;
493 auto& edaDataFile = step->GetEdaDataFile();
494 return withCacheHeaders(crow::response(JsonCrowReturnable(edaDataFile)), etag);
495 }
496
497 crow::response FileModelController::steps_attrlist_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
498 {
499 auto designNameDecoded = UrlEncoding::decode(designName);
500 if (designNameDecoded.empty())
501 {
502 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
503 }
504
505 auto stepNameDecoded = UrlEncoding::decode(stepName);
506 if (stepNameDecoded.empty())
507 {
508 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
509 }
510
511 std::string etag;
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))
515 {
516 return std::move(*errorResponse);
517 }
518
519 auto& stepsByName = pFileArchive->GetStepsByName();
520 auto findIt = stepsByName.find(stepNameDecoded);
521 if (findIt == stepsByName.end())
522 {
523 std::stringstream ss;
524 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
525 return crow::response(crow::status::NOT_FOUND, ss.str());
526 }
527
528 auto& step = findIt->second;
529 auto& attrListFile = step->GetAttrListFile();
530 return withCacheHeaders(crow::response(JsonCrowReturnable(attrListFile)), etag);
531 }
532
533 crow::response FileModelController::steps_profile_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
534 {
535 auto designNameDecoded = UrlEncoding::decode(designName);
536 if (designNameDecoded.empty())
537 {
538 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
539 }
540
541 auto stepNameDecoded = UrlEncoding::decode(stepName);
542 if (stepNameDecoded.empty())
543 {
544 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
545 }
546
547 std::string etag;
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))
551 {
552 return std::move(*errorResponse);
553 }
554
555 auto& stepsByName = pFileArchive->GetStepsByName();
556 auto findIt = stepsByName.find(stepNameDecoded);
557 if (findIt == stepsByName.end())
558 {
559 std::stringstream ss;
560 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
561 return crow::response(crow::status::NOT_FOUND, ss.str());
562 }
563
564 auto& step = findIt->second;
565 auto& profileFile = step->GetProfileFile();
566 return withCacheHeaders(crow::response(JsonCrowReturnable(profileFile)), etag);
567 }
568
569 crow::response FileModelController::steps_stephdr_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
570 {
571 auto designNameDecoded = UrlEncoding::decode(designName);
572 if (designNameDecoded.empty())
573 {
574 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
575 }
576
577 auto stepNameDecoded = UrlEncoding::decode(stepName);
578 if (stepNameDecoded.empty())
579 {
580 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
581 }
582
583 std::string etag;
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))
587 {
588 return std::move(*errorResponse);
589 }
590
591 auto& stepsByName = pFileArchive->GetStepsByName();
592 auto findIt = stepsByName.find(stepNameDecoded);
593 if (findIt == stepsByName.end())
594 {
595 std::stringstream ss;
596 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
597 return crow::response(crow::status::NOT_FOUND, ss.str());
598 }
599
600 auto& step = findIt->second;
601 auto& stepHdrFile = step->GetStepHdrFile();
602 return withCacheHeaders(crow::response(JsonCrowReturnable(stepHdrFile)), etag);
603 }
604
605 crow::response FileModelController::steps_netlists_route_handler(const std::string& designName, const std::string& stepName, const std::string& netlistName, const crow::request& req)
606 {
607 auto designNameDecoded = UrlEncoding::decode(designName);
608 if (designNameDecoded.empty())
609 {
610 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
611 }
612
613 auto stepNameDecoded = UrlEncoding::decode(stepName);
614 if (stepNameDecoded.empty())
615 {
616 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
617 }
618
619 auto netlistNameDecoded = UrlEncoding::decode(netlistName);
620 if (stepNameDecoded.empty())
621 {
622 return crow::response(crow::status::BAD_REQUEST, "netlist name not specified");
623 }
624
625 std::string etag;
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))
629 {
630 return std::move(*errorResponse);
631 }
632
633 auto& stepsByName = pFileArchive->GetStepsByName();
634 auto findIt = stepsByName.find(stepNameDecoded);
635 if (findIt == stepsByName.end())
636 {
637 std::stringstream ss;
638 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
639 return crow::response(crow::status::NOT_FOUND, ss.str());
640 }
641 auto& step = findIt->second;
642
643 auto& netlistsByName = step->GetNetlistsByName();
644 auto findIt2 = netlistsByName.find(netlistNameDecoded);
645 if (findIt2 == netlistsByName.end())
646 {
647 std::stringstream ss;
648 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\"" << " netlist: \"" << netlistNameDecoded << "\"" << " not found";
649 return crow::response(crow::status::NOT_FOUND, ss.str());
650 }
651 auto& netlist = findIt2->second;
652
653 return withCacheHeaders(crow::response(JsonCrowReturnable(*netlist)), etag);
654 }
655
656 crow::response FileModelController::steps_netlists_list_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
657 {
658 auto designNameDecoded = UrlEncoding::decode(designName);
659 if (designNameDecoded.empty())
660 {
661 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
662 }
663
664 auto stepNameDecoded = UrlEncoding::decode(stepName);
665 if (stepNameDecoded.empty())
666 {
667 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
668 }
669
670 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
671 if (auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
672 {
673 return std::move(*errorResponse);
674 }
675
676 auto& stepsByName = pFileArchive->GetStepsByName();
677 auto findIt = stepsByName.find(stepNameDecoded);
678 if (findIt == stepsByName.end())
679 {
680 std::stringstream ss;
681 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
682 return crow::response(crow::status::NOT_FOUND, ss.str());
683 }
684 auto& step = findIt->second;
685
686 auto& netlistsByName = step->GetNetlistsByName();
687 crow::json::wvalue::list netlistNames;
688 for (const auto& kvNetlists : netlistsByName)
689 {
690 netlistNames.push_back(kvNetlists.first);
691 }
692
693 crow::json::wvalue jsonResponse;
694 jsonResponse["netlists"] = std::move(netlistNames);
695 return crow::response(jsonResponse);
696 }
697
698 crow::response FileModelController::steps_list_route_handler(const std::string& designName, const crow::request& req)
699 {
700 auto designNameDecoded = UrlEncoding::decode(designName);
701 if (designNameDecoded.empty())
702 {
703 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
704 }
705
706 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
707 if (auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
708 {
709 return std::move(*errorResponse);
710 }
711
712 auto& stepsByName = pFileArchive->GetStepsByName();
713 crow::json::wvalue::list stepNames;
714 for (const auto& kvSteps : stepsByName)
715 {
716 stepNames.push_back(kvSteps.first);
717 }
718
719 crow::json::wvalue jsonResponse;
720 jsonResponse["steps"] = std::move(stepNames);
721 return crow::response(jsonResponse);
722 }
723
724 crow::response FileModelController::steps_layers_route_handler(const std::string& designName, const std::string& stepName, const std::string& layerName, const crow::request& req)
725 {
726 auto designNameDecoded = UrlEncoding::decode(designName);
727 if (designNameDecoded.empty())
728 {
729 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
730 }
731
732 auto stepNameDecoded = UrlEncoding::decode(stepName);
733 if (stepNameDecoded.empty())
734 {
735 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
736 }
737
738 auto layerNameDecoded = UrlEncoding::decode(layerName);
739 if (layerNameDecoded.empty())
740 {
741 return crow::response(crow::status::BAD_REQUEST, "layer name not specified");
742 }
743
744 std::string etag;
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))
748 {
749 return std::move(*errorResponse);
750 }
751
752 auto& stepsByName = pFileArchive->GetStepsByName();
753 auto findIt = stepsByName.find(stepNameDecoded);
754 if (findIt == stepsByName.end())
755 {
756 std::stringstream ss;
757 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
758 return crow::response(crow::status::NOT_FOUND, ss.str());
759 }
760 auto& step = findIt->second;
761
762 auto& layersByName = step->GetLayersByName();
763 auto findIt2 = layersByName.find(layerNameDecoded);
764 if (findIt2 == layersByName.end())
765 {
766 std::stringstream ss;
767 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\"" << " layer: \"" << layerNameDecoded << "\"" << " not found";
768 return crow::response(crow::status::NOT_FOUND, ss.str());
769 }
770 auto& layer = findIt2->second;
771
772 return withCacheHeaders(crow::response(JsonCrowReturnable(*layer)), etag);
773 }
774
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)
776 {
777 auto designNameDecoded = UrlEncoding::decode(designName);
778 if (designNameDecoded.empty())
779 {
780 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
781 }
782
783 auto stepNameDecoded = UrlEncoding::decode(stepName);
784 if (stepNameDecoded.empty())
785 {
786 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
787 }
788
789 auto layerNameDecoded = UrlEncoding::decode(layerName);
790 if (layerNameDecoded.empty())
791 {
792 return crow::response(crow::status::BAD_REQUEST, "layer name not specified");
793 }
794
795 std::string etag;
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))
799 {
800 return std::move(*errorResponse);
801 }
802
803 auto& stepsByName = pFileArchive->GetStepsByName();
804 auto findIt = stepsByName.find(stepNameDecoded);
805 if (findIt == stepsByName.end())
806 {
807 std::stringstream ss;
808 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
809 return crow::response(crow::status::NOT_FOUND, ss.str());
810 }
811 auto& step = findIt->second;
812
813 auto& layersByName = step->GetLayersByName();
814 auto findIt2 = layersByName.find(layerNameDecoded);
815 if (findIt2 == layersByName.end())
816 {
817 std::stringstream ss;
818 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\"" << " layer: \"" << layerNameDecoded << "\"" << " not found";
819 return crow::response(crow::status::NOT_FOUND, ss.str());
820 }
821 auto& layer = findIt2->second;
822
823 auto& componentsFile = layer->GetComponentsFile();
824
825 // Trace REST response for target components / failures
826 const auto &attributeNames = componentsFile.GetAttributeNames();
827 for (const auto &pComponentRecord : componentsFile.GetComponentRecords())
828 {
830 pComponentRecord->compName,
831 pComponentRecord->pkgRef,
832 pComponentRecord->GetAttributeLookupTable(),
833 attributeNames);
834 }
835 return withCacheHeaders(crow::response(JsonCrowReturnable(componentsFile)), etag);
836 }
837
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)
839 {
840 auto designNameDecoded = UrlEncoding::decode(designName);
841 if (designNameDecoded.empty())
842 {
843 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
844 }
845
846 auto stepNameDecoded = UrlEncoding::decode(stepName);
847 if (stepNameDecoded.empty())
848 {
849 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
850 }
851
852 auto layerNameDecoded = UrlEncoding::decode(layerName);
853 if (layerNameDecoded.empty())
854 {
855 return crow::response(crow::status::BAD_REQUEST, "layer name not specified");
856 }
857
858 std::string etag;
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))
862 {
863 return std::move(*errorResponse);
864 }
865
866 auto& stepsByName = pFileArchive->GetStepsByName();
867 auto findIt = stepsByName.find(stepNameDecoded);
868 if (findIt == stepsByName.end())
869 {
870 std::stringstream ss;
871 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
872 return crow::response(crow::status::NOT_FOUND, ss.str());
873 }
874 auto& step = findIt->second;
875
876 auto& layersByName = step->GetLayersByName();
877 auto findIt2 = layersByName.find(layerNameDecoded);
878 if (findIt2 == layersByName.end())
879 {
880 std::stringstream ss;
881 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\"" << " layer: \"" << layerNameDecoded << "\"" << " not found";
882 return crow::response(crow::status::NOT_FOUND, ss.str());
883 }
884 auto& layer = findIt2->second;
885
886 auto& featuresFile = layer->GetFeaturesFile();
887 return withCacheHeaders(crow::response(JsonCrowReturnable(featuresFile)), etag);
888 }
889
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)
891 {
892 auto designNameDecoded = UrlEncoding::decode(designName);
893 if (designNameDecoded.empty())
894 {
895 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
896 }
897
898 auto stepNameDecoded = UrlEncoding::decode(stepName);
899 if (stepNameDecoded.empty())
900 {
901 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
902 }
903
904 auto layerNameDecoded = UrlEncoding::decode(layerName);
905 if (layerNameDecoded.empty())
906 {
907 return crow::response(crow::status::BAD_REQUEST, "layer name not specified");
908 }
909
910 std::string etag;
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))
914 {
915 return std::move(*errorResponse);
916 }
917
918 auto& stepsByName = pFileArchive->GetStepsByName();
919 auto findIt = stepsByName.find(stepNameDecoded);
920 if (findIt == stepsByName.end())
921 {
922 std::stringstream ss;
923 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
924 return crow::response(crow::status::NOT_FOUND, ss.str());
925 }
926 auto& step = findIt->second;
927
928 auto& layersByName = step->GetLayersByName();
929 auto findIt2 = layersByName.find(layerNameDecoded);
930 if (findIt2 == layersByName.end())
931 {
932 std::stringstream ss;
933 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\"" << " layer: \"" << layerNameDecoded << "\"" << " not found";
934 return crow::response(crow::status::NOT_FOUND, ss.str());
935 }
936 auto& layer = findIt2->second;
937
938 auto& attrlistFile = layer->GetAttrListFile();
939 return withCacheHeaders(crow::response(JsonCrowReturnable(attrlistFile)), etag);
940 }
941
942 crow::response FileModelController::steps_layers_list_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
943 {
944 auto designNameDecoded = UrlEncoding::decode(designName);
945 if (designNameDecoded.empty())
946 {
947 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
948 }
949
950 auto stepNameDecoded = UrlEncoding::decode(stepName);
951 if (stepNameDecoded.empty())
952 {
953 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
954 }
955
956 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
957 if (auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
958 {
959 return std::move(*errorResponse);
960 }
961
962 auto& stepsByName = pFileArchive->GetStepsByName();
963 auto findIt = stepsByName.find(stepNameDecoded);
964 if (findIt == stepsByName.end())
965 {
966 std::stringstream ss;
967 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
968 return crow::response(crow::status::NOT_FOUND, ss.str());
969 }
970 auto& step = findIt->second;
971
972 auto& layersByName = step->GetLayersByName();
973 crow::json::wvalue::list layerNames;
974 for (const auto& kvLayers : layersByName)
975 {
976 layerNames.push_back(kvLayers.first);
977 }
978
979 crow::json::wvalue jsonResponse;
980 jsonResponse["layers"] = std::move(layerNames);
981 return crow::response(jsonResponse);
982 }
983
984 crow::response FileModelController::steps_diagnostics_symbol_units_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
985 {
986 auto designNameDecoded = UrlEncoding::decode(designName);
987 if (designNameDecoded.empty())
988 {
989 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
990 }
991
992 auto stepNameDecoded = UrlEncoding::decode(stepName);
993 if (stepNameDecoded.empty())
994 {
995 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
996 }
997
998 std::string etag;
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))
1002 {
1003 return std::move(*errorResponse);
1004 }
1005
1006 auto& stepsByName = pFileArchive->GetStepsByName();
1007 auto findIt = stepsByName.find(stepNameDecoded);
1008 if (findIt == stepsByName.end())
1009 {
1010 std::stringstream ss;
1011 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
1012 return crow::response(crow::status::NOT_FOUND, ss.str());
1013 }
1014 auto& step = findIt->second;
1015
1016 const auto& layersByName = step->GetLayersByName();
1017 crow::json::wvalue::list layers;
1018 for (const auto& kv : layersByName)
1019 {
1020 const auto& layerName = kv.first;
1021 auto pLayer = kv.second;
1022 if (!pLayer) continue;
1023
1024 const auto& featuresFile = pLayer->GetFeaturesFile();
1025 const auto symbols = Odb::Lib::FileModel::Design::collect_symbols(featuresFile);
1026
1027 int metricCount = 0;
1028 int imperialCount = 0;
1029 int noneCount = 0;
1030 for (const auto& sym : symbols)
1031 {
1032 if (!sym) continue;
1033 switch (sym->GetUnitType())
1034 {
1035 case Odb::Lib::UnitType::Metric: metricCount++; break;
1036 case Odb::Lib::UnitType::Imperial: imperialCount++; break;
1037 case Odb::Lib::UnitType::None: noneCount++; break;
1038 }
1039 }
1040
1041 const auto rawUnits = featuresFile.GetUnits();
1043 const auto hasMixed = (metricCount > 0 && imperialCount > 0);
1044 const auto hasMismatch =
1045 (expected == Odb::Lib::UnitType::Metric && imperialCount > 0) ||
1046 (expected == Odb::Lib::UnitType::Imperial && metricCount > 0);
1047
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);
1058 }
1059
1060 crow::json::wvalue result;
1061 result["design"] = designNameDecoded;
1062 result["step"] = stepNameDecoded;
1063 result["layers"] = std::move(layers);
1064 return withCacheHeaders(crow::response(result), etag);
1065 }
1066
1067 crow::response FileModelController::steps_route_handler(const std::string& designName, const std::string& stepName, const crow::request& req)
1068 {
1069 auto designNameDecoded = UrlEncoding::decode(designName);
1070 if (designNameDecoded.empty())
1071 {
1072 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1073 }
1074
1075 auto stepNameDecoded = UrlEncoding::decode(stepName);
1076 if (stepNameDecoded.empty())
1077 {
1078 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
1079 }
1080
1081 std::string etag;
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))
1085 {
1086 return std::move(*errorResponse);
1087 }
1088
1089 auto& stepsByName = pFileArchive->GetStepsByName();
1090 auto findIt = stepsByName.find(stepNameDecoded);
1091 if (findIt == stepsByName.end())
1092 {
1093 std::stringstream ss;
1094 ss << "(design: \"" << designNameDecoded << "\")" << " step: \"" << stepNameDecoded << "\" not found";
1095 return crow::response(crow::status::NOT_FOUND, ss.str());
1096 }
1097
1098 auto& step = findIt->second;
1099 return withCacheHeaders(crow::response(JsonCrowReturnable(*step)), etag);
1100 }
1101
1102 crow::response FileModelController::symbols_route_handler(const std::string& designName, const std::string& symbolName, const crow::request& req)
1103 {
1104 auto designNameDecoded = UrlEncoding::decode(designName);
1105 if (designNameDecoded.empty())
1106 {
1107 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1108 }
1109
1110 auto symbolNameDecoded = UrlEncoding::decode(symbolName);
1111 if (symbolNameDecoded.empty())
1112 {
1113 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
1114 }
1115
1116 std::string etag;
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))
1120 {
1121 return std::move(*errorResponse);
1122 }
1123
1124 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1125 auto findIt = symbolsByName.find(symbolNameDecoded);
1126 if (findIt == symbolsByName.end())
1127 {
1128 std::stringstream ss;
1129 ss << "(design: \"" << designNameDecoded << "\")" << " symbol: \"" << symbolNameDecoded << "\" not found";
1130 return crow::response(crow::status::NOT_FOUND, ss.str());
1131 }
1132
1133 auto& symbol = findIt->second;
1134 return withCacheHeaders(crow::response(JsonCrowReturnable(*symbol)), etag);
1135 }
1136
1137 crow::response FileModelController::symbols_features_route_handler(const std::string& designName, const std::string& symbolName, const crow::request& req)
1138 {
1139 auto designNameDecoded = UrlEncoding::decode(designName);
1140 if (designNameDecoded.empty())
1141 {
1142 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1143 }
1144
1145 auto symbolNameDecoded = UrlEncoding::decode(symbolName);
1146 if (symbolNameDecoded.empty())
1147 {
1148 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
1149 }
1150
1151 std::string etag;
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))
1155 {
1156 return std::move(*errorResponse);
1157 }
1158
1159 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1160 auto findIt = symbolsByName.find(symbolNameDecoded);
1161 if (findIt == symbolsByName.end())
1162 {
1163 std::stringstream ss;
1164 ss << "(design: \"" << designNameDecoded << "\")" << " symbol: \"" << symbolNameDecoded << "\" not found";
1165 return crow::response(crow::status::NOT_FOUND, ss.str());
1166 }
1167 auto& symbol = findIt->second;
1168
1169 auto& featuresFile = symbol->GetFeaturesFile();
1170 return withCacheHeaders(crow::response(JsonCrowReturnable(featuresFile)), etag);
1171 }
1172
1173 crow::response FileModelController::symbols_attrlist_route_handler(const std::string& designName, const std::string& symbolName, const crow::request& req)
1174 {
1175 auto designNameDecoded = UrlEncoding::decode(designName);
1176 if (designNameDecoded.empty())
1177 {
1178 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1179 }
1180
1181 auto symbolNameDecoded = UrlEncoding::decode(symbolName);
1182 if (symbolNameDecoded.empty())
1183 {
1184 return crow::response(crow::status::BAD_REQUEST, "step name not specified");
1185 }
1186
1187 std::string etag;
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))
1191 {
1192 return std::move(*errorResponse);
1193 }
1194
1195 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1196 auto findIt = symbolsByName.find(symbolNameDecoded);
1197 if (findIt == symbolsByName.end())
1198 {
1199 std::stringstream ss;
1200 ss << "(design: \"" << designNameDecoded << "\")" << " symbol: \"" << symbolNameDecoded << "\" not found";
1201 return crow::response(crow::status::NOT_FOUND, ss.str());
1202 }
1203 auto& symbol = findIt->second;
1204
1205 auto& attrlistFile = symbol->GetAttrListFile();
1206 return withCacheHeaders(crow::response(JsonCrowReturnable(attrlistFile)), etag);
1207 }
1208
1209 crow::response FileModelController::symbols_list_route_handler(const std::string& designName, const crow::request& req)
1210 {
1211 auto designNameDecoded = UrlEncoding::decode(designName);
1212 if (designNameDecoded.empty())
1213 {
1214 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1215 }
1216
1217 std::shared_ptr<Odb::Lib::FileModel::Design::FileArchive> pFileArchive;
1218 if (auto errorResponse = TryGetFileArchive(designNameDecoded, pFileArchive))
1219 {
1220 return std::move(*errorResponse);
1221 }
1222
1223 auto& symbolsByName = pFileArchive->GetSymbolsDirectoriesByName();
1224 crow::json::wvalue::list symbolNames;
1225 for (const auto& kvSymbols : symbolsByName)
1226 {
1227 symbolNames.push_back(kvSymbols.first);
1228 }
1229
1230 crow::json::wvalue jsonResponse;
1231 jsonResponse["symbols"] = std::move(symbolNames);
1232 return crow::response(jsonResponse);
1233 }
1234
1235 crow::response FileModelController::filemodels_list_route_handler(const crow::request& req)
1236 {
1237 return makeLoadedFileModelsResponse(false);
1238 }
1239
1240 crow::response FileModelController::misc_attrlist_route_handler(const std::string& designName, const crow::request& req)
1241 {
1242 auto designNameDecoded = UrlEncoding::decode(designName);
1243 if (designNameDecoded.empty())
1244 {
1245 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1246 }
1247
1248 std::string etag;
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))
1252 {
1253 return std::move(*errorResponse);
1254 }
1255
1256 auto& miscAttrListFile = pFileArchive->GetMiscAttrListFile();
1257 return withCacheHeaders(crow::response(JsonCrowReturnable(miscAttrListFile)), etag);
1258 }
1259
1260 crow::response FileModelController::matrix_matrix_route_handler(const std::string& designName, const crow::request& req)
1261 {
1262 auto designNameDecoded = UrlEncoding::decode(designName);
1263 if (designNameDecoded.empty())
1264 {
1265 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1266 }
1267
1268 std::string etag;
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))
1272 {
1273 return std::move(*errorResponse);
1274 }
1275
1276 auto& matrixFile = pFileArchive->GetMatrixFile();
1277 return withCacheHeaders(crow::response(JsonCrowReturnable(matrixFile)), etag);
1278 }
1279
1280 crow::response FileModelController::misc_info_route_handler(const std::string& designName, const crow::request& req)
1281 {
1282 auto designNameDecoded = UrlEncoding::decode(designName);
1283 if (designNameDecoded.empty())
1284 {
1285 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1286 }
1287
1288 std::string etag;
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))
1292 {
1293 return std::move(*errorResponse);
1294 }
1295
1296 auto& miscInfoFile = pFileArchive->GetMiscInfoFile();
1297 return withCacheHeaders(crow::response(JsonCrowReturnable(miscInfoFile)), etag);
1298 }
1299
1300 crow::response FileModelController::fonts_standard_route_handler(const std::string& designName, const crow::request& req)
1301 {
1302 auto designNameDecoded = UrlEncoding::decode(designName);
1303 if (designNameDecoded.empty())
1304 {
1305 return crow::response(crow::status::BAD_REQUEST, "design name not specified");
1306 }
1307
1308 std::string etag;
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))
1312 {
1313 return std::move(*errorResponse);
1314 }
1315
1316 auto& standardFontsFile = pFileArchive->GetStandardFontsFile();
1317 return withCacheHeaders(crow::response(JsonCrowReturnable(standardFontsFile)), etag);
1318 }
1319}
#define logexception_msg(e, m)
Definition Logger.h:29
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
crow::response makeLoadedFileModelsResponse(bool) const
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)