mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-31 17:08:45 +01:00
Dependency cleanup (#627)
* DBConnection doesn't use ProjectFileIO or need friendship...
... Instead, it is given its own weak_ptr to the project
* Demote the bypass flag into DBConnection...
... So SqliteSampleBlock needs ProjectFileIO only to get the DBConnection
* Accessor functions for the connection objects for SqliteSampleBlock
* Another level of indirection to get to the DBConnection object...
... The document holds the unique_ptr to DBConnection in an attached object;
later we want the SqliteSampleBlockFactory to locate the same pointer without
using ProjectFileIO
* SqliteSampleBlock and its factory don't use class ProjectFileIO...
... Instead they share a pointer to the pointer to the current DBConnection.
This means they no longer know how to invoke the lazy opening of that
connection.
So just require that this be done before any operations on blocks happen. If
it hasn't, throw and let the application recover.
* ProjectFileIO no longer needs weak_ptr to Project for safety...
... so eliminate much ugliness from 127696879d
* Move DBConnection to new files...
... And SqliteSampleBlock does not depend on ProjectFileIO.
* SampleBlock.h doesn't need ClientData.h
* Function ProjectFileIO::Conn() isn't needed
This commit is contained in:
@@ -11,12 +11,7 @@ Paul Licameli split from AudacityProject.h
|
||||
#ifndef __AUDACITY_PROJECT_FILE_IO__
|
||||
#define __AUDACITY_PROJECT_FILE_IO__
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <set>
|
||||
|
||||
#include "ClientData.h" // to inherit
|
||||
@@ -60,9 +55,6 @@ public:
|
||||
static const ProjectFileIO &Get( const AudacityProject &project );
|
||||
|
||||
explicit ProjectFileIO( AudacityProject &project );
|
||||
// unfortunate two-step construction needed because of
|
||||
// enable_shared_from_this
|
||||
void Init( AudacityProject &project );
|
||||
|
||||
ProjectFileIO( const ProjectFileIO & ) PROHIBITED;
|
||||
ProjectFileIO &operator=( const ProjectFileIO & ) PROHIBITED;
|
||||
@@ -110,7 +102,6 @@ public:
|
||||
// SqliteSampleBlock::~SqliteSampleBlock()
|
||||
// ProjectManager::OnCloseWindow()
|
||||
void SetBypass();
|
||||
bool ShouldBypass();
|
||||
|
||||
// Remove all unused space within a project file
|
||||
void Vacuum(const std::shared_ptr<TrackList> &tracks);
|
||||
@@ -146,8 +137,6 @@ private:
|
||||
// if opening fails.
|
||||
sqlite3 *DB();
|
||||
|
||||
Connection &Conn();
|
||||
|
||||
bool OpenConnection(FilePath fileName = {});
|
||||
bool CloseConnection();
|
||||
|
||||
@@ -195,8 +184,10 @@ private:
|
||||
bool ShouldVacuum(const std::shared_ptr<TrackList> &tracks);
|
||||
|
||||
private:
|
||||
Connection &CurrConn();
|
||||
|
||||
// non-static data members
|
||||
std::weak_ptr<AudacityProject> mpProject;
|
||||
AudacityProject &mProject;
|
||||
|
||||
// The project's file path
|
||||
FilePath mFileName;
|
||||
@@ -210,9 +201,6 @@ private:
|
||||
// Is this project still a temporary/unsaved project
|
||||
bool mTemporary;
|
||||
|
||||
// Bypass transactions if database will be deleted after close
|
||||
bool mBypass;
|
||||
|
||||
// Project was vacuumed last time Vacuum() ran
|
||||
bool mWasVacuumed;
|
||||
|
||||
@@ -223,13 +211,10 @@ private:
|
||||
FilePath mPrevFileName;
|
||||
bool mPrevTemporary;
|
||||
|
||||
Connection mCurrConn;
|
||||
TranslatableString mLastError;
|
||||
TranslatableString mLibraryError;
|
||||
|
||||
friend SqliteSampleBlock;
|
||||
friend AutoCommitTransaction;
|
||||
friend DBConnection;
|
||||
};
|
||||
|
||||
class AutoCommitTransaction
|
||||
@@ -247,58 +232,6 @@ private:
|
||||
wxString mName;
|
||||
};
|
||||
|
||||
class DBConnection
|
||||
{
|
||||
public:
|
||||
DBConnection(ProjectFileIO *io);
|
||||
~DBConnection();
|
||||
|
||||
bool Open(const char *fileName);
|
||||
bool Close();
|
||||
|
||||
bool SafeMode(const char *schema = "main");
|
||||
bool FastMode(const char *schema = "main");
|
||||
|
||||
bool Assign(sqlite3 *handle);
|
||||
sqlite3 *Detach();
|
||||
|
||||
sqlite3 *DB();
|
||||
|
||||
int GetLastRC() const ;
|
||||
const wxString GetLastMessage() const;
|
||||
|
||||
enum StatementID
|
||||
{
|
||||
GetSamples,
|
||||
GetSummary256,
|
||||
GetSummary64k,
|
||||
LoadSampleBlock,
|
||||
InsertSampleBlock,
|
||||
DeleteSampleBlock
|
||||
};
|
||||
sqlite3_stmt *GetStatement(enum StatementID id);
|
||||
sqlite3_stmt *Prepare(enum StatementID id, const char *sql);
|
||||
|
||||
private:
|
||||
bool ModeConfig(sqlite3 *db, const char *schema, const char *config);
|
||||
|
||||
void CheckpointThread();
|
||||
static int CheckpointHook(void *data, sqlite3 *db, const char *schema, int pages);
|
||||
|
||||
private:
|
||||
ProjectFileIO &mIO;
|
||||
sqlite3 *mDB;
|
||||
|
||||
std::thread mCheckpointThread;
|
||||
std::condition_variable mCheckpointCondition;
|
||||
std::mutex mCheckpointMutex;
|
||||
std::atomic_bool mCheckpointStop{ false };
|
||||
std::atomic_int mCheckpointWaitingPages{ 0 };
|
||||
std::atomic_int mCheckpointCurrentPages{ 0 };
|
||||
|
||||
std::map<enum StatementID, sqlite3_stmt *> mStatements;
|
||||
};
|
||||
|
||||
class wxTopLevelWindow;
|
||||
|
||||
// TitleRestorer restores project window titles to what they were, in its destructor.
|
||||
|
||||
Reference in New Issue
Block a user