mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Rename settings stuff as it got moved to commonlib.
This commit is contained in:
parent
6e7176be10
commit
74afa9f502
7 changed files with 32 additions and 27 deletions
|
@ -21,8 +21,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace din {
|
namespace dinlib {
|
||||||
struct DinDBSettings {
|
struct SettingsDB {
|
||||||
std::string address;
|
std::string address;
|
||||||
std::string username;
|
std::string username;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
@ -30,10 +30,11 @@ namespace din {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
};
|
};
|
||||||
|
|
||||||
//struct DinSettings {
|
struct Settings {
|
||||||
//};
|
SettingsDB db;
|
||||||
|
};
|
||||||
|
|
||||||
bool load_settings ( const std::string& parPath, DinDBSettings& parOut );
|
bool load_settings ( const std::string& parPath, Settings& parOut );
|
||||||
} //namespace din
|
} //namespace dinlib
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
template<>
|
template<>
|
||||||
struct convert<din::DinDBSettings> {
|
struct convert<dinlib::SettingsDB> {
|
||||||
static Node encode (const din::DinDBSettings& parSettings) {
|
static Node encode (const dinlib::SettingsDB& parSettings) {
|
||||||
Node node;
|
Node node;
|
||||||
node["address"] = parSettings.address;
|
node["address"] = parSettings.address;
|
||||||
node["username"] = parSettings.username;
|
node["username"] = parSettings.username;
|
||||||
|
@ -32,7 +32,7 @@ namespace YAML {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool decode (const Node& parNode, din::DinDBSettings& parSettings) {
|
static bool decode (const Node& parNode, dinlib::SettingsDB& parSettings) {
|
||||||
if (not parNode.IsMap() or parNode.size() != 5) {
|
if (not parNode.IsMap() or parNode.size() != 5) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,13 @@ namespace YAML {
|
||||||
};
|
};
|
||||||
} //namespace YAML
|
} //namespace YAML
|
||||||
|
|
||||||
namespace din {
|
namespace dinlib {
|
||||||
bool load_settings (const std::string& parPath, DinDBSettings& parOut) {
|
bool load_settings (const std::string& parPath, dinlib::Settings& parOut) {
|
||||||
try {
|
try {
|
||||||
auto settings = YAML::LoadFile(parPath);
|
auto settings = YAML::LoadFile(parPath);
|
||||||
|
|
||||||
if (settings["db_settings"]) {
|
if (settings["db_settings"]) {
|
||||||
parOut = settings["db_settings"].as<DinDBSettings>();
|
parOut.db = settings["db_settings"].as<dinlib::SettingsDB>();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,4 @@ namespace din {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} //namespace din
|
} //namespace dinlib
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace din {
|
||||||
}
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
bool read_from_db (FileRecordData& parItem, SetRecordDataFull& parSet, const DinDBSettings& parDB, std::string&& parHash) {
|
bool read_from_db (FileRecordData& parItem, SetRecordDataFull& parSet, const dinlib::SettingsDB& parDB, std::string&& parHash) {
|
||||||
using boost::lexical_cast;
|
using boost::lexical_cast;
|
||||||
|
|
||||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||||
|
@ -93,7 +93,7 @@ namespace din {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_to_db (const DinDBSettings& parDB, const std::vector<FileRecordData>& parData, const SetRecordData& parSetData) {
|
void write_to_db (const dinlib::SettingsDB& parDB, const std::vector<FileRecordData>& parData, const SetRecordData& parSetData) {
|
||||||
auto bool_to_str = [](bool b) { return (b ? "true" : "false"); };
|
auto bool_to_str = [](bool b) { return (b ? "true" : "false"); };
|
||||||
if (parData.empty()) {
|
if (parData.empty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -24,9 +24,11 @@
|
||||||
#include <boost/utility/string_ref.hpp>
|
#include <boost/utility/string_ref.hpp>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
namespace din {
|
namespace dinlib {
|
||||||
struct DinDBSettings;
|
struct SettingsDB;;
|
||||||
|
} //namespace dinlib
|
||||||
|
|
||||||
|
namespace din {
|
||||||
struct FileRecordData {
|
struct FileRecordData {
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string hash;
|
std::string hash;
|
||||||
|
@ -51,8 +53,8 @@ namespace din {
|
||||||
const char type;
|
const char type;
|
||||||
};
|
};
|
||||||
|
|
||||||
void write_to_db ( const DinDBSettings& parDB, const std::vector<FileRecordData>& parData, const SetRecordData& parSetData );
|
void write_to_db ( const dinlib::SettingsDB& parDB, const std::vector<FileRecordData>& parData, const SetRecordData& parSetData );
|
||||||
bool read_from_db ( FileRecordData& parItem, SetRecordDataFull& parSet, const DinDBSettings& parDB, std::string&& parHash );
|
bool read_from_db ( FileRecordData& parItem, SetRecordDataFull& parSet, const dinlib::SettingsDB& parDB, std::string&& parHash );
|
||||||
} //namespace din
|
} //namespace din
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -184,7 +184,7 @@ namespace din {
|
||||||
struct Indexer::LocalData {
|
struct Indexer::LocalData {
|
||||||
typedef std::vector<FileEntry> PathList;
|
typedef std::vector<FileEntry> PathList;
|
||||||
|
|
||||||
DinDBSettings db_settings;
|
dinlib::SettingsDB db_settings;
|
||||||
PathList paths;
|
PathList paths;
|
||||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
std::atomic<std::size_t> done_count;
|
std::atomic<std::size_t> done_count;
|
||||||
|
@ -212,7 +212,7 @@ namespace din {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
Indexer::Indexer (const DinDBSettings& parDBSettings) :
|
Indexer::Indexer (const dinlib::Settings& parSettings) :
|
||||||
m_local_data(new LocalData)
|
m_local_data(new LocalData)
|
||||||
{
|
{
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
|
@ -232,7 +232,7 @@ namespace din {
|
||||||
m_local_data->processing_index = 0;
|
m_local_data->processing_index = 0;
|
||||||
#endif
|
#endif
|
||||||
m_local_data->file_count = 0;
|
m_local_data->file_count = 0;
|
||||||
m_local_data->db_settings = parDBSettings;
|
m_local_data->db_settings = parSettings.db;
|
||||||
}
|
}
|
||||||
|
|
||||||
Indexer::~Indexer() noexcept {
|
Indexer::~Indexer() noexcept {
|
||||||
|
|
|
@ -35,12 +35,14 @@ namespace fastf {
|
||||||
struct FileStats;
|
struct FileStats;
|
||||||
} //namespace fastf
|
} //namespace fastf
|
||||||
|
|
||||||
namespace din {
|
namespace dinlib {
|
||||||
struct DinDBSettings;
|
struct Settings;
|
||||||
|
} //namespace dinlib
|
||||||
|
|
||||||
|
namespace din {
|
||||||
class Indexer {
|
class Indexer {
|
||||||
public:
|
public:
|
||||||
explicit Indexer ( const DinDBSettings& parDBSettings );
|
explicit Indexer ( const dinlib::Settings& parSettings );
|
||||||
Indexer ( Indexer&& ) = default;
|
Indexer ( Indexer&& ) = default;
|
||||||
Indexer ( const Indexer& ) = delete;
|
Indexer ( const Indexer& ) = delete;
|
||||||
~Indexer ( void ) noexcept;
|
~Indexer ( void ) noexcept;
|
||||||
|
|
|
@ -64,9 +64,9 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
const bool verbose = false;
|
const bool verbose = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
din::DinDBSettings settings;
|
dinlib::Settings settings;
|
||||||
{
|
{
|
||||||
const bool loaded = din::load_settings(expand(CONFIG_FILE_PATH), settings);
|
const bool loaded = dinlib::load_settings(expand(CONFIG_FILE_PATH), settings);
|
||||||
if (not loaded) {
|
if (not loaded) {
|
||||||
std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n";
|
std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue