Skip to content

Commit

Permalink
Intermediate commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopheLarchier committed Oct 16, 2024
1 parent f6552a8 commit 436af1e
Show file tree
Hide file tree
Showing 26 changed files with 224 additions and 110 deletions.
1 change: 1 addition & 0 deletions src/gui/parameterscache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ std::shared_ptr<ParametersCache> ParametersCache::instance() noexcept {
try {
_instance = std::shared_ptr<ParametersCache>(new ParametersCache());
} catch (...) {
assert(false);
return nullptr;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/parameterscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace KDC {
class ParametersCache {
public:
static std::shared_ptr<ParametersCache> instance() noexcept;
inline static bool isExtendedLogEnabled() noexcept { return instance()->_parametersInfo.extendedLog(); };
inline static bool isExtendedLogEnabled() noexcept { return instance()->_parametersInfo.extendedLog(); }

ParametersCache(ParametersCache const &) = delete;
void operator=(ParametersCache const &) = delete;
Expand Down
9 changes: 7 additions & 2 deletions src/libcommon/keychainmanager/keychainmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ static const std::string dummyData("dummy");

std::shared_ptr<KeyChainManager> KeyChainManager::_instance = nullptr;

std::shared_ptr<KeyChainManager> KeyChainManager::instance(bool testing) {
std::shared_ptr<KeyChainManager> KeyChainManager::instance(bool testing) noexcept {
if (_instance == nullptr) {
_instance = std::shared_ptr<KeyChainManager>(new KeyChainManager(testing));
try {
_instance = std::shared_ptr<KeyChainManager>(new KeyChainManager(testing));
} catch (...) {
assert(false);
return nullptr;
}
}

return _instance;
Expand Down
2 changes: 1 addition & 1 deletion src/libcommon/keychainmanager/keychainmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class COMMON_EXPORT KeyChainManager : public QObject {
Q_OBJECT

public:
static std::shared_ptr<KeyChainManager> instance(bool testing = false);
static std::shared_ptr<KeyChainManager> instance(bool testing = false) noexcept;

KeyChainManager(KeyChainManager const &) = delete;
void operator=(KeyChainManager const &) = delete;
Expand Down
10 changes: 8 additions & 2 deletions src/libcommon/log/sentry/sentryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,14 @@ std::shared_ptr<SentryHandler> SentryHandler::instance() {
if (!_instance) {
assert(false && "SentryHandler must be initialized before calling instance");
// TODO: When the logger will be moved to the common library, add a log there.
return std::shared_ptr<SentryHandler>(new SentryHandler()); // Create a dummy instance to avoid crash but should never
// happen (the sentry will not be sent)

try {
// Create a dummy instance to avoid crash but should never happen (the sentry will not be sent)
std::shared_ptr<SentryHandler>(new SentryHandler());
} catch (...) {
assert(false);
return nullptr;
}
}
return _instance;
}
Expand Down
9 changes: 7 additions & 2 deletions src/libcommongui/commclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ std::shared_ptr<CommClient> CommClient::_instance = 0;

Q_LOGGING_CATEGORY(lcCommClient, "gui.commclient", QtInfoMsg)

std::shared_ptr<CommClient> CommClient::instance(QObject *parent) {
std::shared_ptr<CommClient> CommClient::instance(QObject *parent) noexcept {
if (_instance == nullptr) {
_instance = std::shared_ptr<CommClient>(new CommClient(parent));
try {
_instance = std::shared_ptr<CommClient>(new CommClient(parent));
} catch (...) {
assert(false);
return nullptr;
}
}

return _instance;
Expand Down
2 changes: 1 addition & 1 deletion src/libcommongui/commclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CommClient : public QObject {
Q_OBJECT

public:
static std::shared_ptr<CommClient> instance(QObject *parent = nullptr);
static std::shared_ptr<CommClient> instance(QObject *parent = nullptr) noexcept;
~CommClient();

CommClient(CommClient const &) = delete;
Expand Down
9 changes: 7 additions & 2 deletions src/libcommonserver/commserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ namespace KDC {

std::shared_ptr<CommServer> CommServer::_instance = nullptr;

std::shared_ptr<CommServer> CommServer::instance(QObject *parent) {
std::shared_ptr<CommServer> CommServer::instance(QObject *parent) noexcept {
if (_instance == nullptr) {
_instance = std::shared_ptr<CommServer>(new CommServer(parent));
try {
_instance = std::shared_ptr<CommServer>(new CommServer(parent));
} catch (...) {
assert(false);
return nullptr;
}
}

return _instance;
Expand Down
2 changes: 1 addition & 1 deletion src/libcommonserver/commserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CommServer : public QObject {
Q_OBJECT

public:
static std::shared_ptr<CommServer> instance(QObject *parent = nullptr);
static std::shared_ptr<CommServer> instance(QObject *parent = nullptr) noexcept;
~CommServer();

CommServer(CommServer const &) = delete;
Expand Down
18 changes: 14 additions & 4 deletions src/libcommonserver/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ Log::~Log() {
log4cplus::Logger::shutdown();
}

std::shared_ptr<Log> Log::instance(const log4cplus::tstring &filePath) {
std::shared_ptr<Log> Log::instance(const log4cplus::tstring &filePath) noexcept {
if (_instance == nullptr) {
if (filePath.empty()) {
throw std::runtime_error("Log must be initialized!");
} else {
assert(false);
return nullptr;
}

try {
_instance = std::shared_ptr<Log>(new Log(filePath));
_instance->checkForExpiredFiles();
} catch (...) {
assert(false);
return nullptr;
}
}

Expand Down Expand Up @@ -115,7 +121,11 @@ SyncPath Log::getLogFilePath() const {

void Log::checkForExpiredFiles() {
auto *customRollingFileAppender = static_cast<CustomRollingFileAppender *>(_logger.getAppender(Log::rfName).get());
customRollingFileAppender->checkForExpiredFiles();
if (customRollingFileAppender) {
customRollingFileAppender->checkForExpiredFiles();
} else {
assert(false);
}
}

} // namespace KDC
2 changes: 1 addition & 1 deletion src/libcommonserver/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace KDC {
class COMMONSERVER_EXPORT Log {
public:
~Log();
static std::shared_ptr<Log> instance(const log4cplus::tstring &filePath = log4cplus::tstring());
static std::shared_ptr<Log> instance(const log4cplus::tstring &filePath = log4cplus::tstring()) noexcept;

Log(Log const &) = delete;
void operator=(Log const &) = delete;
Expand Down
13 changes: 10 additions & 3 deletions src/libcommonserver/network/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,26 @@
*/

#include "proxy.h"
#include "libcommonserver/utility/asserts.h"

#include <stdexcept>

namespace KDC {

std::shared_ptr<Proxy> Proxy::_instance = nullptr;

std::shared_ptr<Proxy> Proxy::instance(const ProxyConfig &proxyConfig) {
std::shared_ptr<Proxy> Proxy::instance(const ProxyConfig &proxyConfig) noexcept {
if (_instance == nullptr) {
if (proxyConfig.type() == ProxyType::Undefined) {
throw std::runtime_error("Proxy must be initialized!");
} else {
assert(false);
return nullptr;
}

try {
_instance = std::shared_ptr<Proxy>(new Proxy(proxyConfig));
} catch (...) {
assert(false);
return nullptr;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcommonserver/network/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace KDC {

class Proxy {
public:
static std::shared_ptr<Proxy> instance(const ProxyConfig &proxyConfig = ProxyConfig());
static std::shared_ptr<Proxy> instance(const ProxyConfig &proxyConfig = ProxyConfig()) noexcept;

Proxy(Proxy const &) = delete;
void operator=(Proxy const &) = delete;
Expand Down
15 changes: 11 additions & 4 deletions src/libparms/db/parmsdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,23 @@ namespace KDC {
std::shared_ptr<ParmsDb> ParmsDb::_instance = nullptr;

std::shared_ptr<ParmsDb> ParmsDb::instance(const std::filesystem::path &dbPath, const std::string &version,
bool autoDelete /*= false*/, bool test /*= false*/) {
bool autoDelete /*= false*/, bool test /*= false*/) noexcept {
if (_instance == nullptr) {
if (dbPath.empty()) {
throw std::runtime_error("ParmsDb must be initialized!");
} else {
assert(false);
return nullptr;
}

try {
_instance = std::shared_ptr<ParmsDb>(new ParmsDb(dbPath, version, autoDelete, test));
if (!_instance->init(version)) {
_instance.reset();
throw std::runtime_error("ParmsDb initialisation error!");
assert(false);
return nullptr;
}
} catch (...) {
assert(false);
return nullptr;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libparms/db/parmsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class PARMS_EXPORT ParmsDb : public Db {
public:
static std::shared_ptr<ParmsDb> instance(const std::filesystem::path &dbPath = std::filesystem::path(),
const std::string &version = std::string(), bool autoDelete = false,
bool test = false);
bool test = false) noexcept;

std::string dbType() const override { return "Parms"; };
std::string dbType() const override { return "Parms"; }

static void reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ static const std::unordered_set<std::string> reservedWinNames = {
std::shared_ptr<PlatformInconsistencyCheckerUtility> PlatformInconsistencyCheckerUtility::_instance = nullptr;
size_t PlatformInconsistencyCheckerUtility::_maxPathLength = 0;

std::shared_ptr<PlatformInconsistencyCheckerUtility> PlatformInconsistencyCheckerUtility::instance() {
std::shared_ptr<PlatformInconsistencyCheckerUtility> PlatformInconsistencyCheckerUtility::instance() noexcept {
if (_instance == nullptr) {
_instance = std::shared_ptr<PlatformInconsistencyCheckerUtility>(new PlatformInconsistencyCheckerUtility());
try {
_instance = std::shared_ptr<PlatformInconsistencyCheckerUtility>(new PlatformInconsistencyCheckerUtility());
} catch (...) {
assert(false);
return nullptr;
}
}
return _instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PlatformInconsistencyCheckerUtility {
typedef enum { SuffixTypeRename, SuffixTypeConflict, SuffixTypeOrphan, SuffixTypeBlacklisted } SuffixType;

public:
static std::shared_ptr<PlatformInconsistencyCheckerUtility> instance();
static std::shared_ptr<PlatformInconsistencyCheckerUtility> instance() noexcept;

SyncName generateNewValidName(const SyncPath &name, SuffixType suffixType);
static ExitCode renameLocalFile(const SyncPath &absoluteLocalPath, SuffixType suffixType, SyncPath *newPathPtr = nullptr);
Expand Down
3 changes: 2 additions & 1 deletion src/libsyncengine/requests/exclusiontemplatecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ namespace KDC {

std::shared_ptr<ExclusionTemplateCache> ExclusionTemplateCache::_instance = nullptr;

std::shared_ptr<ExclusionTemplateCache> ExclusionTemplateCache::instance() {
std::shared_ptr<ExclusionTemplateCache> ExclusionTemplateCache::instance() noexcept {
if (_instance == nullptr) {
try {
_instance = std::shared_ptr<ExclusionTemplateCache>(new ExclusionTemplateCache());
} catch (std::exception const &) {
assert(false);
return nullptr;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyncengine/requests/exclusiontemplatecache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace KDC {

class SYNCENGINE_EXPORT ExclusionTemplateCache {
public:
static std::shared_ptr<ExclusionTemplateCache> instance();
static std::shared_ptr<ExclusionTemplateCache> instance() noexcept;

ExclusionTemplateCache(ExclusionTemplateCache const &) = delete;

Expand Down
3 changes: 2 additions & 1 deletion src/libsyncengine/requests/parameterscache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ namespace KDC {

std::shared_ptr<ParametersCache> ParametersCache::_instance = nullptr;

std::shared_ptr<ParametersCache> ParametersCache::instance(bool isTest /*= false*/) {
std::shared_ptr<ParametersCache> ParametersCache::instance(bool isTest /*= false*/) noexcept {
if (_instance == nullptr) {
try {
_instance = std::shared_ptr<ParametersCache>(new ParametersCache(isTest));
} catch (std::exception const &) {
assert(false);
return nullptr;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyncengine/requests/parameterscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace KDC {

class SYNCENGINE_EXPORT ParametersCache {
public:
static std::shared_ptr<ParametersCache> instance(bool isTest = false);
inline static bool isExtendedLogEnabled() noexcept { return instance()->_parameters.extendedLog(); };
static std::shared_ptr<ParametersCache> instance(bool isTest = false) noexcept;
inline static bool isExtendedLogEnabled() noexcept { return instance()->_parameters.extendedLog(); }

ParametersCache(ParametersCache const &) = delete;
void operator=(ParametersCache const &) = delete;
Expand Down
3 changes: 2 additions & 1 deletion src/libsyncengine/requests/syncnodecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ namespace KDC {

std::shared_ptr<SyncNodeCache> SyncNodeCache::_instance = nullptr;

std::shared_ptr<SyncNodeCache> SyncNodeCache::instance() {
std::shared_ptr<SyncNodeCache> SyncNodeCache::instance() noexcept {
if (_instance == nullptr) {
try {
_instance = std::shared_ptr<SyncNodeCache>(new SyncNodeCache());
} catch (std::exception const &) {
assert(false);
return nullptr;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyncengine/requests/syncnodecache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace KDC {

class SYNCENGINE_EXPORT SyncNodeCache {
public:
static std::shared_ptr<SyncNodeCache> instance();
static std::shared_ptr<SyncNodeCache> instance() noexcept;

SyncNodeCache(SyncNodeCache const &) = delete;
void operator=(SyncNodeCache const &) = delete;
Expand Down
3 changes: 1 addition & 2 deletions src/libsyncengine/syncpal/syncpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,13 @@ bool SyncPal::createOrOpenDb(const SyncPath &syncDbPath, const std::string &vers
_syncDb = std::shared_ptr<SyncDb>(new SyncDb(syncDbPath.string(), version, targetNodeId));
if (!_syncDb->init(version)) {
_syncDb.reset();
assert(false);
LOG_SYNCPAL_ERROR(_logger, "Database initialisation error");

return false;
}

} catch (std::exception const &) {
LOG_SYNCPAL_WARN(_logger, "Error in SyncDb::SyncDb");

return false;
}

Expand Down
Loading

0 comments on commit 436af1e

Please sign in to comment.