OdbDesignLib
OdbDesign ODB++ Parsing Library
All Classes
OdbAppBase.cpp
1 #include "OdbServerAppBase.h"
2 #include "Logger.h"
3 #include <filesystem>
4 
5 using namespace Utils;
6 using namespace std::filesystem;
7 
8 namespace Odb::Lib::App
9 {
10  OdbAppBase::OdbAppBase(int argc, char* argv[])
11  : m_designCache(DEFAULT_DESIGNS_DIR)
12  , m_commandLineArgs(argc, argv)
13  {
14  GOOGLE_PROTOBUF_VERIFY_VERSION;
15  }
16 
17  OdbAppBase::~OdbAppBase()
18  {
19  Logger::instance()->stop();
20  google::protobuf::ShutdownProtobufLibrary();
21  }
22 
23  const OdbDesignArgs& OdbAppBase::args() const
24  {
25  return m_commandLineArgs;
26  }
27 
28  DesignCache& OdbAppBase::designs()
29  {
30  return m_designCache;
31  }
32 
33  Utils::ExitCode OdbAppBase::Run()
34  {
35  //Logger::instance()->logLevel(Logger::Level::Debug);
36  Logger::instance()->logLevel(Logger::Level::Info);
37  Logger::instance()->start();
38 
39  // set designs dir if passed in
40  if (!args().designsDir().empty())
41  {
42  designs().setDirectory(args().designsDir());
43  }
44 
45  // load a design if specified via command line args
46  if (!args().loadDesign().empty())
47  {
48  try
49  {
50  auto pFileArchive =
51  //designs().GetDesign(args().loadDesign());
52  designs().GetFileArchive(args().loadDesign());
53  if (pFileArchive == nullptr)
54  {
55  logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
56  return Utils::ExitCode::FailedInitLoadDesign;
57  }
58  else
59  {
60  //std::string filename =
61  pFileArchive->SaveFileModel(".", "notused");
62  }
63  }
64  catch (filesystem_error& fe)
65  {
66  logexception(fe);
67  logerror("filesystem_error: \"" + args().loadDesign() + "\" " + fe.what());
68  }
69  catch (std::exception& e)
70  {
71  logexception(e);
72  logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
73  return Utils::ExitCode::FailedInitLoadDesign;
74  }
75  }
76 
77  // load all designs from designs-dir if specified
78  if (args().loadAll())
79  {
80  designs().loadAllDesigns(false);
81  }
82 
83  return Utils::ExitCode::Success;
84  }
85 }