OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
OdbAppBase.cpp
Go to the documentation of this file.
1#include "Logger.h"
2#include <filesystem>
3#include <exception>
4#include "DesignCache.h"
5#include "OdbAppBase.h"
6#include "OdbDesignArgs.h"
7#include <google/protobuf/stubs/common.h>
8#include <ExitCode.h>
9
10using namespace Utils;
11using namespace std::filesystem;
12
13namespace Odb::Lib::App
14{
15 OdbAppBase::OdbAppBase(int argc, char* argv[])
16 : m_designCache(DEFAULT_DESIGNS_DIR)
17 , m_commandLineArgs(argc, argv)
18 {
19 GOOGLE_PROTOBUF_VERIFY_VERSION;
20 }
21
23 {
25 google::protobuf::ShutdownProtobufLibrary();
26 }
27
29 {
30 return m_commandLineArgs;
31 }
32
37
39 {
40 //Logger::instance()->logLevel(Logger::Level::Debug);
41 Logger::instance()->logLevel(Logger::Level::Info);
43
44 // set designs dir if passed in
45 if (!args().designsDir().empty())
46 {
47 designs().setDirectory(args().designsDir());
48 }
49
50 // set the design cache byte budget (--cache-max-mb, 0 disables eviction)
51 designs().setCacheMaxBytes(static_cast<std::uint64_t>(args().cacheMaxMb()) * 1024ull * 1024ull);
52
53 // cap concurrent background parses kicked via LoadDesignAsync
54 // (--max-background-loads, 0 = unbounded)
55 designs().setMaxBackgroundLoads(static_cast<std::size_t>(args().maxBackgroundLoads()));
56
57 // load a design if specified via command line args
58 if (!args().loadDesign().empty())
59 {
60 try
61 {
62 auto pFileArchive =
63 //designs().GetDesign(args().loadDesign());
64 designs().GetFileArchive(args().loadDesign());
65 if (pFileArchive == nullptr)
66 {
67 logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
69 }
70 else
71 {
72 //std::string filename =
73 pFileArchive->SaveFileModel(".", "notused");
74 }
75 }
76 catch (filesystem_error& fe)
77 {
78 logexception(fe);
79 logerror("filesystem_error: \"" + args().loadDesign() + "\" " + fe.what());
80 }
81 catch (std::exception& e)
82 {
83 logexception(e);
84 logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
86 }
87 }
88
89 // load all designs from designs-dir if specified
90 if (args().loadAll())
91 {
92 designs().loadAllDesigns(false);
93 }
94
96 }
97}
#define logerror(s)
Definition Logger.h:17
#define logexception(e)
Definition Logger.h:26
int loadAllDesigns(bool stopOnError)
void setMaxBackgroundLoads(std::size_t maxLoads)
std::shared_ptr< FileModel::Design::FileArchive > GetFileArchive(const std::string &designName)
void setDirectory(const std::string &directory)
void setCacheMaxBytes(std::uint64_t maxBytes)
OdbAppBase(int argc, char *argv[])
DesignCache & designs() override
const OdbDesignArgs & args() const override
const OdbDesignArgs m_commandLineArgs
Definition OdbAppBase.h:27
virtual Utils::ExitCode Run() override
void stop()
Definition Logger.cpp:126
Level logLevel() const
Definition Logger.cpp:42
void start()
Definition Logger.cpp:120
static Logger * instance()
Definition Logger.cpp:31
ExitCode
Definition ExitCode.h:7