From be1a19f7c7654710a065d83c9cda1997823b3f00 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 22 Aug 2020 02:30:00 +0100 Subject: [PATCH] Move backend name to config file Still, only one backend is available at this point. --- orotool.conf | 1 + src/app_config.cpp | 7 +++++++ src/app_config.hpp | 1 + src/config.hpp.in | 8 ++++++++ src/main.cpp | 2 +- src/oro/originsdb.cpp | 2 +- 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/orotool.conf b/orotool.conf index aac4ee0..9e824bf 100644 --- a/orotool.conf +++ b/orotool.conf @@ -1,6 +1,7 @@ [system] db_path=originsro.db3 worker_threads=3 +backend=sqlite [rules] fetch_extra_delay=30 diff --git a/src/app_config.cpp b/src/app_config.cpp index 6173536..aee069c 100644 --- a/src/app_config.cpp +++ b/src/app_config.cpp @@ -34,6 +34,9 @@ namespace { constexpr const char g_worker_threads_sect[] = "system"; constexpr const char g_worker_threads[] = "worker_threads"; + constexpr const char g_backend_sect[] = "system"; + constexpr const char g_backend[] = "backend"; + constexpr const char g_fetch_extra_delay_sect[] = "rules"; constexpr const char g_fetch_extra_delay[] = "fetch_extra_delay"; constexpr const char g_fetch_extra_delay_def[] = "30"; @@ -125,4 +128,8 @@ std::size_t AppConfig::fetch_extra_delay() const { } } +std::string_view AppConfig::backend() const { + return value_ifp(m_ini, g_backend_sect, g_backend, g_def_backend_name, false); +} + } //namespace duck diff --git a/src/app_config.hpp b/src/app_config.hpp index d940eb7..dfe9f96 100644 --- a/src/app_config.hpp +++ b/src/app_config.hpp @@ -32,6 +32,7 @@ public: std::string_view api_key() const; std::size_t worker_threads() const; std::size_t fetch_extra_delay() const; + std::string_view backend() const; private: kamokan::IniFile m_ini; diff --git a/src/config.hpp.in b/src/config.hpp.in index 0e5c715..15135bb 100644 --- a/src/config.hpp.in +++ b/src/config.hpp.in @@ -31,4 +31,12 @@ constexpr const unsigned short int g_version_patch = @PROJECT_VERSION_PATCH@; #mesondefine OROTOOL_WITH_SQLITE +#if defined(OROTOOL_WITH_SQLITE) +constexpr const char g_sqlite_backend_name[] = "sqlite"; +#endif + +#if defined(OROTOOL_WITH_SQLITE) +inline constexpr const auto& g_def_backend_name = g_sqlite_backend_name; +#endif + } //namespace duck diff --git a/src/main.cpp b/src/main.cpp index e947104..89766b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) { print_ping(oro_api); - std::unique_ptr db(oro::OriginsDB::make("sqlite", app_conf.db_path())); + std::unique_ptr db(oro::OriginsDB::make(app_conf.backend(), app_conf.db_path())); duck::test( &oro_api, diff --git a/src/oro/originsdb.cpp b/src/oro/originsdb.cpp index 4fb5d8b..e9f95e3 100644 --- a/src/oro/originsdb.cpp +++ b/src/oro/originsdb.cpp @@ -29,7 +29,7 @@ namespace oro { return {}; } #if defined(OROTOOL_WITH_SQLITE) - else if (name == "sqlite") { + else if (name == duck::g_sqlite_backend_name) { return std::make_unique(param); } #endif