Skip to content

Commit

Permalink
PersisterController -> PersisterFacade
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 16, 2024
1 parent bb82124 commit 373620e
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 301 deletions.
10 changes: 5 additions & 5 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace
auto constexpr AutosaveSenderId = "Autosave";
}

_AutosaveWindow::_AutosaveWindow(SimulationController const& simController, PersisterController const& persisterController)
_AutosaveWindow::_AutosaveWindow(SimulationController const& simController, PersisterFacade const& persisterFacade)
: _AlienWindow("Autosave (work in progress)", "windows.autosave", false)
, _simController(simController)
, _persisterController(persisterController)
, _persisterFacade(persisterFacade)
{
_settingsOpen = GlobalSettings::get().getBool("windows.autosave.settings.open", _settingsOpen);
_settingsHeight = GlobalSettings::get().getFloat("windows.autosave.settings.height", _settingsHeight);
Expand Down Expand Up @@ -185,21 +185,21 @@ void _AutosaveWindow::createSavepoint()
static int i = 0;
auto senderInfo = SenderInfo{.senderId = SenderId{AutosaveSenderId}, .wishResultData = true, .wishErrorInfo = true};
auto saveData = SaveSimulationRequestData{"d:\\test" + std::to_string(++i) + ".sim", Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()};
auto jobId = _persisterController->scheduleSaveSimulationToFile(senderInfo, saveData);
auto jobId = _persisterFacade->scheduleSaveSimulationToFile(senderInfo, saveData);

_savePoints.emplace_front(SavepointState::InQueue, jobId.value, "", "", 0);
}

void _AutosaveWindow::updateSavepoint(SavepointEntry& savepoint)
{
if (savepoint.state != SavepointState::Persisted) {
auto requestState = _persisterController->getRequestState(PersisterRequestId(savepoint.id));
auto requestState = _persisterFacade->getRequestState(PersisterRequestId(savepoint.id));
if (requestState == PersisterRequestState::InProgress) {
savepoint.state = SavepointState::InProgress;
}
if (requestState == PersisterRequestState::Finished) {
savepoint.state = SavepointState::Persisted;
auto jobResult = _persisterController->fetchSavedSimulationData(PersisterRequestId{savepoint.id});
auto jobResult = _persisterFacade->fetchSavedSimulationData(PersisterRequestId{savepoint.id});
savepoint.timestep = jobResult.timestep;
savepoint.timestamp = StringHelper::format(jobResult.timestamp);
savepoint.name = jobResult.name;
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Definitions.h"
#include "AlienWindow.h"
#include "PersisterInterface/PersisterController.h"
#include "PersisterInterface/PersisterFacade.h"

enum class SavepointState
{
Expand All @@ -26,7 +26,7 @@ struct SavepointEntry
class _AutosaveWindow : public _AlienWindow
{
public:
_AutosaveWindow(SimulationController const& simController, PersisterController const& persisterController);
_AutosaveWindow(SimulationController const& simController, PersisterFacade const& persisterFacade);
~_AutosaveWindow();

private:
Expand All @@ -43,7 +43,7 @@ class _AutosaveWindow : public _AlienWindow
void validationAndCorrection();

SimulationController _simController;
PersisterController _persisterController;
PersisterFacade _persisterFacade;

bool _settingsOpen = false;
float _settingsHeight = 130.0f;
Expand Down
16 changes: 8 additions & 8 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ namespace

_BrowserWindow::_BrowserWindow(
SimulationController const& simController,
PersisterController const& persisterController,
PersisterFacade const& persisterFacade,
StatisticsWindow const& statisticsWindow,
TemporalControlWindow const& temporalControlWindow,
EditorController const& editorController)
: _AlienWindow("Browser", "windows.browser", true)
, _simController(simController)
, _persisterController(persisterController)
, _persisterFacade(persisterFacade)
, _statisticsWindow(statisticsWindow)
, _temporalControlWindow(temporalControlWindow)
, _editorController(editorController)
{
_downloadCache = std::make_shared<_DownloadCache>();
_refreshProcessor = _TaskProcessor::createTaskProcessor(_persisterController);
_emojiProcessor = _TaskProcessor::createTaskProcessor(_persisterController);
_refreshProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
_emojiProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);

auto& settings = GlobalSettings::get();
_currentWorkspace.resourceType = settings.getInt("windows.browser.resource type", _currentWorkspace.resourceType);
Expand Down Expand Up @@ -170,11 +170,11 @@ void _BrowserWindow::refreshIntern(bool withRetry)
{
_refreshProcessor->executeTask(
[&](auto const& senderId) {
return _persisterController->scheduleGetNetworkResources(
return _persisterFacade->scheduleGetNetworkResources(
SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = withRetry}, GetNetworkResourcesRequestData());
},
[&](auto const& requestId) {
auto data = _persisterController->fetchGetNetworkResourcesData(requestId);
auto data = _persisterFacade->fetchGetNetworkResourcesData(requestId);
_userTOs = data.userTOs;
_ownEmojiTypeBySimId = data.emojiTypeByResourceId;

Expand Down Expand Up @@ -1446,12 +1446,12 @@ std::string _BrowserWindow::getUserNamesToEmojiType(std::string const& resourceI
if (!_emojiProcessor->pendingTasks()) {
_emojiProcessor->executeTask(
[&](auto const& senderId) {
return _persisterController->scheduleGetUserNamesForEmoji(
return _persisterFacade->scheduleGetUserNamesForEmoji(
SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = false},
GetUserNamesForEmojiRequestData{.resourceId = resourceId, .emojiType = emojiType});
},
[&](auto const& requestId) {
auto data = _persisterController->fetchGetUserNamesForEmojiData(requestId);
auto data = _persisterFacade->fetchGetUserNamesForEmojiData(requestId);
_userNamesByEmojiTypeBySimIdCache.emplace(std::make_pair(data.resourceId, data.emojiType), data.userNames);
},
[](auto const& errors) { MessageDialog::get().information("Error", errors); });
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Network/NetworkResourceRawTO.h"
#include "Network/UserTO.h"
#include "EngineInterface/SerializerService.h"
#include "PersisterInterface/PersisterController.h"
#include "PersisterInterface/PersisterFacade.h"

#include "AlienWindow.h"
#include "Definitions.h"
Expand All @@ -22,7 +22,7 @@ class _BrowserWindow : public _AlienWindow
public:
_BrowserWindow(
SimulationController const& simController,
PersisterController const& persisterController,
PersisterFacade const& persisterFacade,
StatisticsWindow const& statisticsWindow,
TemporalControlWindow const& temporalControlWindow,
EditorController const& editorController);
Expand Down Expand Up @@ -143,7 +143,7 @@ class _BrowserWindow : public _AlienWindow
DownloadCache _downloadCache;

SimulationController _simController;
PersisterController _persisterController;
PersisterFacade _persisterFacade;
StatisticsWindow _statisticsWindow;
TemporalControlWindow _temporalControlWindow;
LoginDialogWeakPtr _loginDialog;
Expand Down
16 changes: 8 additions & 8 deletions source/Gui/FileTransferController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace
}

void FileTransferController::init(
PersisterController const& persisterController,
PersisterFacade const& persisterFacade,
SimulationController const& simController,
TemporalControlWindow const& temporalControlWindow)
{
_persisterController = persisterController;
_persisterFacade = persisterFacade;
_simController = simController;
_temporalControlWindow = temporalControlWindow;
_openSimulationProcessor = _TaskProcessor::createTaskProcessor(_persisterController);
_openSimulationProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
}

void FileTransferController::onOpenSimulation()
Expand All @@ -40,11 +40,11 @@ void FileTransferController::onOpenSimulation()
[&](auto const& senderId) {
auto senderInfo = SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = true};
auto readData = ReadSimulationRequestData{firstFilename.string()};
return _persisterController->scheduleReadSimulationFromFile(senderInfo, readData);
return _persisterFacade->scheduleReadSimulationFromFile(senderInfo, readData);
},
[&](auto const& requestId) {
auto const& data = _persisterController->fetchReadSimulationData(requestId);
_persisterController->shutdown();
auto const& data = _persisterFacade->fetchReadSimulationData(requestId);
_persisterFacade->shutdown();

_simController->closeSimulation();

Expand Down Expand Up @@ -73,7 +73,7 @@ void FileTransferController::onOpenSimulation()
data.deserializedSimulation.auxiliaryData.generalSettings,
data.deserializedSimulation.auxiliaryData.simulationParameters);
}
_persisterController->restart();
_persisterFacade->restart();

Viewport::setCenterInWorldPos(data.deserializedSimulation.auxiliaryData.center);
Viewport::setZoomFactor(data.deserializedSimulation.auxiliaryData.zoom);
Expand All @@ -94,7 +94,7 @@ void FileTransferController::onSaveSimulation()
printOverlayMessage("Saving ...");
auto senderInfo = SenderInfo{.senderId = SenderId{FileTransferSenderId}, .wishResultData = false, .wishErrorInfo = true};
auto saveData = SaveSimulationRequestData{firstFilename.string(), Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()};
_persisterController->scheduleSaveSimulationToFile(senderInfo, saveData);
_persisterFacade->scheduleSaveSimulationToFile(senderInfo, saveData);
});
}

Expand Down
4 changes: 2 additions & 2 deletions source/Gui/FileTransferController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class FileTransferController
MAKE_SINGLETON(FileTransferController);

public:
void init(PersisterController const& persisterController, SimulationController const& simController, TemporalControlWindow const& temporalControlWindow);
void init(PersisterFacade const& persisterFacade, SimulationController const& simController, TemporalControlWindow const& temporalControlWindow);

void onOpenSimulation();
void onSaveSimulation();

void process();

private:
PersisterController _persisterController;
PersisterFacade _persisterFacade;
SimulationController _simController;
TemporalControlWindow _temporalControlWindow;

Expand Down
10 changes: 5 additions & 5 deletions source/Gui/LoginController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

void LoginController::init(
SimulationController const& simController,
PersisterController const& persisterController,
PersisterFacade const& persisterFacade,
ActivateUserDialog const& activateUserDialog,
BrowserWindow const& browserWindow)
{
_simController = simController;
_persisterController = persisterController;
_persisterFacade = persisterFacade;
_activateUserDialog = activateUserDialog;
_browserWindow = browserWindow;
_taskProcessor = _TaskProcessor::createTaskProcessor(_persisterController);
_taskProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);

auto& settings = GlobalSettings::get();
_remember = settings.getBool("controller.login.remember", _remember);
Expand All @@ -44,7 +44,7 @@ void LoginController::onLogin()
if (!_userName.empty()) {
_taskProcessor->executeTask(
[&](auto const& senderId) {
auto result = _persisterController->scheduleLogin(
auto result = _persisterFacade->scheduleLogin(
SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = true},
LoginRequestData{.userName = _userName, .password = _password, .userInfo = getUserInfo()});
if (!_remember) {
Expand All @@ -54,7 +54,7 @@ void LoginController::onLogin()
return result;
},
[&](auto const& requestId) {
auto const& data = _persisterController->fetchLoginData(requestId);
auto const& data = _persisterFacade->fetchLoginData(requestId);
if (data.unknownUser) {
auto& settings = GlobalSettings::get();
auto userName = settings.getString("dialogs.login.user name", "");
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/LoginController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include "Base/Singleton.h"
#include "Definitions.h"
#include "PersisterInterface/PersisterController.h"
#include "PersisterInterface/PersisterFacade.h"

class LoginController
{
MAKE_SINGLETON(LoginController);
public:

void init(SimulationController const& simController, PersisterController const& persisterController, ActivateUserDialog const& activateUserDialog, BrowserWindow const& browserWindow);
void init(SimulationController const& simController, PersisterFacade const& persisterFacade, ActivateUserDialog const& activateUserDialog, BrowserWindow const& browserWindow);
void shutdown();

void onLogin();
Expand All @@ -34,7 +34,7 @@ class LoginController

private:
SimulationController _simController;
PersisterController _persisterController;
PersisterFacade _persisterFacade;
ActivateUserDialog _activateUserDialog;
BrowserWindow _browserWindow;

Expand Down
4 changes: 2 additions & 2 deletions source/Gui/LoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

_LoginDialog::_LoginDialog(
SimulationController const& simController,
PersisterController const& persisterController,
PersisterFacade const& persisterFacade,
CreateUserDialog const& createUserDialog,
ActivateUserDialog const& activateUserDialog,
ResetPasswordDialog const& resetPasswordDialog)
: _AlienDialog("Login")
, _simController(simController)
, _persisterController(persisterController)
, _persisterFacade(persisterFacade)
, _createUserDialog(createUserDialog)
, _activateUserDialog(activateUserDialog)
, _resetPasswordDialog(resetPasswordDialog)
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/LoginDialog.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "Network/Definitions.h"
#include "PersisterInterface/PersisterController.h"
#include "PersisterInterface/PersisterFacade.h"

#include "AlienDialog.h"
#include "Definitions.h"
Expand All @@ -11,7 +11,7 @@ class _LoginDialog : public _AlienDialog
public:
_LoginDialog(
SimulationController const& simController,
PersisterController const& persisterController,
PersisterFacade const& persisterFacade,
CreateUserDialog const& createUserDialog,
ActivateUserDialog const& activateUserDialog,
ResetPasswordDialog const& resetPasswordDialog);
Expand All @@ -21,7 +21,7 @@ class _LoginDialog : public _AlienDialog
void processIntern();

SimulationController _simController;
PersisterController _persisterController;
PersisterFacade _persisterFacade;
BrowserWindow _browserWindow;
CreateUserDialog _createUserDialog;
ActivateUserDialog _activateUserDialog;
Expand Down
8 changes: 4 additions & 4 deletions source/Gui/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Base/FileLogger.h"
#include "EngineInterface/SerializerService.h"
#include "EngineImpl/SimulationControllerImpl.h"
#include "PersisterImpl/PersisterControllerImpl.h"
#include "PersisterImpl/PersisterFacadeImpl.h"

#include "MainWindow.h"
#include "GuiLogger.h"
Expand All @@ -33,13 +33,13 @@ int main(int argc, char** argv)
}

SimulationController simController;
PersisterController persisterController;
PersisterFacade persisterFacade;
MainWindow mainWindow;

try {
simController = std::make_shared<_SimulationControllerImpl>();
persisterController = std::make_shared<_PersisterControllerImpl>();
mainWindow = std::make_shared<_MainWindow>(simController, persisterController, logger);
persisterFacade = std::make_shared<_PersisterFacadeImpl>();
mainWindow = std::make_shared<_MainWindow>(simController, persisterFacade, logger);
mainWindow->mainLoop();
mainWindow->shutdown();

Expand Down
Loading

0 comments on commit 373620e

Please sign in to comment.