mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
Other: C++ Code reformat.
This commit is contained in:
@ -21,8 +21,7 @@
|
||||
#include <random>
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
namespace {
|
||||
@ -56,8 +55,7 @@ QStringList const lastNames {
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Return the 64 bit Mersenne twister random number generator.
|
||||
//****************************************************************************************************************************************************
|
||||
std::mt19937_64& rng()
|
||||
{
|
||||
std::mt19937_64 &rng() {
|
||||
// Do not use for crypto. std::random_device is not good enough.
|
||||
static std::mt19937_64 generator = std::mt19937_64(std::random_device()());
|
||||
return generator;
|
||||
@ -70,17 +68,17 @@ std::mt19937_64& rng()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user configuration directory used by bridge (based on Golang OS/File's UserConfigDir).
|
||||
//****************************************************************************************************************************************************
|
||||
QString userConfigDir()
|
||||
{
|
||||
QString userConfigDir() {
|
||||
QString dir;
|
||||
#ifdef Q_OS_WIN
|
||||
dir = qgetenv ("AppData");
|
||||
if (dir.isEmpty())
|
||||
throw Exception("%AppData% is not defined.");
|
||||
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
||||
dir = qgetenv ("HOME");
|
||||
if (dir.isEmpty())
|
||||
dir = qgetenv("HOME");
|
||||
if (dir.isEmpty()) {
|
||||
throw Exception("$HOME is not defined.");
|
||||
}
|
||||
dir += "/Library/Application Support";
|
||||
#else
|
||||
dir = qgetenv ("XDG_CONFIG_HOME");
|
||||
@ -102,8 +100,7 @@ QString userConfigDir()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user cache directory used by bridge (based on Golang OS/File's UserCacheDir).
|
||||
//****************************************************************************************************************************************************
|
||||
QString userCacheDir()
|
||||
{
|
||||
QString userCacheDir() {
|
||||
QString dir;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@ -111,9 +108,10 @@ QString userCacheDir()
|
||||
if (dir.isEmpty())
|
||||
throw Exception("%LocalAppData% is not defined.");
|
||||
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
||||
dir = qgetenv ("HOME");
|
||||
if (dir.isEmpty())
|
||||
dir = qgetenv("HOME");
|
||||
if (dir.isEmpty()) {
|
||||
throw Exception("$HOME is not defined.");
|
||||
}
|
||||
dir += "/Library/Caches";
|
||||
#else
|
||||
dir = qgetenv ("XDG_CACHE_HOME");
|
||||
@ -132,11 +130,11 @@ QString userCacheDir()
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user data directory used by bridge (based on Golang OS/File's UserDataDir).
|
||||
//****************************************************************************************************************************************************
|
||||
QString userDataDir()
|
||||
{
|
||||
QString userDataDir() {
|
||||
QString folder;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
@ -157,21 +155,21 @@ QString userDataDir()
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user logs directory used by bridge.
|
||||
//****************************************************************************************************************************************************
|
||||
QString userLogsDir()
|
||||
{
|
||||
QString userLogsDir() {
|
||||
QString const path = QDir(userDataDir()).absoluteFilePath("logs");
|
||||
QDir().mkpath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return sentry cache directory used by bridge.
|
||||
//****************************************************************************************************************************************************
|
||||
QString sentryCacheDir()
|
||||
{
|
||||
QString sentryCacheDir() {
|
||||
QString const path = QDir(userDataDir()).absoluteFilePath("sentry_cache");
|
||||
QDir().mkpath(path);
|
||||
return path;
|
||||
@ -181,8 +179,7 @@ QString sentryCacheDir()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The value GOOS would return for the current platform.
|
||||
//****************************************************************************************************************************************************
|
||||
QString goos()
|
||||
{
|
||||
QString goos() {
|
||||
#if defined(Q_OS_DARWIN)
|
||||
return "darwin";
|
||||
#elif defined(Q_OS_WINDOWS)
|
||||
@ -198,8 +195,7 @@ QString goos()
|
||||
///
|
||||
/// \return a random number in the range [0, n-1]
|
||||
//****************************************************************************************************************************************************
|
||||
qint64 randN(qint64 n)
|
||||
{
|
||||
qint64 randN(qint64 n) {
|
||||
QMutexLocker locker(&rngMutex);
|
||||
return (n > 0) ? std::uniform_int_distribution<qint64>(0, n - 1)(rng()) : 0;
|
||||
}
|
||||
@ -208,8 +204,7 @@ qint64 randN(qint64 n)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return A random first name.
|
||||
//****************************************************************************************************************************************************
|
||||
QString randomFirstName()
|
||||
{
|
||||
QString randomFirstName() {
|
||||
return firstNames[randN(firstNames.size())];
|
||||
}
|
||||
|
||||
@ -217,8 +212,7 @@ QString randomFirstName()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return A random last name.
|
||||
//****************************************************************************************************************************************************
|
||||
QString randomLastName()
|
||||
{
|
||||
QString randomLastName() {
|
||||
return lastNames[randN(lastNames.size())];
|
||||
}
|
||||
|
||||
@ -226,15 +220,14 @@ QString randomLastName()
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
SPUser randomUser()
|
||||
{
|
||||
SPUser randomUser() {
|
||||
SPUser user = User::newUser(nullptr);
|
||||
user->setID(QUuid::createUuid().toString());
|
||||
QString const firstName = randomFirstName();
|
||||
QString const lastName = randomLastName();
|
||||
QString const username = QString("%1.%2").arg(firstName.toLower(), lastName.toLower());
|
||||
user->setUsername(username);
|
||||
user->setAddresses(QStringList() << (username + "@proton.me") << (username + "@protonmail.com") );
|
||||
user->setAddresses(QStringList() << (username + "@proton.me") << (username + "@protonmail.com"));
|
||||
user->setPassword(QUuid().createUuid().toString(QUuid::StringFormat::WithoutBraces).left(20));
|
||||
user->setAvatarText(firstName.left(1) + lastName.left(1));
|
||||
user->setState(UserState::Connected);
|
||||
@ -249,14 +242,15 @@ SPUser randomUser()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The OS the application is running on.
|
||||
//****************************************************************************************************************************************************
|
||||
OS os()
|
||||
{
|
||||
OS os() {
|
||||
QString const osStr = QSysInfo::productType();
|
||||
if ((osStr == "macos") || (osStr == "osx")) // Qt < 5 returns "osx", Qt6 returns "macos".
|
||||
if ((osStr == "macos") || (osStr == "osx")) { // Qt < 5 returns "osx", Qt6 returns "macos".
|
||||
return OS::MacOS;
|
||||
}
|
||||
|
||||
if (osStr == "windows")
|
||||
if (osStr == "windows") {
|
||||
return OS::Windows;
|
||||
}
|
||||
|
||||
return OS::Linux;
|
||||
}
|
||||
@ -265,8 +259,7 @@ OS os()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if and only if the application is currently running on Linux.
|
||||
//****************************************************************************************************************************************************
|
||||
bool onLinux()
|
||||
{
|
||||
bool onLinux() {
|
||||
return OS::Linux == os();
|
||||
}
|
||||
|
||||
@ -274,8 +267,7 @@ bool onLinux()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if and only if the application is currently running on MacOS.
|
||||
//****************************************************************************************************************************************************
|
||||
bool onMacOS()
|
||||
{
|
||||
bool onMacOS() {
|
||||
return OS::MacOS == os();
|
||||
}
|
||||
|
||||
@ -283,8 +275,7 @@ bool onMacOS()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if and only if the application is currently running on Windows.
|
||||
//****************************************************************************************************************************************************
|
||||
bool onWindows()
|
||||
{
|
||||
bool onWindows() {
|
||||
return OS::Windows == os();
|
||||
}
|
||||
|
||||
|
||||
@ -23,8 +23,7 @@
|
||||
#include <bridgepp/User/User.h>
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
|
||||
@ -19,8 +19,7 @@
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
@ -28,36 +27,32 @@ namespace bridgepp
|
||||
//****************************************************************************************************************************************************
|
||||
Exception::Exception(QString what) noexcept
|
||||
: std::exception()
|
||||
, what_(std::move(what))
|
||||
{
|
||||
, what_(std::move(what)) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] ref The Exception to copy from
|
||||
//****************************************************************************************************************************************************
|
||||
Exception::Exception(Exception const& ref) noexcept
|
||||
Exception::Exception(Exception const &ref) noexcept
|
||||
: std::exception(ref)
|
||||
, what_(ref.what_)
|
||||
{
|
||||
, what_(ref.what_) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] ref The Exception to copy from
|
||||
//****************************************************************************************************************************************************
|
||||
Exception::Exception(Exception&& ref) noexcept
|
||||
Exception::Exception(Exception &&ref) noexcept
|
||||
: std::exception(ref)
|
||||
, what_(ref.what_)
|
||||
{
|
||||
, what_(ref.what_) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return a string describing the exception
|
||||
//****************************************************************************************************************************************************
|
||||
QString const& Exception::qwhat() const noexcept
|
||||
{
|
||||
QString const &Exception::qwhat() const noexcept {
|
||||
return what_;
|
||||
}
|
||||
|
||||
@ -65,8 +60,7 @@ QString const& Exception::qwhat() const noexcept
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return A pointer to the description string of the exception.
|
||||
//****************************************************************************************************************************************************
|
||||
const char* Exception::what() const noexcept
|
||||
{
|
||||
const char *Exception::what() const noexcept {
|
||||
return what_.toLocal8Bit().constData();
|
||||
}
|
||||
|
||||
|
||||
@ -23,15 +23,13 @@
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Exception class.
|
||||
//****************************************************************************************************************************************************
|
||||
class Exception : public std::exception
|
||||
{
|
||||
class Exception : public std::exception {
|
||||
public: // member functions
|
||||
explicit Exception(QString what = QString()) noexcept; ///< Constructor
|
||||
Exception(Exception const &ref) noexcept; ///< copy constructor
|
||||
|
||||
@ -25,8 +25,7 @@ using namespace grpc;
|
||||
using namespace google::protobuf;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
|
||||
Empty empty; ///< Empty protobuf message, re-used across calls.
|
||||
@ -37,8 +36,7 @@ QString const hostname = "127.0.0.1"; ///< The hostname of the focus service.
|
||||
}
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
@ -46,28 +44,29 @@ namespace bridgepp
|
||||
/// \param[out] outError if not null and the function returns false.
|
||||
/// \return true iff the connexion was successfully established.
|
||||
//****************************************************************************************************************************************************
|
||||
bool FocusGRPCClient::connectToServer(qint64 timeoutMs, QString *outError)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool FocusGRPCClient::connectToServer(qint64 timeoutMs, QString *outError) {
|
||||
try {
|
||||
QString const address = QString("%1:%2").arg(hostname).arg(port);
|
||||
channel_ = grpc::CreateChannel(address.toStdString(), grpc::InsecureChannelCredentials());
|
||||
if (!channel_)
|
||||
if (!channel_) {
|
||||
throw Exception("Could not create focus service channel.");
|
||||
}
|
||||
stub_ = Focus::NewStub(channel_);
|
||||
|
||||
if (!channel_->WaitForConnected(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(timeoutMs, GPR_TIMESPAN))))
|
||||
if (!channel_->WaitForConnected(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(timeoutMs, GPR_TIMESPAN)))) {
|
||||
throw Exception("Could not connect to focus service");
|
||||
}
|
||||
|
||||
if (channel_->GetState(true) != GRPC_CHANNEL_READY)
|
||||
if (channel_->GetState(true) != GRPC_CHANNEL_READY) {
|
||||
throw Exception("Connexion check with focus service failed.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception const &e)
|
||||
{
|
||||
if (outError)
|
||||
catch (Exception const &e) {
|
||||
if (outError) {
|
||||
*outError = e.qwhat();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -76,8 +75,7 @@ bool FocusGRPCClient::connectToServer(qint64 timeoutMs, QString *outError)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The status for the call.
|
||||
//****************************************************************************************************************************************************
|
||||
grpc::Status FocusGRPCClient::raise()
|
||||
{
|
||||
grpc::Status FocusGRPCClient::raise() {
|
||||
ClientContext ctx;
|
||||
return stub_->Raise(&ctx, empty, &empty);
|
||||
}
|
||||
@ -87,13 +85,13 @@ grpc::Status FocusGRPCClient::raise()
|
||||
/// \param[out] outVersion The version string.
|
||||
/// \return The status for the call.
|
||||
//****************************************************************************************************************************************************
|
||||
grpc::Status FocusGRPCClient::version(QString &outVersion)
|
||||
{
|
||||
grpc::Status FocusGRPCClient::version(QString &outVersion) {
|
||||
ClientContext ctx;
|
||||
VersionResponse response;
|
||||
Status status = stub_->Version(&ctx, empty, &response);
|
||||
if (status.ok())
|
||||
if (status.ok()) {
|
||||
outVersion = QString::fromStdString(response.version());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -24,15 +24,13 @@
|
||||
#include "focus.grpc.pb.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//**********************************************************************************************************************
|
||||
/// \brief Focus GRPC client class
|
||||
//**********************************************************************************************************************
|
||||
class FocusGRPCClient
|
||||
{
|
||||
class FocusGRPCClient {
|
||||
public: // member functions.
|
||||
FocusGRPCClient() = default; ///< Default constructor.
|
||||
FocusGRPCClient(FocusGRPCClient const &) = delete; ///< Disabled copy-constructor.
|
||||
|
||||
@ -19,19 +19,16 @@
|
||||
#include "EventFactory.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return a new SPStreamEvent
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent newStreamEvent()
|
||||
{
|
||||
bridgepp::SPStreamEvent newStreamEvent() {
|
||||
return std::make_shared<grpc::StreamEvent>();
|
||||
}
|
||||
|
||||
@ -40,8 +37,7 @@ bridgepp::SPStreamEvent newStreamEvent()
|
||||
/// \param[in] appEvent The app event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapAppEvent(grpc::AppEvent *appEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapAppEvent(grpc::AppEvent *appEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_app(appEvent);
|
||||
return event;
|
||||
@ -52,8 +48,7 @@ bridgepp::SPStreamEvent wrapAppEvent(grpc::AppEvent *appEvent)
|
||||
/// \param[in] loginEvent The login event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapLoginEvent(grpc::LoginEvent *loginEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapLoginEvent(grpc::LoginEvent *loginEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_login(loginEvent);
|
||||
return event;
|
||||
@ -64,8 +59,7 @@ bridgepp::SPStreamEvent wrapLoginEvent(grpc::LoginEvent *loginEvent)
|
||||
/// \param[in] updateEvent The app event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapUpdateEvent(grpc::UpdateEvent *updateEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapUpdateEvent(grpc::UpdateEvent *updateEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_update(updateEvent);
|
||||
return event;
|
||||
@ -76,8 +70,7 @@ bridgepp::SPStreamEvent wrapUpdateEvent(grpc::UpdateEvent *updateEvent)
|
||||
/// \param[in] cacheEvent The cache event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapCacheEvent(grpc::DiskCacheEvent *cacheEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapCacheEvent(grpc::DiskCacheEvent *cacheEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_cache(cacheEvent);
|
||||
return event;
|
||||
@ -88,8 +81,7 @@ bridgepp::SPStreamEvent wrapCacheEvent(grpc::DiskCacheEvent *cacheEvent)
|
||||
/// \param[in] mailSettingsEvent The mail settings event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapMailServerSettingsEvent(grpc::MailServerSettingsEvent *mailServerSettingsEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapMailServerSettingsEvent(grpc::MailServerSettingsEvent *mailServerSettingsEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_mailserversettings(mailServerSettingsEvent);
|
||||
return event;
|
||||
@ -100,8 +92,7 @@ bridgepp::SPStreamEvent wrapMailServerSettingsEvent(grpc::MailServerSettingsEven
|
||||
/// \param[in] keychainEvent The keychain event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapKeychainEvent(grpc::KeychainEvent *keychainEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapKeychainEvent(grpc::KeychainEvent *keychainEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_keychain(keychainEvent);
|
||||
return event;
|
||||
@ -112,8 +103,7 @@ bridgepp::SPStreamEvent wrapKeychainEvent(grpc::KeychainEvent *keychainEvent)
|
||||
/// \param[in] mailEvent The mail event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapMailEvent(grpc::MailEvent *mailEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapMailEvent(grpc::MailEvent *mailEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_mail(mailEvent);
|
||||
return event;
|
||||
@ -124,8 +114,7 @@ bridgepp::SPStreamEvent wrapMailEvent(grpc::MailEvent *mailEvent)
|
||||
/// \param[in] userEvent The user event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapUserEvent(grpc::UserEvent *userEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapUserEvent(grpc::UserEvent *userEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_user(userEvent);
|
||||
return event;
|
||||
@ -136,8 +125,7 @@ bridgepp::SPStreamEvent wrapUserEvent(grpc::UserEvent *userEvent)
|
||||
/// \param[in] genericErrorEvent The generic error event.
|
||||
/// \return The stream event.
|
||||
//****************************************************************************************************************************************************
|
||||
bridgepp::SPStreamEvent wrapGenericErrorEvent(grpc::GenericErrorEvent *genericErrorEvent)
|
||||
{
|
||||
bridgepp::SPStreamEvent wrapGenericErrorEvent(grpc::GenericErrorEvent *genericErrorEvent) {
|
||||
auto event = newStreamEvent();
|
||||
event->set_allocated_genericerror(genericErrorEvent);
|
||||
return event;
|
||||
@ -150,8 +138,7 @@ bridgepp::SPStreamEvent wrapGenericErrorEvent(grpc::GenericErrorEvent *genericEr
|
||||
/// \param[in] connected The internet status.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newInternetStatusEvent(bool connected)
|
||||
{
|
||||
SPStreamEvent newInternetStatusEvent(bool connected) {
|
||||
auto *internetStatusEvent = new grpc::InternetStatusEvent();
|
||||
internetStatusEvent->set_connected(connected);
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
@ -163,8 +150,7 @@ SPStreamEvent newInternetStatusEvent(bool connected)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newToggleAutostartFinishedEvent()
|
||||
{
|
||||
SPStreamEvent newToggleAutostartFinishedEvent() {
|
||||
auto *event = new grpc::ToggleAutostartFinishedEvent;
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
appEvent->set_allocated_toggleautostartfinished(event);
|
||||
@ -175,8 +161,7 @@ SPStreamEvent newToggleAutostartFinishedEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newResetFinishedEvent()
|
||||
{
|
||||
SPStreamEvent newResetFinishedEvent() {
|
||||
auto event = new grpc::ResetFinishedEvent;
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
appEvent->set_allocated_resetfinished(event);
|
||||
@ -187,8 +172,7 @@ SPStreamEvent newResetFinishedEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newReportBugFinishedEvent()
|
||||
{
|
||||
SPStreamEvent newReportBugFinishedEvent() {
|
||||
auto event = new grpc::ReportBugFinishedEvent;
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
appEvent->set_allocated_reportbugfinished(event);
|
||||
@ -199,8 +183,7 @@ SPStreamEvent newReportBugFinishedEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newReportBugSuccessEvent()
|
||||
{
|
||||
SPStreamEvent newReportBugSuccessEvent() {
|
||||
auto event = new grpc::ReportBugSuccessEvent;
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
appEvent->set_allocated_reportbugsuccess(event);
|
||||
@ -211,8 +194,7 @@ SPStreamEvent newReportBugSuccessEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newReportBugErrorEvent()
|
||||
{
|
||||
SPStreamEvent newReportBugErrorEvent() {
|
||||
auto event = new grpc::ReportBugErrorEvent;
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
appEvent->set_allocated_reportbugerror(event);
|
||||
@ -223,8 +205,7 @@ SPStreamEvent newReportBugErrorEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newShowMainWindowEvent()
|
||||
{
|
||||
SPStreamEvent newShowMainWindowEvent() {
|
||||
auto event = new grpc::ShowMainWindowEvent;
|
||||
auto appEvent = new grpc::AppEvent;
|
||||
appEvent->set_allocated_showmainwindow(event);
|
||||
@ -237,8 +218,7 @@ SPStreamEvent newShowMainWindowEvent()
|
||||
/// \param[in] message The message.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newLoginError(grpc::LoginErrorType error, QString const &message)
|
||||
{
|
||||
SPStreamEvent newLoginError(grpc::LoginErrorType error, QString const &message) {
|
||||
auto event = new ::grpc::LoginErrorEvent;
|
||||
event->set_type(error);
|
||||
event->set_message(message.toStdString());
|
||||
@ -252,8 +232,7 @@ SPStreamEvent newLoginError(grpc::LoginErrorType error, QString const &message)
|
||||
/// \param[in] username The username.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newLoginTfaRequestedEvent(QString const &username)
|
||||
{
|
||||
SPStreamEvent newLoginTfaRequestedEvent(QString const &username) {
|
||||
auto event = new ::grpc::LoginTfaRequestedEvent;
|
||||
event->set_username(username.toStdString());
|
||||
auto loginEvent = new grpc::LoginEvent;
|
||||
@ -266,8 +245,7 @@ SPStreamEvent newLoginTfaRequestedEvent(QString const &username)
|
||||
/// \param[in] username The username.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newLoginTwoPasswordsRequestedEvent()
|
||||
{
|
||||
SPStreamEvent newLoginTwoPasswordsRequestedEvent() {
|
||||
auto event = new ::grpc::LoginTwoPasswordsRequestedEvent;
|
||||
auto loginEvent = new grpc::LoginEvent;
|
||||
loginEvent->set_allocated_twopasswordrequested(event);
|
||||
@ -280,8 +258,7 @@ SPStreamEvent newLoginTwoPasswordsRequestedEvent()
|
||||
/// \param[in] wasSignedOut Was the user signed-out.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newLoginFinishedEvent(QString const &userID, bool wasSignedOut)
|
||||
{
|
||||
SPStreamEvent newLoginFinishedEvent(QString const &userID, bool wasSignedOut) {
|
||||
auto event = new ::grpc::LoginFinishedEvent;
|
||||
event->set_userid(userID.toStdString());
|
||||
event->set_wassignedout(wasSignedOut);
|
||||
@ -295,8 +272,7 @@ SPStreamEvent newLoginFinishedEvent(QString const &userID, bool wasSignedOut)
|
||||
/// \param[in] userID The userID.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newLoginAlreadyLoggedInEvent(QString const &userID)
|
||||
{
|
||||
SPStreamEvent newLoginAlreadyLoggedInEvent(QString const &userID) {
|
||||
auto event = new ::grpc::LoginFinishedEvent;
|
||||
event->set_userid(userID.toStdString());
|
||||
auto loginEvent = new grpc::LoginEvent;
|
||||
@ -309,8 +285,7 @@ SPStreamEvent newLoginAlreadyLoggedInEvent(QString const &userID)
|
||||
/// \param[in] errorType The error type.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateErrorEvent(grpc::UpdateErrorType errorType)
|
||||
{
|
||||
SPStreamEvent newUpdateErrorEvent(grpc::UpdateErrorType errorType) {
|
||||
auto event = new grpc::UpdateErrorEvent;
|
||||
event->set_type(errorType);
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
@ -323,8 +298,7 @@ SPStreamEvent newUpdateErrorEvent(grpc::UpdateErrorType errorType)
|
||||
/// \param[in] version The version.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateManualReadyEvent(QString const &version)
|
||||
{
|
||||
SPStreamEvent newUpdateManualReadyEvent(QString const &version) {
|
||||
auto event = new grpc::UpdateManualReadyEvent;
|
||||
event->set_version(version.toStdString());
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
@ -336,8 +310,7 @@ SPStreamEvent newUpdateManualReadyEvent(QString const &version)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return the event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateManualRestartNeededEvent()
|
||||
{
|
||||
SPStreamEvent newUpdateManualRestartNeededEvent() {
|
||||
auto event = new grpc::UpdateManualRestartNeededEvent;
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
updateEvent->set_allocated_manualrestartneeded(event);
|
||||
@ -349,8 +322,7 @@ SPStreamEvent newUpdateManualRestartNeededEvent()
|
||||
/// \param[in] version The version.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateForceEvent(QString const &version)
|
||||
{
|
||||
SPStreamEvent newUpdateForceEvent(QString const &version) {
|
||||
auto event = new grpc::UpdateForceEvent;
|
||||
event->set_version(version.toStdString());
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
@ -362,8 +334,7 @@ SPStreamEvent newUpdateForceEvent(QString const &version)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return the event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateSilentRestartNeeded()
|
||||
{
|
||||
SPStreamEvent newUpdateSilentRestartNeeded() {
|
||||
auto event = new grpc::UpdateSilentRestartNeeded;
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
updateEvent->set_allocated_silentrestartneeded(event);
|
||||
@ -374,8 +345,7 @@ SPStreamEvent newUpdateSilentRestartNeeded()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateIsLatestVersion()
|
||||
{
|
||||
SPStreamEvent newUpdateIsLatestVersion() {
|
||||
auto event = new grpc::UpdateIsLatestVersion;
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
updateEvent->set_allocated_islatestversion(event);
|
||||
@ -386,8 +356,7 @@ SPStreamEvent newUpdateIsLatestVersion()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUpdateCheckFinished()
|
||||
{
|
||||
SPStreamEvent newUpdateCheckFinished() {
|
||||
auto event = new grpc::UpdateCheckFinished;
|
||||
auto updateEvent = new grpc::UpdateEvent;
|
||||
updateEvent->set_allocated_checkfinished(event);
|
||||
@ -399,8 +368,7 @@ SPStreamEvent newUpdateCheckFinished()
|
||||
/// \param[in] errorType The error type.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newDiskCacheErrorEvent(grpc::DiskCacheErrorType errorType)
|
||||
{
|
||||
SPStreamEvent newDiskCacheErrorEvent(grpc::DiskCacheErrorType errorType) {
|
||||
auto event = new grpc::DiskCacheErrorEvent;
|
||||
event->set_type(errorType);
|
||||
auto cacheEvent = new grpc::DiskCacheEvent;
|
||||
@ -413,8 +381,7 @@ SPStreamEvent newDiskCacheErrorEvent(grpc::DiskCacheErrorType errorType)
|
||||
/// \param[in] path The path of the cache.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newDiskCachePathChangedEvent(QString const &path)
|
||||
{
|
||||
SPStreamEvent newDiskCachePathChangedEvent(QString const &path) {
|
||||
auto event = new grpc::DiskCachePathChangedEvent;
|
||||
event->set_path(path.toStdString());
|
||||
auto cacheEvent = new grpc::DiskCacheEvent;
|
||||
@ -426,20 +393,19 @@ SPStreamEvent newDiskCachePathChangedEvent(QString const &path)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newDiskCachePathChangeFinishedEvent()
|
||||
{
|
||||
SPStreamEvent newDiskCachePathChangeFinishedEvent() {
|
||||
auto event = new grpc::DiskCachePathChangeFinishedEvent;
|
||||
auto cacheEvent = new grpc::DiskCacheEvent;
|
||||
cacheEvent->set_allocated_pathchangefinished(event);
|
||||
return wrapCacheEvent(cacheEvent);
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] errorType The error type.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newMailServerSettingsErrorEvent(grpc::MailServerSettingsErrorType errorType)
|
||||
{
|
||||
SPStreamEvent newMailServerSettingsErrorEvent(grpc::MailServerSettingsErrorType errorType) {
|
||||
auto event = new grpc::MailServerSettingsErrorEvent;
|
||||
event->set_type(errorType);
|
||||
auto mailServerSettingsEvent = new grpc::MailServerSettingsEvent;
|
||||
@ -452,8 +418,7 @@ SPStreamEvent newMailServerSettingsErrorEvent(grpc::MailServerSettingsErrorType
|
||||
/// \param[in] settings The settings.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings const &settings)
|
||||
{
|
||||
SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings const &settings) {
|
||||
auto event = new grpc::MailServerSettingsChangedEvent;
|
||||
event->set_allocated_settings(new grpc::ImapSmtpSettings(settings));
|
||||
auto mailServerSettingsEvent = new grpc::MailServerSettingsEvent;
|
||||
@ -465,8 +430,7 @@ SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings const &setting
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newChangeMailServerSettingsFinished()
|
||||
{
|
||||
SPStreamEvent newChangeMailServerSettingsFinished() {
|
||||
auto event = new grpc::ChangeMailServerSettingsFinishedEvent;
|
||||
auto mailServerSettingsEvent = new grpc::MailServerSettingsEvent;
|
||||
mailServerSettingsEvent->set_allocated_changemailserversettingsfinished(event);
|
||||
@ -477,8 +441,7 @@ SPStreamEvent newChangeMailServerSettingsFinished()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newChangeKeychainFinishedEvent()
|
||||
{
|
||||
SPStreamEvent newChangeKeychainFinishedEvent() {
|
||||
auto event = new grpc::ChangeKeychainFinishedEvent;
|
||||
auto keychainEvent = new grpc::KeychainEvent;
|
||||
keychainEvent->set_allocated_changekeychainfinished(event);
|
||||
@ -489,8 +452,7 @@ SPStreamEvent newChangeKeychainFinishedEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newHasNoKeychainEvent()
|
||||
{
|
||||
SPStreamEvent newHasNoKeychainEvent() {
|
||||
auto event = new grpc::HasNoKeychainEvent;
|
||||
auto keychainEvent = new grpc::KeychainEvent;
|
||||
keychainEvent->set_allocated_hasnokeychain(event);
|
||||
@ -501,8 +463,7 @@ SPStreamEvent newHasNoKeychainEvent()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newRebuildKeychainEvent()
|
||||
{
|
||||
SPStreamEvent newRebuildKeychainEvent() {
|
||||
auto event = new grpc::RebuildKeychainEvent;
|
||||
auto keychainEvent = new grpc::KeychainEvent;
|
||||
keychainEvent->set_allocated_rebuildkeychain(event);
|
||||
@ -514,8 +475,7 @@ SPStreamEvent newRebuildKeychainEvent()
|
||||
/// \param[in] email The email.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newNoActiveKeyForRecipientEvent(QString const &email)
|
||||
{
|
||||
SPStreamEvent newNoActiveKeyForRecipientEvent(QString const &email) {
|
||||
auto event = new grpc::NoActiveKeyForRecipientEvent;
|
||||
event->set_email(email.toStdString());
|
||||
auto mailEvent = new grpc::MailEvent;
|
||||
@ -528,8 +488,7 @@ SPStreamEvent newNoActiveKeyForRecipientEvent(QString const &email)
|
||||
/// \param[in] address The address.
|
||||
/// /// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newAddressChangedEvent(QString const &address)
|
||||
{
|
||||
SPStreamEvent newAddressChangedEvent(QString const &address) {
|
||||
auto event = new grpc::AddressChangedEvent;
|
||||
event->set_address(address.toStdString());
|
||||
auto mailEvent = new grpc::MailEvent;
|
||||
@ -542,8 +501,7 @@ SPStreamEvent newAddressChangedEvent(QString const &address)
|
||||
/// \param[in] address The address.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newAddressChangedLogoutEvent(QString const &address)
|
||||
{
|
||||
SPStreamEvent newAddressChangedLogoutEvent(QString const &address) {
|
||||
auto event = new grpc::AddressChangedLogoutEvent;
|
||||
event->set_address(address.toStdString());
|
||||
auto mailEvent = new grpc::MailEvent;
|
||||
@ -555,8 +513,7 @@ SPStreamEvent newAddressChangedLogoutEvent(QString const &address)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newApiCertIssueEvent()
|
||||
{
|
||||
SPStreamEvent newApiCertIssueEvent() {
|
||||
auto event = new grpc::ApiCertIssueEvent;
|
||||
auto mailEvent = new grpc::MailEvent;
|
||||
mailEvent->set_allocated_apicertissue(event);
|
||||
@ -568,8 +525,7 @@ SPStreamEvent newApiCertIssueEvent()
|
||||
/// \param[in] userID The userID.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newToggleSplitModeFinishedEvent(QString const &userID)
|
||||
{
|
||||
SPStreamEvent newToggleSplitModeFinishedEvent(QString const &userID) {
|
||||
auto event = new grpc::ToggleSplitModeFinishedEvent;
|
||||
event->set_userid(userID.toStdString());
|
||||
auto userEvent = new grpc::UserEvent;
|
||||
@ -582,8 +538,7 @@ SPStreamEvent newToggleSplitModeFinishedEvent(QString const &userID)
|
||||
/// \param[in] username The username.
|
||||
/// /// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUserDisconnectedEvent(QString const &username)
|
||||
{
|
||||
SPStreamEvent newUserDisconnectedEvent(QString const &username) {
|
||||
auto event = new grpc::UserDisconnectedEvent;
|
||||
event->set_username(username.toStdString());
|
||||
auto userEvent = new grpc::UserEvent;
|
||||
@ -596,8 +551,7 @@ SPStreamEvent newUserDisconnectedEvent(QString const &username)
|
||||
/// \param[in] userID The userID.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newUserChangedEvent(QString const &userID)
|
||||
{
|
||||
SPStreamEvent newUserChangedEvent(QString const &userID) {
|
||||
auto event = new grpc::UserChangedEvent;
|
||||
event->set_userid(userID.toStdString());
|
||||
auto userEvent = new grpc::UserEvent;
|
||||
@ -610,8 +564,7 @@ SPStreamEvent newUserChangedEvent(QString const &userID)
|
||||
/// \param[in] errorCode The error errorCode.
|
||||
/// \return The event.
|
||||
//****************************************************************************************************************************************************
|
||||
SPStreamEvent newGenericErrorEvent(grpc::ErrorCode errorCode)
|
||||
{
|
||||
SPStreamEvent newGenericErrorEvent(grpc::ErrorCode errorCode) {
|
||||
auto event = new grpc::GenericErrorEvent;
|
||||
event->set_code(errorCode);
|
||||
return wrapGenericErrorEvent(event);
|
||||
|
||||
@ -24,8 +24,7 @@
|
||||
#include "GRPCUtils.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
// App events
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -28,8 +28,7 @@
|
||||
#include "grpc++/grpc++.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
typedef grpc::Status (grpc::Bridge::Stub::*SimpleMethod)(grpc::ClientContext *, const google::protobuf::Empty &, google::protobuf::Empty *);
|
||||
@ -46,8 +45,7 @@ typedef std::unique_ptr<grpc::ClientContext> UPClientContext;
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief gRPC client class. This class encapsulate the gRPC service, abstracting all data type conversions.
|
||||
//****************************************************************************************************************************************************
|
||||
class GRPCClient : public QObject
|
||||
{
|
||||
class GRPCClient : public QObject {
|
||||
Q_OBJECT
|
||||
public: // static member functions
|
||||
static void removeServiceConfigFile(); ///< Delete the service config file.
|
||||
@ -209,7 +207,7 @@ public:
|
||||
grpc::Status stopEventStreamReader(); ///< Stop the event stream.
|
||||
|
||||
private:
|
||||
void log(Log::Level level, QString const & message); ///< Log an event.
|
||||
void log(Log::Level level, QString const &message); ///< Log an event.
|
||||
void logTrace(QString const &message); ///< Log a trace event.
|
||||
void logDebug(QString const &message); ///< Log a debug event.
|
||||
void logError(QString const &message); ///< Log an error event.
|
||||
|
||||
@ -23,8 +23,7 @@
|
||||
using namespace bridgepp;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
Exception const invalidFileException("The service configuration file is invalid"); // Exception for invalid config.
|
||||
Exception const couldNotSaveException("The service configuration file could not be saved"); ///< Exception for write errors.
|
||||
@ -42,11 +41,11 @@ QString const keyFileSocketPath = "fileSocketPath"; ///< The JSON key for the fi
|
||||
/// \param[in] object The JSON object containing the value.
|
||||
/// \param[in] key The key under which the value is stored.
|
||||
//****************************************************************************************************************************************************
|
||||
QString jsonStringValue(QJsonObject const &object, QString const &key)
|
||||
{
|
||||
QString jsonStringValue(QJsonObject const &object, QString const &key) {
|
||||
QJsonValue const v = object[key];
|
||||
if (!v.isString())
|
||||
if (!v.isString()) {
|
||||
throw invalidFileException;
|
||||
}
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@ -59,11 +58,11 @@ QString jsonStringValue(QJsonObject const &object, QString const &key)
|
||||
/// \param[in] object The JSON object containing the value.
|
||||
/// \param[in] key The key under which the value is stored.
|
||||
//****************************************************************************************************************************************************
|
||||
qint32 jsonIntValue(QJsonObject const &object, QString const &key)
|
||||
{
|
||||
qint32 jsonIntValue(QJsonObject const &object, QString const &key) {
|
||||
QJsonValue const v = object[key];
|
||||
if (!v.isDouble())
|
||||
if (!v.isDouble()) {
|
||||
throw invalidFileException;
|
||||
}
|
||||
return v.toInt();
|
||||
}
|
||||
|
||||
@ -76,13 +75,12 @@ qint32 jsonIntValue(QJsonObject const &object, QString const &key)
|
||||
/// \param[out] outError if not null and an error occurs, this variable contains a description of the error.
|
||||
/// \return true iff the operation was successful.
|
||||
//****************************************************************************************************************************************************
|
||||
bool GRPCConfig::load(QString const &path, QString *outError)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool GRPCConfig::load(QString const &path, QString *outError) {
|
||||
try {
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
throw Exception("Could not open gRPC service config file.");
|
||||
}
|
||||
|
||||
QJsonDocument const doc = QJsonDocument::fromJson(file.readAll());
|
||||
QJsonObject const object = doc.object();
|
||||
@ -93,10 +91,10 @@ bool GRPCConfig::load(QString const &path, QString *outError)
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception const &e)
|
||||
{
|
||||
if (outError)
|
||||
catch (Exception const &e) {
|
||||
if (outError) {
|
||||
*outError = e.qwhat();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -107,10 +105,8 @@ bool GRPCConfig::load(QString const &path, QString *outError)
|
||||
/// \param[out] outError if not null and an error occurs, this variable contains a description of the error.
|
||||
/// \return true iff the operation was successful.
|
||||
//****************************************************************************************************************************************************
|
||||
bool GRPCConfig::save(QString const &path, QString *outError)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool GRPCConfig::save(QString const &path, QString *outError) {
|
||||
try {
|
||||
QJsonObject object;
|
||||
object.insert(keyPort, port);
|
||||
object.insert(keyCert, cert);
|
||||
@ -118,19 +114,21 @@ bool GRPCConfig::save(QString const &path, QString *outError)
|
||||
object.insert(keyFileSocketPath, fileSocketPath);
|
||||
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
throw couldNotSaveException;
|
||||
}
|
||||
|
||||
QByteArray const array = QJsonDocument(object).toJson();
|
||||
if (array.size() != file.write(array))
|
||||
if (array.size() != file.write(array)) {
|
||||
throw couldNotSaveException;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception const &e)
|
||||
{
|
||||
if (outError)
|
||||
catch (Exception const &e) {
|
||||
if (outError) {
|
||||
*outError = e.qwhat();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,7 @@
|
||||
//****************************************************************************************************************************************************
|
||||
/// Service configuration class.
|
||||
//****************************************************************************************************************************************************
|
||||
struct GRPCConfig
|
||||
{
|
||||
struct GRPCConfig {
|
||||
public: // data members
|
||||
qint32 port; ///< The port.
|
||||
QString cert; ///< The server TLS certificate.
|
||||
@ -36,5 +35,4 @@ public: // data members
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //BRIDGE_PP_GRPC_CONFIG_H
|
||||
|
||||
@ -22,12 +22,10 @@
|
||||
using namespace grpc;
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
|
||||
ErrorInfo const unknownError { UNKNOWN_ERROR, QObject::tr("Unknown error"), QObject::tr("An unknown error occurred.") }; // Unknown error
|
||||
@ -36,7 +34,7 @@ ErrorInfo const unknownError { UNKNOWN_ERROR, QObject::tr("Unknown error"), QObj
|
||||
QList<ErrorInfo> const errorList {
|
||||
unknownError,
|
||||
{ TLS_CERT_EXPORT_ERROR, QObject::tr("Export error"), QObject::tr("The TLS certificate could not be exported.") },
|
||||
{ TLS_KEY_EXPORT_ERROR, QObject::tr("Export error"), QObject::tr("The TLS private key could not be exported.") },
|
||||
{ TLS_KEY_EXPORT_ERROR, QObject::tr("Export error"), QObject::tr("The TLS private key could not be exported.") },
|
||||
};
|
||||
|
||||
|
||||
@ -46,9 +44,8 @@ QList<ErrorInfo> const errorList {
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] error
|
||||
//****************************************************************************************************************************************************
|
||||
ErrorInfo errorInfo(grpc::ErrorCode code)
|
||||
{
|
||||
QList<ErrorInfo>::const_iterator it = std::find_if(errorList.begin(), errorList.end(), [code](ErrorInfo info) -> bool { return code == info.code;});
|
||||
ErrorInfo errorInfo(grpc::ErrorCode code) {
|
||||
QList<ErrorInfo>::const_iterator it = std::find_if(errorList.begin(), errorList.end(), [code](ErrorInfo info) -> bool { return code == info.code; });
|
||||
return errorList.end() == it ? unknownError : *it;
|
||||
}
|
||||
|
||||
|
||||
@ -22,22 +22,19 @@
|
||||
#include "../BridgeUtils.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
std::string const grpcMetadataServerTokenKey = "server-token";
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return the gRPC server config file name
|
||||
//****************************************************************************************************************************************************
|
||||
QString grpcServerConfigFilename()
|
||||
{
|
||||
QString grpcServerConfigFilename() {
|
||||
return "grpcServerConfig.json";
|
||||
}
|
||||
|
||||
@ -45,8 +42,7 @@ QString grpcServerConfigFilename()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return the gRPC client config file name
|
||||
//****************************************************************************************************************************************************
|
||||
QString grpcClientConfigBaseFilename()
|
||||
{
|
||||
QString grpcClientConfigBaseFilename() {
|
||||
return "grpcClientConfig_%1.json";
|
||||
}
|
||||
|
||||
@ -54,8 +50,7 @@ QString grpcClientConfigBaseFilename()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The server certificate file name
|
||||
//****************************************************************************************************************************************************
|
||||
QString serverCertificateFilename()
|
||||
{
|
||||
QString serverCertificateFilename() {
|
||||
return "cert.pem";
|
||||
}
|
||||
|
||||
@ -63,8 +58,7 @@ QString serverCertificateFilename()
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
QString serverKeyFilename()
|
||||
{
|
||||
QString serverKeyFilename() {
|
||||
return "key.pem";
|
||||
}
|
||||
|
||||
@ -83,8 +77,7 @@ bool useFileSocketForGRPC() {
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The absolute path of the service config path.
|
||||
//****************************************************************************************************************************************************
|
||||
QString grpcServerConfigPath()
|
||||
{
|
||||
QString grpcServerConfigPath() {
|
||||
return QDir(userConfigDir()).absoluteFilePath(grpcServerConfigFilename());
|
||||
}
|
||||
|
||||
@ -92,8 +85,7 @@ QString grpcServerConfigPath()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The absolute path of the service config path.
|
||||
//****************************************************************************************************************************************************
|
||||
QString grpcClientConfigBasePath()
|
||||
{
|
||||
QString grpcClientConfigBasePath() {
|
||||
return QDir(userConfigDir()).absoluteFilePath(grpcClientConfigBaseFilename());
|
||||
}
|
||||
|
||||
@ -101,8 +93,7 @@ QString grpcClientConfigBasePath()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The absolute path of the server certificate.
|
||||
//****************************************************************************************************************************************************
|
||||
QString serverCertificatePath()
|
||||
{
|
||||
QString serverCertificatePath() {
|
||||
return QDir(userConfigDir()).absoluteFilePath(serverCertificateFilename());
|
||||
}
|
||||
|
||||
@ -110,8 +101,7 @@ QString serverCertificatePath()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The absolute path of the server key.
|
||||
//****************************************************************************************************************************************************
|
||||
QString serverKeyPath()
|
||||
{
|
||||
QString serverKeyPath() {
|
||||
|
||||
return QDir(userConfigDir()).absoluteFilePath(serverKeyFilename());
|
||||
}
|
||||
@ -122,19 +112,18 @@ QString serverKeyPath()
|
||||
/// \return The path of the created file.
|
||||
/// \return A null string if the file could not be saved..
|
||||
//****************************************************************************************************************************************************
|
||||
QString createClientConfigFile(QString const &token)
|
||||
{
|
||||
QString createClientConfigFile(QString const &token) {
|
||||
QString const basePath = grpcClientConfigBasePath();
|
||||
QString path, error;
|
||||
for (qint32 i = 0; i < 1000; ++i) // we try a decent amount of times
|
||||
{
|
||||
path = basePath.arg(i);
|
||||
if (!QFileInfo(path).exists())
|
||||
{
|
||||
if (!QFileInfo(path).exists()) {
|
||||
GRPCConfig config;
|
||||
config.token = token;
|
||||
if (!config.save(path))
|
||||
if (!config.save(path)) {
|
||||
return QString();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@ -147,10 +136,8 @@ QString createClientConfigFile(QString const &token)
|
||||
/// \param[in] level The Log::Level.
|
||||
/// \return The grpc::LogLevel.
|
||||
//****************************************************************************************************************************************************
|
||||
grpc::LogLevel logLevelToGRPC(Log::Level level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
grpc::LogLevel logLevelToGRPC(Log::Level level) {
|
||||
switch (level) {
|
||||
case Log::Level::Panic:
|
||||
return grpc::LogLevel::LOG_PANIC;
|
||||
case Log::Level::Fatal:
|
||||
@ -175,10 +162,8 @@ grpc::LogLevel logLevelToGRPC(Log::Level level)
|
||||
/// \param[in] level The level::LogLevel.
|
||||
/// \return The Log::Level.
|
||||
//****************************************************************************************************************************************************
|
||||
Log::Level logLevelFromGRPC(grpc::LogLevel level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
Log::Level logLevelFromGRPC(grpc::LogLevel level) {
|
||||
switch (level) {
|
||||
case grpc::LOG_PANIC:
|
||||
return Log::Level::Panic;
|
||||
case grpc::LOG_FATAL:
|
||||
@ -203,10 +188,8 @@ Log::Level logLevelFromGRPC(grpc::LogLevel level)
|
||||
/// \param[in] state The user state.
|
||||
/// \return The gRPC user state.
|
||||
//****************************************************************************************************************************************************
|
||||
grpc::UserState userStateToGRPC(UserState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
grpc::UserState userStateToGRPC(UserState state) {
|
||||
switch (state) {
|
||||
case UserState::SignedOut:
|
||||
return grpc::UserState::SIGNED_OUT;
|
||||
case UserState::Locked:
|
||||
@ -223,16 +206,14 @@ grpc::UserState userStateToGRPC(UserState state)
|
||||
/// \param[in] state The gRPC user state
|
||||
/// \return the user state
|
||||
//****************************************************************************************************************************************************
|
||||
UserState userStateFromGRPC(grpc::UserState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
UserState userStateFromGRPC(grpc::UserState state) {
|
||||
switch (state) {
|
||||
case grpc::UserState::SIGNED_OUT:
|
||||
return UserState::SignedOut;
|
||||
case grpc::UserState::LOCKED:
|
||||
return UserState::Locked;
|
||||
case grpc::UserState::CONNECTED:
|
||||
return UserState ::Connected;
|
||||
return UserState::Connected;
|
||||
default:
|
||||
throw Exception(QString("unknown gRPC user state %1.").arg(qint32(state)));
|
||||
}
|
||||
@ -243,16 +224,16 @@ UserState userStateFromGRPC(grpc::UserState state)
|
||||
/// \param[in] grpcUser The gRPC user.
|
||||
/// \return user The user.
|
||||
//****************************************************************************************************************************************************
|
||||
SPUser userFromGRPC(grpc::User const &grpcUser)
|
||||
{
|
||||
SPUser userFromGRPC(grpc::User const &grpcUser) {
|
||||
SPUser user = User::newUser(nullptr);
|
||||
|
||||
user->setID(QString::fromStdString(grpcUser.id()));
|
||||
user->setUsername(QString::fromStdString(grpcUser.username()));
|
||||
user->setPassword(QString::fromStdString(grpcUser.password()));
|
||||
QStringList addresses;
|
||||
for (int j = 0; j < grpcUser.addresses_size(); ++j)
|
||||
for (int j = 0; j < grpcUser.addresses_size(); ++j) {
|
||||
addresses.append(QString::fromStdString(grpcUser.addresses(j)));
|
||||
}
|
||||
user->setAddresses(addresses);
|
||||
user->setAvatarText(QString::fromStdString(grpcUser.avatartext()));
|
||||
user->setState(userStateFromGRPC(grpcUser.state()));
|
||||
@ -268,14 +249,14 @@ SPUser userFromGRPC(grpc::User const &grpcUser)
|
||||
/// \param[in] user the user.
|
||||
/// \param[out] outGRPCUser The GRPC user.
|
||||
//****************************************************************************************************************************************************
|
||||
void userToGRPC(User const &user, grpc::User &outGRPCUser)
|
||||
{
|
||||
void userToGRPC(User const &user, grpc::User &outGRPCUser) {
|
||||
outGRPCUser.set_id(user.id().toStdString());
|
||||
outGRPCUser.set_username(user.username().toStdString());
|
||||
outGRPCUser.set_password(user.password().toStdString());
|
||||
outGRPCUser.clear_addresses();
|
||||
for (QString const& address: user.addresses())
|
||||
for (QString const &address: user.addresses()) {
|
||||
outGRPCUser.add_addresses(address.toStdString());
|
||||
}
|
||||
outGRPCUser.set_avatartext(user.avatarText().toStdString());
|
||||
outGRPCUser.set_state(userStateToGRPC(user.state()));
|
||||
outGRPCUser.set_splitmode(user.splitMode());
|
||||
@ -288,14 +269,14 @@ void userToGRPC(User const &user, grpc::User &outGRPCUser)
|
||||
/// \return The path to a file that can be used for a gRPC file socket.
|
||||
/// \return A null string if no path could be found.
|
||||
//****************************************************************************************************************************************************
|
||||
QString getAvailableFileSocketPath()
|
||||
{
|
||||
QString getAvailableFileSocketPath() {
|
||||
QDir const tempDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||
for (qint32 i = 0; i < 10000; i++) {
|
||||
QString const path = tempDir.absoluteFilePath(QString("bridge_%1.sock").arg(qint32(i), 4, 10, QChar('0')));
|
||||
QFile f(path);
|
||||
if ((!f.exists()) || f.remove())
|
||||
if ((!f.exists()) || f.remove()) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
|
||||
@ -25,8 +25,7 @@
|
||||
#include "bridge.grpc.pb.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
extern std::string const grpcMetadataServerTokenKey; ///< The key for the server token stored in the gRPC calls context metadata.
|
||||
|
||||
@ -20,12 +20,10 @@
|
||||
#include "../Exception/Exception.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
Log *qtHandlerLog { nullptr }; ///< The log instance handling qt logs.
|
||||
QMutex qtHandlerMutex; ///< A mutex used to access qtHandlerLog.
|
||||
@ -45,8 +43,7 @@ QList<QPair<Log::Level, QString>> const logLevelStrings {
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] log The log handling qt log entries. Can be null.
|
||||
//****************************************************************************************************************************************************
|
||||
void setQtMessageHandlerLog(Log *log)
|
||||
{
|
||||
void setQtMessageHandlerLog(Log *log) {
|
||||
QMutexLocker locker(&qtHandlerMutex);
|
||||
qtHandlerLog = log;
|
||||
}
|
||||
@ -55,8 +52,7 @@ void setQtMessageHandlerLog(Log *log)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The log handling qt log entries. Can be null.
|
||||
//****************************************************************************************************************************************************
|
||||
Log *qtMessageHandlerLog()
|
||||
{
|
||||
Log *qtMessageHandlerLog() {
|
||||
QMutexLocker locker(&qtHandlerMutex);
|
||||
return qtHandlerLog;
|
||||
}
|
||||
@ -66,13 +62,12 @@ Log *qtMessageHandlerLog()
|
||||
/// \param[in] type The message type.
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void qtMessageHandler(QtMsgType type, QMessageLogContext const &, QString const &message)
|
||||
{
|
||||
void qtMessageHandler(QtMsgType type, QMessageLogContext const &, QString const &message) {
|
||||
Log *log = qtMessageHandlerLog();
|
||||
if (!log)
|
||||
if (!log) {
|
||||
return;
|
||||
switch (type)
|
||||
{
|
||||
}
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
log->debug(message);
|
||||
break;
|
||||
@ -102,8 +97,7 @@ void qtMessageHandler(QtMsgType type, QMessageLogContext const &, QString const
|
||||
/// \param[in] message The log entry message.
|
||||
/// \return The string for the log entry
|
||||
//****************************************************************************************************************************************************
|
||||
QString Log::logEntryToString(Log::Level level, QDateTime const &dateTime, QString const &message)
|
||||
{
|
||||
QString Log::logEntryToString(Log::Level level, QDateTime const &dateTime, QString const &message) {
|
||||
return QString("%1[%2] %3").arg(levelToString(level).left(4).toUpper(), dateTime.toString("MMM dd HH:mm:ss.zzz"), message);
|
||||
}
|
||||
|
||||
@ -112,8 +106,7 @@ QString Log::logEntryToString(Log::Level level, QDateTime const &dateTime, QStri
|
||||
/// \param[in] level The level.
|
||||
/// \return A string describing the level.
|
||||
//****************************************************************************************************************************************************
|
||||
QString Log::levelToString(Log::Level level)
|
||||
{
|
||||
QString Log::levelToString(Log::Level level) {
|
||||
QList<QPair<Log::Level, QString>>::const_iterator it = std::find_if(logLevelStrings.begin(), logLevelStrings.end(),
|
||||
[&level](QPair<Log::Level, QString> const &pair) -> bool {
|
||||
return pair.first == level;
|
||||
@ -129,16 +122,16 @@ QString Log::levelToString(Log::Level level)
|
||||
/// \param[out] outLevel The log level parsed. if not found, the value of the variable is not modified.
|
||||
/// \return true iff parsing was successful.
|
||||
//****************************************************************************************************************************************************
|
||||
bool Log::stringToLevel(QString const &str, Log::Level &outLevel)
|
||||
{
|
||||
bool Log::stringToLevel(QString const &str, Log::Level &outLevel) {
|
||||
QList<QPair<Log::Level, QString>>::const_iterator it = std::find_if(logLevelStrings.begin(), logLevelStrings.end(),
|
||||
[&str](QPair<Log::Level, QString> const &pair) -> bool {
|
||||
return 0 == QString::compare(str, pair.second, Qt::CaseInsensitive);
|
||||
});
|
||||
|
||||
bool const found = (it != logLevelStrings.end());
|
||||
if (found)
|
||||
if (found) {
|
||||
outLevel = it->first;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
@ -147,8 +140,7 @@ bool Log::stringToLevel(QString const &str, Log::Level &outLevel)
|
||||
//****************************************************************************************************************************************************
|
||||
/// the message handle process the message from the Qt logging system.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::registerAsQtMessageHandler()
|
||||
{
|
||||
void Log::registerAsQtMessageHandler() {
|
||||
setQtMessageHandlerLog(this);
|
||||
qInstallMessageHandler(qtMessageHandler);
|
||||
}
|
||||
@ -160,16 +152,14 @@ void Log::registerAsQtMessageHandler()
|
||||
Log::Log()
|
||||
: QObject()
|
||||
, stdout_(stdout)
|
||||
, stderr_(stderr)
|
||||
{
|
||||
, stderr_(stderr) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] level The log level.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::setLevel(Log::Level level)
|
||||
{
|
||||
void Log::setLevel(Log::Level level) {
|
||||
QMutexLocker locker(&mutex_);
|
||||
level_ = level;
|
||||
}
|
||||
@ -178,8 +168,7 @@ void Log::setLevel(Log::Level level)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The log level.
|
||||
//****************************************************************************************************************************************************
|
||||
Log::Level Log::level() const
|
||||
{
|
||||
Log::Level Log::level() const {
|
||||
QMutexLocker locker(&mutex_);
|
||||
return level_;
|
||||
}
|
||||
@ -188,8 +177,7 @@ Log::Level Log::level() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] value Should the log entries be sent to STDOUT/STDERR.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::setEchoInConsole(bool value)
|
||||
{
|
||||
void Log::setEchoInConsole(bool value) {
|
||||
QMutexLocker locker(&mutex_);
|
||||
echoInConsole_ = value;
|
||||
}
|
||||
@ -198,8 +186,7 @@ void Log::setEchoInConsole(bool value)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true iff the log entries be should sent to STDOUT/STDERR.
|
||||
//****************************************************************************************************************************************************
|
||||
bool Log::echoInConsole() const
|
||||
{
|
||||
bool Log::echoInConsole() const {
|
||||
QMutexLocker locker(&mutex_);
|
||||
return echoInConsole_;
|
||||
}
|
||||
@ -210,15 +197,16 @@ bool Log::echoInConsole() const
|
||||
/// \param[out] outError if an error occurs and this pointer in not null, on exit it contains a description of the error.
|
||||
/// \return true if and only if the operation was successful.
|
||||
//****************************************************************************************************************************************************
|
||||
bool Log::startWritingToFile(QString const &path, QString *outError)
|
||||
{
|
||||
bool Log::startWritingToFile(QString const &path, QString *outError) {
|
||||
QMutexLocker locker(&mutex_);
|
||||
file_ = std::make_unique<QFile>(path);
|
||||
if (file_->open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
if (file_->open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (outError)
|
||||
if (outError) {
|
||||
*outError = QString("Could not open log file '%1' for writing.");
|
||||
}
|
||||
file_.reset();
|
||||
return false;
|
||||
}
|
||||
@ -227,8 +215,7 @@ bool Log::startWritingToFile(QString const &path, QString *outError)
|
||||
//****************************************************************************************************************************************************
|
||||
///
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::stopWritingToFile()
|
||||
{
|
||||
void Log::stopWritingToFile() {
|
||||
QMutexLocker locker(&mutex_);
|
||||
file_.reset();
|
||||
}
|
||||
@ -237,8 +224,7 @@ void Log::stopWritingToFile()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::panic(QString const &message)
|
||||
{
|
||||
void Log::panic(QString const &message) {
|
||||
return this->addEntry(Level::Panic, message);
|
||||
}
|
||||
|
||||
@ -246,8 +232,7 @@ void Log::panic(QString const &message)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::fatal(QString const &message)
|
||||
{
|
||||
void Log::fatal(QString const &message) {
|
||||
return this->addEntry(Level::Fatal, message);
|
||||
}
|
||||
|
||||
@ -255,8 +240,7 @@ void Log::fatal(QString const &message)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::error(QString const &message)
|
||||
{
|
||||
void Log::error(QString const &message) {
|
||||
return this->addEntry(Level::Error, message);
|
||||
}
|
||||
|
||||
@ -264,8 +248,7 @@ void Log::error(QString const &message)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::warn(QString const &message)
|
||||
{
|
||||
void Log::warn(QString const &message) {
|
||||
return this->addEntry(Level::Warn, message);
|
||||
}
|
||||
|
||||
@ -273,8 +256,7 @@ void Log::warn(QString const &message)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::info(QString const &message)
|
||||
{
|
||||
void Log::info(QString const &message) {
|
||||
return this->addEntry(Level::Info, message);
|
||||
}
|
||||
|
||||
@ -282,8 +264,7 @@ void Log::info(QString const &message)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::debug(QString const &message)
|
||||
{
|
||||
void Log::debug(QString const &message) {
|
||||
return this->addEntry(Level::Debug, message);
|
||||
}
|
||||
|
||||
@ -291,8 +272,7 @@ void Log::debug(QString const &message)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::trace(QString const &message)
|
||||
{
|
||||
void Log::trace(QString const &message) {
|
||||
return this->addEntry(Level::Trace, message);
|
||||
}
|
||||
|
||||
@ -301,28 +281,27 @@ void Log::trace(QString const &message)
|
||||
/// \param[in] level The level.
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void Log::addEntry(Log::Level level, QString const &message)
|
||||
{
|
||||
void Log::addEntry(Log::Level level, QString const &message) {
|
||||
QDateTime const dateTime = QDateTime::currentDateTime();
|
||||
QMutexLocker locker(&mutex_);
|
||||
if (qint32(level) > qint32(level_))
|
||||
if (qint32(level) > qint32(level_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit entryAdded(level, message);
|
||||
|
||||
if (!(echoInConsole_ || file_))
|
||||
if (!(echoInConsole_ || file_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString const entryStr = logEntryToString(level, dateTime, message) + "\n";
|
||||
if (echoInConsole_)
|
||||
{
|
||||
if (echoInConsole_) {
|
||||
QTextStream &stream = (qint32(level) <= (qint32(Level::Warn))) ? stderr_ : stdout_;
|
||||
stream << entryStr;
|
||||
stream.flush();
|
||||
}
|
||||
|
||||
if (file_)
|
||||
{
|
||||
if (file_) {
|
||||
file_->write(entryStr.toLocal8Bit());
|
||||
file_->flush();
|
||||
}
|
||||
|
||||
@ -20,20 +20,17 @@
|
||||
#define BRIDGE_PP_LOG_H
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Basic log class. No logging to file. Four levels. Rebroadcast received log entries via Qt signals.
|
||||
//****************************************************************************************************************************************************
|
||||
class Log : public QObject
|
||||
{
|
||||
class Log : public QObject {
|
||||
Q_OBJECT
|
||||
public: // data types.
|
||||
/// \brief Log level class. The list matches [loggers log levels](https://pkg.go.dev/github.com/sirupsen/logrus).
|
||||
enum class Level
|
||||
{
|
||||
enum class Level {
|
||||
Panic, ///< Panic log level.
|
||||
Fatal, ///< Fatal log level.
|
||||
Error, ///< Error log level.
|
||||
@ -46,7 +43,7 @@ public: // data types.
|
||||
public: // static member functions.
|
||||
static QString logEntryToString(Log::Level level, QDateTime const &dateTime, QString const &message); ///< Return a string describing a log entry.
|
||||
static QString levelToString(Log::Level level); ///< return the string for a level.
|
||||
static bool stringToLevel(QString const &str, Log::Level& outLevel); ///< parse a level from a string.
|
||||
static bool stringToLevel(QString const &str, Log::Level &outLevel); ///< parse a level from a string.
|
||||
|
||||
public: // static data member.
|
||||
static const Level defaultLevel { Level::Info }; ///< The default log level (the same as logrus).
|
||||
@ -63,7 +60,7 @@ public: // member functions.
|
||||
Level level() const; ///< Get the log level.
|
||||
void setEchoInConsole(bool value); ///< Set if the log entries should be echoed in STDOUT/STDERR.
|
||||
bool echoInConsole() const; ///< Check if the log entries should be echoed in STDOUT/STDERR.
|
||||
bool startWritingToFile(QString const& path, QString *outError = nullptr); ///< Start writing the log to file. Concerns only future entries.
|
||||
bool startWritingToFile(QString const &path, QString *outError = nullptr); ///< Start writing the log to file. Concerns only future entries.
|
||||
void stopWritingToFile();
|
||||
void registerAsQtMessageHandler(); ///< Install the Qt message handler.
|
||||
|
||||
|
||||
@ -20,8 +20,7 @@
|
||||
#include "Exception/Exception.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
@ -34,13 +33,14 @@ ProcessMonitor::ProcessMonitor(QString const &exePath, QStringList const &args,
|
||||
, exePath_(exePath)
|
||||
, args_(args)
|
||||
, out_(stdout)
|
||||
, err_(stderr)
|
||||
{
|
||||
, err_(stderr) {
|
||||
QFileInfo fileInfo(exePath);
|
||||
if (!fileInfo.exists())
|
||||
if (!fileInfo.exists()) {
|
||||
throw Exception(QString("Could not locate %1 executable.").arg(fileInfo.baseName()));
|
||||
if ((!fileInfo.isFile()) || (!fileInfo.isExecutable()))
|
||||
}
|
||||
if ((!fileInfo.isFile()) || (!fileInfo.isExecutable())) {
|
||||
throw Exception(QString("Invalid %1 executable").arg(fileInfo.baseName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -49,15 +49,13 @@ ProcessMonitor::ProcessMonitor(QString const &exePath, QStringList const &args,
|
||||
//****************************************************************************************************************************************************
|
||||
void ProcessMonitor::forwardProcessOutput(QProcess &p) {
|
||||
QByteArray array = p.readAllStandardError();
|
||||
if (!array.isEmpty())
|
||||
{
|
||||
if (!array.isEmpty()) {
|
||||
err_ << array;
|
||||
err_.flush();
|
||||
}
|
||||
|
||||
array = p.readAllStandardOutput();
|
||||
if (!array.isEmpty())
|
||||
{
|
||||
if (!array.isEmpty()) {
|
||||
out_ << array;
|
||||
out_.flush();
|
||||
}
|
||||
@ -67,10 +65,8 @@ void ProcessMonitor::forwardProcessOutput(QProcess &p) {
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
void ProcessMonitor::run()
|
||||
{
|
||||
try
|
||||
{
|
||||
void ProcessMonitor::run() {
|
||||
try {
|
||||
{
|
||||
QMutexLocker locker(&statusMutex_);
|
||||
status_.ended = false;
|
||||
@ -88,8 +84,7 @@ void ProcessMonitor::run()
|
||||
status_.pid = p.processId();
|
||||
}
|
||||
|
||||
while (!p.waitForFinished(100))
|
||||
{
|
||||
while (!p.waitForFinished(100)) {
|
||||
this->forwardProcessOutput(p);
|
||||
}
|
||||
this->forwardProcessOutput(p);
|
||||
@ -101,8 +96,7 @@ void ProcessMonitor::run()
|
||||
emit processExited(status_.returnCode);
|
||||
emit finished();
|
||||
}
|
||||
catch (Exception const &e)
|
||||
{
|
||||
catch (Exception const &e) {
|
||||
emit error(e.qwhat());
|
||||
}
|
||||
}
|
||||
@ -111,8 +105,7 @@ void ProcessMonitor::run()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return status of the monitored process
|
||||
//****************************************************************************************************************************************************
|
||||
const ProcessMonitor::MonitorStatus ProcessMonitor::getStatus()
|
||||
{
|
||||
const ProcessMonitor::MonitorStatus ProcessMonitor::getStatus() {
|
||||
QMutexLocker locker(&statusMutex_);
|
||||
return status_;
|
||||
}
|
||||
|
||||
@ -23,19 +23,16 @@
|
||||
#include "Worker/Worker.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//**********************************************************************************************************************
|
||||
/// \brief Process launcher and monitor class.
|
||||
//**********************************************************************************************************************
|
||||
class ProcessMonitor : public Worker
|
||||
{
|
||||
class ProcessMonitor : public Worker {
|
||||
Q_OBJECT
|
||||
public: // static member functions
|
||||
struct MonitorStatus
|
||||
{
|
||||
struct MonitorStatus {
|
||||
bool ended = false;
|
||||
int returnCode = 0;
|
||||
qint64 pid = 0;
|
||||
|
||||
@ -19,15 +19,13 @@
|
||||
#include "User.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] parent The parent object of the user.
|
||||
//****************************************************************************************************************************************************
|
||||
SPUser User::newUser(QObject *parent)
|
||||
{
|
||||
SPUser User::newUser(QObject *parent) {
|
||||
return SPUser(new User(parent));
|
||||
}
|
||||
|
||||
@ -36,8 +34,7 @@ SPUser User::newUser(QObject *parent)
|
||||
/// \param[in] parent The parent object.
|
||||
//****************************************************************************************************************************************************
|
||||
User::User(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
: QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
@ -45,8 +42,7 @@ User::User(QObject *parent)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] user The user to copy from
|
||||
//****************************************************************************************************************************************************
|
||||
void User::update(User const &user)
|
||||
{
|
||||
void User::update(User const &user) {
|
||||
this->setID(user.id());
|
||||
this->setUsername(user.username());
|
||||
this->setPassword(user.password());
|
||||
@ -62,8 +58,7 @@ void User::update(User const &user)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] makeItActive Should split mode be made active.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::toggleSplitMode(bool makeItActive)
|
||||
{
|
||||
void User::toggleSplitMode(bool makeItActive) {
|
||||
emit toggleSplitModeForUser(id_, makeItActive);
|
||||
}
|
||||
|
||||
@ -71,8 +66,7 @@ void User::toggleSplitMode(bool makeItActive)
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
void User::logout()
|
||||
{
|
||||
void User::logout() {
|
||||
emit logoutUser(id_);
|
||||
}
|
||||
|
||||
@ -80,8 +74,7 @@ void User::logout()
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
void User::remove()
|
||||
{
|
||||
void User::remove() {
|
||||
emit removeUser(id_);
|
||||
}
|
||||
|
||||
@ -89,8 +82,7 @@ void User::remove()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] address The email address to configure Apple Mail for.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::configureAppleMail(QString const &address)
|
||||
{
|
||||
void User::configureAppleMail(QString const &address) {
|
||||
emit configureAppleMailForUser(id_, address);
|
||||
}
|
||||
|
||||
@ -99,8 +91,7 @@ void User::configureAppleMail(QString const &address)
|
||||
// The only purpose of this call is to forward to the QML application the toggleSplitModeFinished(userID) event
|
||||
// that was received by the UserList model.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::emitToggleSplitModeFinished()
|
||||
{
|
||||
void User::emitToggleSplitModeFinished() {
|
||||
emit toggleSplitModeFinished();
|
||||
}
|
||||
|
||||
@ -108,8 +99,7 @@ void User::emitToggleSplitModeFinished()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The userID.
|
||||
//****************************************************************************************************************************************************
|
||||
QString User::id() const
|
||||
{
|
||||
QString User::id() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
@ -117,10 +107,10 @@ QString User::id() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] id The userID.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setID(QString const &id)
|
||||
{
|
||||
if (id == id_)
|
||||
void User::setID(QString const &id) {
|
||||
if (id == id_) {
|
||||
return;
|
||||
}
|
||||
|
||||
id_ = id;
|
||||
emit idChanged(id_);
|
||||
@ -130,8 +120,7 @@ void User::setID(QString const &id)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The username.
|
||||
//****************************************************************************************************************************************************
|
||||
QString User::username() const
|
||||
{
|
||||
QString User::username() const {
|
||||
return username_;
|
||||
}
|
||||
|
||||
@ -139,10 +128,10 @@ QString User::username() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] username The username.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setUsername(QString const &username)
|
||||
{
|
||||
if (username == username_)
|
||||
void User::setUsername(QString const &username) {
|
||||
if (username == username_) {
|
||||
return;
|
||||
}
|
||||
|
||||
username_ = username;
|
||||
emit usernameChanged(username_);
|
||||
@ -152,8 +141,7 @@ void User::setUsername(QString const &username)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The password.
|
||||
//****************************************************************************************************************************************************
|
||||
QString User::password() const
|
||||
{
|
||||
QString User::password() const {
|
||||
return password_;
|
||||
}
|
||||
|
||||
@ -161,10 +149,10 @@ QString User::password() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] password The password.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setPassword(QString const &password)
|
||||
{
|
||||
if (password == password_)
|
||||
void User::setPassword(QString const &password) {
|
||||
if (password == password_) {
|
||||
return;
|
||||
}
|
||||
|
||||
password_ = password;
|
||||
emit passwordChanged(password_);
|
||||
@ -174,8 +162,7 @@ void User::setPassword(QString const &password)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The addresses.
|
||||
//****************************************************************************************************************************************************
|
||||
QStringList User::addresses() const
|
||||
{
|
||||
QStringList User::addresses() const {
|
||||
return addresses_;
|
||||
}
|
||||
|
||||
@ -183,10 +170,10 @@ QStringList User::addresses() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] addresses The addresses.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setAddresses(QStringList const &addresses)
|
||||
{
|
||||
if (addresses == addresses_)
|
||||
void User::setAddresses(QStringList const &addresses) {
|
||||
if (addresses == addresses_) {
|
||||
return;
|
||||
}
|
||||
|
||||
addresses_ = addresses;
|
||||
emit addressesChanged(addresses_);
|
||||
@ -196,8 +183,7 @@ void User::setAddresses(QStringList const &addresses)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The avatar text.
|
||||
//****************************************************************************************************************************************************
|
||||
QString User::avatarText() const
|
||||
{
|
||||
QString User::avatarText() const {
|
||||
return avatarText_;
|
||||
}
|
||||
|
||||
@ -205,10 +191,10 @@ QString User::avatarText() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] avatarText The avatar text.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setAvatarText(QString const &avatarText)
|
||||
{
|
||||
if (avatarText == avatarText_)
|
||||
void User::setAvatarText(QString const &avatarText) {
|
||||
if (avatarText == avatarText_) {
|
||||
return;
|
||||
}
|
||||
|
||||
avatarText_ = avatarText;
|
||||
emit usernameChanged(avatarText_);
|
||||
@ -218,8 +204,7 @@ void User::setAvatarText(QString const &avatarText)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The user state.
|
||||
//****************************************************************************************************************************************************
|
||||
UserState User::state() const
|
||||
{
|
||||
UserState User::state() const {
|
||||
return state_;
|
||||
}
|
||||
|
||||
@ -227,10 +212,10 @@ UserState User::state() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] state The user state.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setState(UserState state)
|
||||
{
|
||||
if (state_ == state)
|
||||
void User::setState(UserState state) {
|
||||
if (state_ == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
state_ = state;
|
||||
emit stateChanged(state);
|
||||
@ -240,8 +225,7 @@ void User::setState(UserState state)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The split mode status.
|
||||
//****************************************************************************************************************************************************
|
||||
bool User::splitMode() const
|
||||
{
|
||||
bool User::splitMode() const {
|
||||
return splitMode_;
|
||||
}
|
||||
|
||||
@ -249,10 +233,10 @@ bool User::splitMode() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] splitMode The split mode status.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setSplitMode(bool splitMode)
|
||||
{
|
||||
if (splitMode == splitMode_)
|
||||
void User::setSplitMode(bool splitMode) {
|
||||
if (splitMode == splitMode_) {
|
||||
return;
|
||||
}
|
||||
|
||||
splitMode_ = splitMode;
|
||||
emit splitModeChanged(splitMode_);
|
||||
@ -262,8 +246,7 @@ void User::setSplitMode(bool splitMode)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The used bytes.
|
||||
//****************************************************************************************************************************************************
|
||||
float User::usedBytes() const
|
||||
{
|
||||
float User::usedBytes() const {
|
||||
return usedBytes_;
|
||||
}
|
||||
|
||||
@ -271,10 +254,10 @@ float User::usedBytes() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] usedBytes The used bytes.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setUsedBytes(float usedBytes)
|
||||
{
|
||||
if (usedBytes == usedBytes_)
|
||||
void User::setUsedBytes(float usedBytes) {
|
||||
if (usedBytes == usedBytes_) {
|
||||
return;
|
||||
}
|
||||
|
||||
usedBytes_ = usedBytes;
|
||||
emit usedBytesChanged(usedBytes_);
|
||||
@ -284,8 +267,7 @@ void User::setUsedBytes(float usedBytes)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The total bytes.
|
||||
//****************************************************************************************************************************************************
|
||||
float User::totalBytes() const
|
||||
{
|
||||
float User::totalBytes() const {
|
||||
return totalBytes_;
|
||||
}
|
||||
|
||||
@ -293,10 +275,10 @@ float User::totalBytes() const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] totalBytes The total bytes.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::setTotalBytes(float totalBytes)
|
||||
{
|
||||
if (totalBytes == totalBytes_)
|
||||
void User::setTotalBytes(float totalBytes) {
|
||||
if (totalBytes == totalBytes_) {
|
||||
return;
|
||||
}
|
||||
|
||||
totalBytes_ = totalBytes;
|
||||
emit totalBytesChanged(totalBytes_);
|
||||
@ -307,13 +289,16 @@ void User::setTotalBytes(float totalBytes)
|
||||
/// \param[in] state The user state.
|
||||
/// \return A string describing the state.
|
||||
//****************************************************************************************************************************************************
|
||||
QString User::stateToString(UserState state)
|
||||
{
|
||||
QString User::stateToString(UserState state) {
|
||||
switch (state) {
|
||||
case UserState::SignedOut: return "Signed out";
|
||||
case UserState::Locked: return "Locked";
|
||||
case UserState::Connected: return "Connected";
|
||||
default: return "Unknown";
|
||||
case UserState::SignedOut:
|
||||
return "Signed out";
|
||||
case UserState::Locked:
|
||||
return "Locked";
|
||||
case UserState::Connected:
|
||||
return "Connected";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,8 +20,7 @@
|
||||
#define BRIDGE_PP_USER_H
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
@ -29,25 +28,25 @@ namespace bridgepp
|
||||
/// See https://qml.guide/enums-in-qt-qml/ for details (we used Q_OBJECT instead of Q_GADGET as in the reference document avoid a QML warning
|
||||
/// complaining about the case of the data type).
|
||||
//****************************************************************************************************************************************************
|
||||
class EUserState: public QObject
|
||||
{
|
||||
class EUserState : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class State
|
||||
{
|
||||
enum class State {
|
||||
SignedOut = 0,
|
||||
Locked = 1,
|
||||
Connected = 2
|
||||
};
|
||||
|
||||
|
||||
Q_ENUM(State)
|
||||
|
||||
|
||||
EUserState() = delete; ///< Default constructor.
|
||||
EUserState(EUserState const&) = delete; ///< Disabled copy-constructor.
|
||||
EUserState(EUserState&&) = delete; ///< Disabled assignment copy-constructor.
|
||||
EUserState(EUserState const &) = delete; ///< Disabled copy-constructor.
|
||||
EUserState(EUserState &&) = delete; ///< Disabled assignment copy-constructor.
|
||||
~EUserState() = default; ///< Destructor.
|
||||
EUserState& operator=(EUserState const&) = delete; ///< Disabled assignment operator.
|
||||
EUserState& operator=(EUserState&&) = delete; ///< Disabled move assignment operator.
|
||||
EUserState &operator=(EUserState const &) = delete; ///< Disabled assignment operator.
|
||||
EUserState &operator=(EUserState &&) = delete; ///< Disabled move assignment operator.
|
||||
};
|
||||
|
||||
|
||||
@ -60,8 +59,7 @@ typedef std::shared_ptr<class User> SPUser; ///< Type definition for shared poin
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief User class.
|
||||
//****************************************************************************************************************************************************
|
||||
class User : public QObject
|
||||
{
|
||||
class User : public QObject {
|
||||
|
||||
Q_OBJECT
|
||||
public: // static member function
|
||||
|
||||
@ -20,8 +20,7 @@
|
||||
#include "../Exception/Exception.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
@ -31,18 +30,17 @@ namespace bridgepp
|
||||
Overseer::Overseer(Worker *worker, QObject *parent)
|
||||
: QObject(parent)
|
||||
, thread_(new QThread(parent))
|
||||
, worker_(worker)
|
||||
{
|
||||
if (!worker_)
|
||||
, worker_(worker) {
|
||||
if (!worker_) {
|
||||
throw Exception("Overseer cannot accept a nil worker.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
Overseer::~Overseer()
|
||||
{
|
||||
Overseer::~Overseer() {
|
||||
this->releaseWorker();
|
||||
}
|
||||
|
||||
@ -50,21 +48,21 @@ Overseer::~Overseer()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] autorelease Should the overseer automatically release the worker and thread when done.
|
||||
//****************************************************************************************************************************************************
|
||||
void Overseer::startWorker(bool autorelease) const
|
||||
{
|
||||
if (!worker_)
|
||||
void Overseer::startWorker(bool autorelease) const {
|
||||
if (!worker_) {
|
||||
throw Exception("Cannot start overseer with null worker.");
|
||||
if (!thread_)
|
||||
}
|
||||
if (!thread_) {
|
||||
throw Exception("Cannot start overseer with null thread.");
|
||||
}
|
||||
|
||||
worker_->moveToThread(thread_);
|
||||
connect(thread_, &QThread::started, worker_, &Worker::run);
|
||||
connect(worker_, &Worker::finished, [&]() {thread_->quit(); }); // Safety, normally the thread already properly quits.
|
||||
connect(worker_, &Worker::finished, [&]() { thread_->quit(); }); // Safety, normally the thread already properly quits.
|
||||
connect(worker_, &Worker::error, [&]() { thread_->quit(); });
|
||||
connect(worker_, &Worker::cancelled, [&]() { thread_->quit(); });
|
||||
|
||||
if (autorelease)
|
||||
{
|
||||
if (autorelease) {
|
||||
connect(worker_, &Worker::error, this, &Overseer::releaseWorker);
|
||||
connect(worker_, &Worker::cancelled, this, &Overseer::releaseWorker);
|
||||
connect(worker_, &Worker::finished, this, &Overseer::releaseWorker);
|
||||
@ -77,18 +75,14 @@ void Overseer::startWorker(bool autorelease) const
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
void Overseer::releaseWorker()
|
||||
{
|
||||
if (worker_)
|
||||
{
|
||||
void Overseer::releaseWorker() {
|
||||
if (worker_) {
|
||||
worker_->deleteLater();
|
||||
worker_ = nullptr;
|
||||
}
|
||||
|
||||
if (thread_)
|
||||
{
|
||||
if (!thread_->isFinished())
|
||||
{
|
||||
if (thread_) {
|
||||
if (!thread_->isFinished()) {
|
||||
thread_->quit();
|
||||
thread_->wait();
|
||||
}
|
||||
@ -101,10 +95,10 @@ void Overseer::releaseWorker()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true iff the worker is finished.
|
||||
//****************************************************************************************************************************************************
|
||||
bool Overseer::isFinished() const
|
||||
{
|
||||
if ((!worker_) || (!worker_->thread()))
|
||||
bool Overseer::isFinished() const {
|
||||
if ((!worker_) || (!worker_->thread())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return worker_->thread()->isFinished();
|
||||
}
|
||||
@ -115,17 +109,19 @@ bool Overseer::isFinished() const
|
||||
/// never times out.
|
||||
/// \return false if and only if the timeout delay was reached.
|
||||
//****************************************************************************************************************************************************
|
||||
bool Overseer::wait(qint32 timeoutMs) const
|
||||
{
|
||||
if (this->isFinished())
|
||||
bool Overseer::wait(qint32 timeoutMs) const {
|
||||
if (this->isFinished()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
bool inTime = true;
|
||||
if (timeoutMs >= 0)
|
||||
{
|
||||
connect(&timer, &QTimer::timeout, &loop, [&]() { loop.quit(); inTime = false; } );
|
||||
if (timeoutMs >= 0) {
|
||||
connect(&timer, &QTimer::timeout, &loop, [&]() {
|
||||
loop.quit();
|
||||
inTime = false;
|
||||
});
|
||||
timer.setSingleShot(true);
|
||||
timer.start(timeoutMs);
|
||||
}
|
||||
@ -149,8 +145,7 @@ bool Overseer::wait(qint32 timeoutMs) const
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The worker.
|
||||
//****************************************************************************************************************************************************
|
||||
Worker *Overseer::worker() const
|
||||
{
|
||||
Worker *Overseer::worker() const {
|
||||
return worker_;
|
||||
}
|
||||
|
||||
|
||||
@ -23,15 +23,13 @@
|
||||
#include "Worker.h"
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Overseer used to manager a worker instance and its associated thread.
|
||||
//****************************************************************************************************************************************************
|
||||
class Overseer : public QObject
|
||||
{
|
||||
class Overseer : public QObject {
|
||||
Q_OBJECT
|
||||
public: // member functions.
|
||||
explicit Overseer(Worker *worker, QObject *parent); ///< Default constructor.
|
||||
@ -49,8 +47,8 @@ public slots:
|
||||
void releaseWorker(); ///< Delete the worker and its thread.
|
||||
|
||||
public: // data members.
|
||||
QThread *thread_{nullptr}; ///< The thread.
|
||||
Worker *worker_{nullptr}; ///< The worker.
|
||||
QThread *thread_ { nullptr }; ///< The thread.
|
||||
Worker *worker_ { nullptr }; ///< The worker.
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -20,20 +20,17 @@
|
||||
#define BRIDGE_PP_WORKER_H
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Pure virtual class for worker intended to perform a threaded operation.
|
||||
//****************************************************************************************************************************************************
|
||||
class Worker : public QObject
|
||||
{
|
||||
class Worker : public QObject {
|
||||
Q_OBJECT
|
||||
public: // member functions
|
||||
explicit Worker(QObject *parent)
|
||||
: QObject(parent)
|
||||
{} ///< Default constructor.
|
||||
: QObject(parent) {} ///< Default constructor.
|
||||
Worker(Worker const &) = delete; ///< Disabled copy-constructor.
|
||||
Worker(Worker &&) = delete; ///< Disabled assignment copy-constructor.
|
||||
~Worker() override = default; ///< Destructor.
|
||||
|
||||
Reference in New Issue
Block a user