OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
OdbAppBase.cpp
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
22 OdbAppBase::~OdbAppBase()
23 {
24 Logger::instance()->stop();
25 google::protobuf::ShutdownProtobufLibrary();
26 }
27
28 const OdbDesignArgs& OdbAppBase::args() const
29 {
30 return m_commandLineArgs;
31 }
32
33 DesignCache& OdbAppBase::designs()
34 {
35 return m_designCache;
36 }
37
38 Utils::ExitCode OdbAppBase::Run()
39 {
40 //Logger::instance()->logLevel(Logger::Level::Debug);
41 Logger::instance()->logLevel(Logger::Level::Info);
42 Logger::instance()->start();
43
44 // set designs dir if passed in
45 if (!args().designsDir().empty())
46 {
47 designs().setDirectory(args().designsDir());
48 }
49
50 // load a design if specified via command line args
51 if (!args().loadDesign().empty())
52 {
53 try
54 {
55 auto pFileArchive =
56 //designs().GetDesign(args().loadDesign());
57 designs().GetFileArchive(args().loadDesign());
58 if (pFileArchive == nullptr)
59 {
60 logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
61 return Utils::ExitCode::FailedInitLoadDesign;
62 }
63 else
64 {
65 //std::string filename =
66 pFileArchive->SaveFileModel(".", "notused");
67 }
68 }
69 catch (filesystem_error& fe)
70 {
71 logexception(fe);
72 logerror("filesystem_error: \"" + args().loadDesign() + "\" " + fe.what());
73 }
74 catch (std::exception& e)
75 {
76 logexception(e);
77 logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
78 return Utils::ExitCode::FailedInitLoadDesign;
79 }
80 }
81
82 // load all designs from designs-dir if specified
83 if (args().loadAll())
84 {
85 designs().loadAllDesigns(false);
86 }
87
88 return Utils::ExitCode::Success;
89 }
90}