Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Klass <kissaki@posteo.de>2018-06-18 00:11:17 +0300
committerJan Klass <kissaki@posteo.de>2018-06-18 21:27:08 +0300
commit222def784593bfa5f7960f6c2ce0d299568c2cc9 (patch)
tree0bc5676117dd769522df3d97e8a9b4aafa86f114 /src/mumble/Database.h
parenta092a444c523c524013b2bb5c5cf4527870d033a (diff)
Fix #3411: Threaded access to Database
Qt5 documents that QSqlDatabase must not be called from varying threads. An instance must be limited to its thread. In Mumble the Database class handles database access. Up to now it contained static methods and always used the global default database instance. We instantiate the default database connection into the Global context. It is mostly used from the main event loop, but also from a thread in ServerHandler. This is broken as per specification, and Qt 5.11 seems to finally enforce that. To resolve this issue, we promote Database to an instantiable class, use the created Global context class instance from the event loop, and a distinct Database instance (and connection) from the ServerHandler instance (and thread).
Diffstat (limited to 'src/mumble/Database.h')
-rw-r--r--src/mumble/Database.h66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/mumble/Database.h b/src/mumble/Database.h
index 26b251eed..63c383465 100644
--- a/src/mumble/Database.h
+++ b/src/mumble/Database.h
@@ -6,6 +6,7 @@
#ifndef MUMBLE_MUMBLE_DATABASE_H_
#define MUMBLE_MUMBLE_DATABASE_H_
+#include <QSqlDatabase>
#include "Settings.h"
#include "UnresolvedServerAddress.h"
@@ -22,51 +23,54 @@ class Database : public QObject {
private:
Q_OBJECT
Q_DISABLE_COPY(Database)
+
+ QSqlDatabase db;
public:
- Database();
+ Database(const QString &dbname);
~Database() Q_DECL_OVERRIDE;
- static QList<FavoriteServer> getFavorites();
- static void setFavorites(const QList<FavoriteServer> &servers);
- static void setPassword(const QString &host, unsigned short port, const QString &user, const QString &pw);
- static bool fuzzyMatch(QString &name, QString &user, QString &pw, QString &host, unsigned short port);
- static bool isLocalIgnored(const QString &hash);
- static void setLocalIgnored(const QString &hash, bool ignored);
+ QList<FavoriteServer> getFavorites();
+ void setFavorites(const QList<FavoriteServer> &servers);
+ void setPassword(const QString &host, unsigned short port, const QString &user, const QString &pw);
+ bool fuzzyMatch(QString &name, QString &user, QString &pw, QString &host, unsigned short port);
+
+ bool isLocalIgnored(const QString &hash);
+ void setLocalIgnored(const QString &hash, bool ignored);
- static bool isLocalMuted(const QString &hash);
- static void setLocalMuted(const QString &hash, bool muted);
+ bool isLocalMuted(const QString &hash);
+ void setLocalMuted(const QString &hash, bool muted);
- static float getUserLocalVolume(const QString &hash);
- static void setUserLocalVolume(const QString &hash, float volume);
+ float getUserLocalVolume(const QString &hash);
+ void setUserLocalVolume(const QString &hash, float volume);
- static bool isChannelFiltered(const QByteArray &server_cert_digest, const int channel_id);
- static void setChannelFiltered(const QByteArray &server_cert_digest, const int channel_id, bool hidden);
+ bool isChannelFiltered(const QByteArray &server_cert_digest, const int channel_id);
+ void setChannelFiltered(const QByteArray &server_cert_digest, const int channel_id, bool hidden);
- static QMap<UnresolvedServerAddress, unsigned int> getPingCache();
- static void setPingCache(const QMap<UnresolvedServerAddress, unsigned int> &cache);
+ QMap<UnresolvedServerAddress, unsigned int> getPingCache();
+ void setPingCache(const QMap<UnresolvedServerAddress, unsigned int> &cache);
- static bool seenComment(const QString &hash, const QByteArray &commenthash);
- static void setSeenComment(const QString &hash, const QByteArray &commenthash);
+ bool seenComment(const QString &hash, const QByteArray &commenthash);
+ void setSeenComment(const QString &hash, const QByteArray &commenthash);
- static QByteArray blob(const QByteArray &hash);
- static void setBlob(const QByteArray &hash, const QByteArray &blob);
+ QByteArray blob(const QByteArray &hash);
+ void setBlob(const QByteArray &hash, const QByteArray &blob);
- static QStringList getTokens(const QByteArray &digest);
- static void setTokens(const QByteArray &digest, QStringList &tokens);
+ QStringList getTokens(const QByteArray &digest);
+ void setTokens(const QByteArray &digest, QStringList &tokens);
- static QList<Shortcut> getShortcuts(const QByteArray &digest);
- static bool setShortcuts(const QByteArray &digest, QList<Shortcut> &shortcuts);
+ QList<Shortcut> getShortcuts(const QByteArray &digest);
+ bool setShortcuts(const QByteArray &digest, QList<Shortcut> &shortcuts);
- static void addFriend(const QString &name, const QString &hash);
- static void removeFriend(const QString &hash);
- static const QString getFriend(const QString &hash);
- static const QMap<QString, QString> getFriends();
+ void addFriend(const QString &name, const QString &hash);
+ void removeFriend(const QString &hash);
+ const QString getFriend(const QString &hash);
+ const QMap<QString, QString> getFriends();
- static const QString getDigest(const QString &hostname, unsigned short port);
- static void setDigest(const QString &hostname, unsigned short port, const QString &digest);
+ const QString getDigest(const QString &hostname, unsigned short port);
+ void setDigest(const QString &hostname, unsigned short port, const QString &digest);
- static bool getUdp(const QByteArray &digest);
- static void setUdp(const QByteArray &digest, bool udp);
+ bool getUdp(const QByteArray &digest);
+ void setUdp(const QByteArray &digest, bool udp);
};
#endif