Calculate program file directories:

* Determine location of database files in Config
* Inject database directory or file path in PeerFinder and Validators
* PeerFinder and Validators will share the same sqlite file
This commit is contained in:
Nik Bougalis
2014-02-28 09:19:37 -08:00
committed by Vinnie Falco
parent e055dc1513
commit 28c7827f14
9 changed files with 84 additions and 32 deletions

View File

@@ -39,6 +39,7 @@ public:
static Manager* New (
Stoppable& parent,
SiteFiles::Manager& siteFiles,
File const& pathToDbFileOrDirectory,
Callback& callback,
clock_type& clock,
Journal journal);

View File

@@ -30,6 +30,7 @@ class ManagerImp
public:
ServiceQueue m_queue;
SiteFiles::Manager& m_siteFiles;
File m_databaseFile;
clock_type& m_clock;
Journal m_journal;
StoreSqdb m_store;
@@ -43,12 +44,14 @@ public:
ManagerImp (
Stoppable& stoppable,
SiteFiles::Manager& siteFiles,
File const& pathToDbFileOrDirectory,
Callback& callback,
clock_type& clock,
Journal journal)
: Manager (stoppable)
, Thread ("PeerFinder")
, m_siteFiles (siteFiles)
, m_databaseFile (pathToDbFileOrDirectory)
, m_clock (clock)
, m_journal (journal)
, m_store (journal)
@@ -56,6 +59,8 @@ public:
, m_logic (clock, callback, m_store, m_checker, journal)
, m_secondsTimer (this)
{
if (m_databaseFile.isDirectory ())
m_databaseFile = m_databaseFile.getChildFile("peerfinder.sqlite");
}
~ManagerImp ()
@@ -262,15 +267,12 @@ public:
{
m_journal.debug << "Initializing";
File const file (File::getSpecialLocation (
File::userDocumentsDirectory).getChildFile ("PeerFinder.sqlite"));
Error error (m_store.open (file));
Error error (m_store.open (m_databaseFile));
if (error)
{
m_journal.fatal <<
"Failed to open '" << file.getFullPathName() << "'";
"Failed to open '" << m_databaseFile.getFullPathName() << "'";
}
if (! error)
@@ -311,11 +313,13 @@ Manager::Manager (Stoppable& parent)
Manager* Manager::New (
Stoppable& parent,
SiteFiles::Manager& siteFiles,
File const& databaseFile,
Callback& callback,
clock_type& clock,
Journal journal)
{
return new ManagerImp (parent, siteFiles, callback, clock, journal);
return new ManagerImp (parent, siteFiles, databaseFile,
callback, clock, journal);
}
}

View File

@@ -36,9 +36,13 @@ protected:
public:
/** Create a new Manager object.
@param parent The parent Stoppable.
@param pathToDbFileOrDirectory The directory where our database is stored
@param journal Where to send log output.
*/
static Manager* New (Stoppable& stoppableParent, Journal journal);
static Manager* New (
Stoppable& stoppableParent,
File const& pathToDbFileOrDirectory,
Journal journal);
/** Destroy the object.
Any pending source fetch operations are aborted. This will block

View File

@@ -134,6 +134,7 @@ class ManagerImp
{
public:
Journal m_journal;
File m_databaseFile;
StoreSqdb m_store;
Logic m_logic;
DeadlineTimer m_checkTimer;
@@ -149,10 +150,14 @@ public:
//
bool m_checkSources;
ManagerImp (Stoppable& parent, Journal journal)
ManagerImp (
Stoppable& parent,
File const& pathToDbFileOrDirectory,
Journal journal)
: Stoppable ("Validators::Manager", parent)
, Thread ("Validators")
, m_journal (journal)
, m_databaseFile (pathToDbFileOrDirectory)
, m_store (m_journal)
, m_logic (m_store, m_journal)
, m_checkTimer (this)
@@ -164,6 +169,11 @@ public:
"Validators constructed (debug)";
m_journal.info <<
"Validators constructed (info)";
if (m_databaseFile.isDirectory ())
m_databaseFile = m_databaseFile.getChildFile("validators.sqlite");
}
~ManagerImp ()
@@ -306,11 +316,8 @@ public:
void init ()
{
File const file (File::getSpecialLocation (
File::userDocumentsDirectory).getChildFile ("validators.sqlite"));
Error error (m_store.open (m_databaseFile));
Error error (m_store.open (file));
if (! error)
{
m_logic.load ();
@@ -375,9 +382,12 @@ Manager::Manager ()
{
}
Validators::Manager* Validators::Manager::New (Stoppable& parent, Journal journal)
Validators::Manager* Validators::Manager::New (
Stoppable& parent,
File const& pathToDbFileOrDirectory,
Journal journal)
{
return new Validators::ManagerImp (parent, journal);
return new Validators::ManagerImp (parent, pathToDbFileOrDirectory, journal);
}
}