mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +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 <cstdint>
|
||||
|
||||
namespace din {
|
||||
struct DinDBSettings {
|
||||
namespace dinlib {
|
||||
struct SettingsDB {
|
||||
std::string address;
|
||||
std::string username;
|
||||
std::string password;
|
||||
|
@ -30,10 +30,11 @@ namespace din {
|
|||
uint16_t port;
|
||||
};
|
||||
|
||||
//struct DinSettings {
|
||||
//};
|
||||
struct Settings {
|
||||
SettingsDB db;
|
||||
};
|
||||
|
||||
bool load_settings ( const std::string& parPath, DinDBSettings& parOut );
|
||||
} //namespace din
|
||||
bool load_settings ( const std::string& parPath, Settings& parOut );
|
||||
} //namespace dinlib
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<din::DinDBSettings> {
|
||||
static Node encode (const din::DinDBSettings& parSettings) {
|
||||
struct convert<dinlib::SettingsDB> {
|
||||
static Node encode (const dinlib::SettingsDB& parSettings) {
|
||||
Node node;
|
||||
node["address"] = parSettings.address;
|
||||
node["username"] = parSettings.username;
|
||||
|
@ -32,7 +32,7 @@ namespace YAML {
|
|||
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) {
|
||||
return false;
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ namespace YAML {
|
|||
};
|
||||
} //namespace YAML
|
||||
|
||||
namespace din {
|
||||
bool load_settings (const std::string& parPath, DinDBSettings& parOut) {
|
||||
namespace dinlib {
|
||||
bool load_settings (const std::string& parPath, dinlib::Settings& parOut) {
|
||||
try {
|
||||
auto settings = YAML::LoadFile(parPath);
|
||||
|
||||
if (settings["db_settings"]) {
|
||||
parOut = settings["db_settings"].as<DinDBSettings>();
|
||||
parOut.db = settings["db_settings"].as<dinlib::SettingsDB>();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -63,4 +63,4 @@ namespace din {
|
|||
|
||||
return false;
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinlib
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace din {
|
|||
}
|
||||
} //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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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"); };
|
||||
if (parData.empty()) {
|
||||
return;
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
#include <boost/utility/string_ref.hpp>
|
||||
#include <ctime>
|
||||
|
||||
namespace din {
|
||||
struct DinDBSettings;
|
||||
namespace dinlib {
|
||||
struct SettingsDB;;
|
||||
} //namespace dinlib
|
||||
|
||||
namespace din {
|
||||
struct FileRecordData {
|
||||
std::string path;
|
||||
std::string hash;
|
||||
|
@ -51,8 +53,8 @@ namespace din {
|
|||
const char type;
|
||||
};
|
||||
|
||||
void write_to_db ( const DinDBSettings& parDB, const std::vector<FileRecordData>& parData, const SetRecordData& parSetData );
|
||||
bool read_from_db ( FileRecordData& parItem, SetRecordDataFull& parSet, const DinDBSettings& parDB, std::string&& parHash );
|
||||
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 dinlib::SettingsDB& parDB, std::string&& parHash );
|
||||
} //namespace din
|
||||
|
||||
#endif
|
||||
|
|
|
@ -184,7 +184,7 @@ namespace din {
|
|||
struct Indexer::LocalData {
|
||||
typedef std::vector<FileEntry> PathList;
|
||||
|
||||
DinDBSettings db_settings;
|
||||
dinlib::SettingsDB db_settings;
|
||||
PathList paths;
|
||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||
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)
|
||||
{
|
||||
#if !defined(NDEBUG)
|
||||
|
@ -232,7 +232,7 @@ namespace din {
|
|||
m_local_data->processing_index = 0;
|
||||
#endif
|
||||
m_local_data->file_count = 0;
|
||||
m_local_data->db_settings = parDBSettings;
|
||||
m_local_data->db_settings = parSettings.db;
|
||||
}
|
||||
|
||||
Indexer::~Indexer() noexcept {
|
||||
|
|
|
@ -35,12 +35,14 @@ namespace fastf {
|
|||
struct FileStats;
|
||||
} //namespace fastf
|
||||
|
||||
namespace din {
|
||||
struct DinDBSettings;
|
||||
namespace dinlib {
|
||||
struct Settings;
|
||||
} //namespace dinlib
|
||||
|
||||
namespace din {
|
||||
class Indexer {
|
||||
public:
|
||||
explicit Indexer ( const DinDBSettings& parDBSettings );
|
||||
explicit Indexer ( const dinlib::Settings& parSettings );
|
||||
Indexer ( Indexer&& ) = default;
|
||||
Indexer ( const Indexer& ) = delete;
|
||||
~Indexer ( void ) noexcept;
|
||||
|
|
|
@ -64,9 +64,9 @@ int main (int parArgc, char* parArgv[]) {
|
|||
const bool verbose = false;
|
||||
#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) {
|
||||
std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n";
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue