Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
audacity::sqlite::SafeConnection Class Referencefinal

A class representing a safe connection to SQLite. More...

#include <SafeConnection.h>

Inheritance diagram for audacity::sqlite::SafeConnection:
[legend]
Collaboration diagram for audacity::sqlite::SafeConnection:
[legend]

Classes

struct  Lock
 
struct  Tag
 

Public Member Functions

 SafeConnection (Tag, Connection connection)
 
Lock Acquire () noexcept
 

Static Public Member Functions

static std::shared_ptr< SafeConnectionOpen (std::string_view path, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized, Error *openError=nullptr)
 
static std::shared_ptr< SafeConnectionReopen (const Connection &connection, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized, Error *openError=nullptr)
 
static std::shared_ptr< SafeConnectionReopen (sqlite3 *connection, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized, Error *openError=nullptr)
 
static std::shared_ptr< SafeConnectionReopen (SafeConnection &connection, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized, Error *openError=nullptr)
 

Private Types

using MutexType = std::recursive_mutex
 

Private Attributes

Connection mConnection
 
MutexType mConnectionMutex
 

Detailed Description

A class representing a safe connection to SQLite.

This class is a wrapper around the Connection class that provides a thread-safe access to the connection.

Definition at line 21 of file SafeConnection.h.

Member Typedef Documentation

◆ MutexType

using audacity::sqlite::SafeConnection::MutexType = std::recursive_mutex
private

Definition at line 28 of file SafeConnection.h.

Constructor & Destructor Documentation

◆ SafeConnection()

audacity::sqlite::SafeConnection::SafeConnection ( Tag  ,
Connection  connection 
)

Definition at line 11 of file SafeConnection.cpp.

12 : mConnection(std::move(connection))
13{
14}

Member Function Documentation

◆ Acquire()

SafeConnection::Lock audacity::sqlite::SafeConnection::Acquire ( )
noexcept

Definition at line 85 of file SafeConnection.cpp.

86{
87 return Lock { shared_from_this() };
88}

◆ Open()

std::shared_ptr< SafeConnection > audacity::sqlite::SafeConnection::Open ( std::string_view  path,
OpenMode  mode = OpenMode::ReadWriteCreate,
ThreadMode  threadMode = ThreadMode::Serialized,
Error openError = nullptr 
)
static

Definition at line 16 of file SafeConnection.cpp.

19{
20 auto connection = Connection::Open(path, mode, threadMode);
21
22 if (!connection)
23 {
24 if (openError)
25 *openError = connection.GetError();
26
27 return {};
28 }
29
30 return std::make_shared<SafeConnection>(Tag {}, std::move(*connection));
31}
static Result< Connection > Open(std::string_view path, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized)
Opens a connection to a database.
Definition: Connection.cpp:21

References audacity::sqlite::Connection::Open().

Referenced by audacity::cloud::audiocom::sync::CloudProjectsDatabase::OpenConnection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reopen() [1/3]

std::shared_ptr< SafeConnection > audacity::sqlite::SafeConnection::Reopen ( const Connection connection,
OpenMode  mode = OpenMode::ReadWriteCreate,
ThreadMode  threadMode = ThreadMode::Serialized,
Error openError = nullptr 
)
static

Definition at line 33 of file SafeConnection.cpp.

36{
37 auto connection = Connection::Reopen(prevConnection, mode, threadMode);
38
39 if (!connection)
40 {
41 if (openError)
42 *openError = connection.GetError();
43
44 return {};
45 }
46
47 return std::make_shared<SafeConnection>(Tag {}, std::move(*connection));
48}
static Result< Connection > Reopen(const Connection &connection, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized)
Definition: Connection.cpp:82

References audacity::sqlite::Connection::Reopen().

Here is the call graph for this function:

◆ Reopen() [2/3]

std::shared_ptr< SafeConnection > audacity::sqlite::SafeConnection::Reopen ( SafeConnection connection,
OpenMode  mode = OpenMode::ReadWriteCreate,
ThreadMode  threadMode = ThreadMode::Serialized,
Error openError = nullptr 
)
static

Definition at line 67 of file SafeConnection.cpp.

70{
71 auto connection =
72 Connection::Reopen(prevConnection.mConnection, mode, threadMode);
73
74 if (!connection)
75 {
76 if (openError)
77 *openError = connection.GetError();
78
79 return {};
80 }
81
82 return std::make_shared<SafeConnection>(Tag {}, std::move(*connection));
83}

References mConnection, and audacity::sqlite::Connection::Reopen().

Here is the call graph for this function:

◆ Reopen() [3/3]

std::shared_ptr< SafeConnection > audacity::sqlite::SafeConnection::Reopen ( sqlite3 *  connection,
OpenMode  mode = OpenMode::ReadWriteCreate,
ThreadMode  threadMode = ThreadMode::Serialized,
Error openError = nullptr 
)
static

Definition at line 50 of file SafeConnection.cpp.

53{
54 auto connection = Connection::Reopen(prevConnection, mode, threadMode);
55
56 if (!connection)
57 {
58 if (openError)
59 *openError = connection.GetError();
60
61 return {};
62 }
63
64 return std::make_shared<SafeConnection>(Tag {}, std::move(*connection));
65}

References audacity::sqlite::Connection::Reopen().

Here is the call graph for this function:

Member Data Documentation

◆ mConnection

Connection audacity::sqlite::SafeConnection::mConnection
private

Definition at line 80 of file SafeConnection.h.

Referenced by Reopen().

◆ mConnectionMutex

MutexType audacity::sqlite::SafeConnection::mConnectionMutex
private

Definition at line 81 of file SafeConnection.h.


The documentation for this class was generated from the following files: