Skip to content

Commit

Permalink
Greatly improve frontend/backend communication hygiene + logging
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Oct 24, 2024
1 parent 2361e0e commit 67da49b
Show file tree
Hide file tree
Showing 67 changed files with 1,196 additions and 967 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ endif()

include(OB/FetchQx)
ob_fetch_qx(
REF "b29e03cf42dfed65a5ecaf18ce192f3051f0e25f"
REF "9043d76da8214c8bbe3f3343c72c5382b85dc36a"
COMPONENTS
${CLIFP_QX_COMPONENTS}
)
Expand All @@ -99,7 +99,7 @@ ob_fetch_quazip(

# Fetch Neargye's Magic Enum
include(OB/FetchMagicEnum)
ob_fetch_magicenum("v0.9.3")
ob_fetch_magicenum("v0.9.6")

# Process Targets
set(APP_TARGET_NAME ${PROJECT_NAMESPACE_LC}_${PROJECT_NAMESPACE_LC})
Expand Down
6 changes: 5 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ set(CLIFP_SOURCE
kernel/buildinfo.h
kernel/core.h
kernel/core.cpp
kernel/directive.h
kernel/director.h
kernel/director.cpp
kernel/directorate.h
kernel/directorate.cpp
kernel/driver.h
kernel/driver.cpp
kernel/errorstatus.h
Expand Down Expand Up @@ -57,7 +62,6 @@ set(CLIFP_SOURCE
tools/mounter_qmp.cpp
tools/mounter_router.h
tools/mounter_router.cpp
frontend/message.h
frontend/statusrelay.h
frontend/statusrelay.cpp
controller.h
Expand Down
11 changes: 6 additions & 5 deletions app/src/command/c-download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "c-download.h"

// Project Includes
#include "kernel/core.h"
#include "task/t-download.h"
#include "task/t-generic.h"

Expand Down Expand Up @@ -61,13 +62,13 @@ Qx::Error CDownload::perform()
if(pItr == playlists.cend())
{
CDownloadError err(CDownloadError::InvalidPlaylist, playlistName);
postError(err);
postDirective<DError>(err);
return err;
}
logEvent(LOG_EVENT_PLAYLIST_MATCH.arg(pItr->id().toString(QUuid::WithoutBraces)));

// Queue downloads for each game
TDownload* downloadTask = new TDownload(&mCore);
TDownload* downloadTask = new TDownload(mCore);
downloadTask->setStage(Task::Stage::Primary);
downloadTask->setDescription(u"playlist data packs"_s);
QList<int> dataIds;
Expand All @@ -83,7 +84,7 @@ Qx::Error CDownload::perform()
Fp::GameData gameData;
if(Fp::DbError gdErr = db->getGameData(gameData, pg.gameId()); gdErr.isValid())
{
postError(gdErr);
postDirective<DError>(gdErr);
return gdErr;
}

Expand All @@ -100,7 +101,7 @@ Qx::Error CDownload::perform()
TDownloadError packError = downloadTask->addDatapack(tk, &gameData);
if(packError.isValid())
{
postError(packError);
postDirective<DError>(packError);
return packError;
}

Expand All @@ -119,7 +120,7 @@ Qx::Error CDownload::perform()

// Enqueue onDiskState update task
Core* corePtr = &mCore; // Safe, will outlive task
TGeneric* onDiskUpdateTask = new TGeneric(corePtr);
TGeneric* onDiskUpdateTask = new TGeneric(mCore);
onDiskUpdateTask->setStage(Task::Stage::Primary);
onDiskUpdateTask->setDescription(u"Update GameData onDisk state."_s);
onDiskUpdateTask->setAction([dataIds, corePtr]{
Expand Down
18 changes: 11 additions & 7 deletions app/src/command/c-link.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Unit Include
#include "c-link.h"

// Project Includes
#include "kernel/core.h"

//===============================================================================================================
// CLinkError
//===============================================================================================================
Expand Down Expand Up @@ -59,7 +62,7 @@ Qx::Error CLink::perform()
Fp::DbError dbError = database->getEntry(entry_v, shortcutId);
if(dbError.isValid())
{
postError(dbError);
postDirective<DError>(dbError);
return dbError;
}

Expand All @@ -76,7 +79,7 @@ Qx::Error CLink::perform()
Fp::DbError dbError = database->getEntry(entry_v, addApp.parentId());
if(dbError.isValid())
{
postError(dbError);
postDirective<DError>(dbError);
return dbError;
}
Q_ASSERT(std::holds_alternative<Fp::Game>(entry_v));
Expand All @@ -99,11 +102,12 @@ Qx::Error CLink::perform()
logEvent(LOG_EVENT_NO_PATH);

// Prompt user for path
Core::ExistingDirRequest edr{
QString selectedPath; // Default is empty dir
postDirective(DExistingDir{
.caption = DIAG_CAPTION,
.dir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)
};
QString selectedPath = mCore.requestExistingDirPath(edr);
.startingDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
.response = &selectedPath
});

if(selectedPath.isEmpty())
{
Expand All @@ -123,7 +127,7 @@ Qx::Error CLink::perform()
if(!shortcutDir.mkpath(shortcutDir.absolutePath()))
{
CLinkError err(CLinkError::InvalidPath);
postError(err);
postDirective<DError>(err);
return err;
}
logEvent(LOG_EVENT_CREATED_DIR_PATH.arg(QDir::toNativeSeparators(shortcutDir.absolutePath())));
Expand Down
7 changes: 4 additions & 3 deletions app/src/command/c-link_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// Project Includes
#include "c-play.h"
#include "project_vars.h"
#include "utility.h"

//===============================================================================================================
Expand All @@ -20,7 +21,7 @@ Qx::Error CLink::createShortcut(const QString& name, const QDir& dir, QUuid id)
if(!Utility::installAppIconForUser())
{
CLinkError err(CLinkError::IconInstallFailed);
mCore.postError(NAME, err);
postDirective<DError>(err);
return err;
}

Expand All @@ -41,11 +42,11 @@ Qx::Error CLink::createShortcut(const QString& name, const QDir& dir, QUuid id)
// Check for write error
if(writeReport.isFailure())
{
mCore.postError(NAME, writeReport);
postDirective<DError>(writeReport);
return writeReport;
}

mCore.logEvent(NAME, LOG_EVENT_CREATED_SHORTCUT.arg(id.toString(QUuid::WithoutBraces), QDir::toNativeSeparators(fullEntryPath)));
logEvent(LOG_EVENT_CREATED_SHORTCUT.arg(id.toString(QUuid::WithoutBraces), QDir::toNativeSeparators(fullEntryPath)));

// Return success
return CLinkError();
Expand Down
2 changes: 1 addition & 1 deletion app/src/command/c-link_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Qx::Error CLink::createShortcut(const QString& name, const QDir& dir, QUuid id)
// Check for creation failure
if(shortcutError.isValid())
{
postError(shortcutError);
postDirective<DError>(shortcutError);
return shortcutError;
}
else
Expand Down
27 changes: 14 additions & 13 deletions app/src/command/c-play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include <qx/core/qx-regularexpression.h>

// Project Includes
#include "../task/t-exec.h"
#include "../task/t-message.h"
#include "../task/t-extra.h"
#include "kernel/core.h"
#include "task/t-exec.h"
#include "task/t-message.h"
#include "task/t-extra.h"

//===============================================================================================================
// CPlayError
Expand Down Expand Up @@ -100,7 +101,7 @@ Qx::Error CPlay::handleEntry(const Fp::Game& game)
Fp::GameData gameData;
if(Fp::DbError gdErr = db->getGameData(gameData, game.id()); gdErr.isValid())
{
postError(gdErr);
postDirective<DError>(gdErr);
return gdErr;
}
bool hasDatapack = !gameData.isNull();
Expand Down Expand Up @@ -130,7 +131,7 @@ Qx::Error CPlay::handleEntry(const Fp::Game& game)
addAppSearchError = db->queryEntrys(addAppSearchResult, addAppFilter);
if(addAppSearchError.isValid())
{
postError(addAppSearchError);
postDirective<DError>(addAppSearchError);
return addAppSearchError;
}

Expand Down Expand Up @@ -176,7 +177,7 @@ Qx::Error CPlay::handleEntry(const Fp::AddApp& addApp)
Fp::GameData parentGameData;
if(Fp::DbError gdErr = db->getGameData(parentGameData, parentId); gdErr.isValid())
{
postError(gdErr);
postDirective<DError>(gdErr);
return gdErr;
}
bool hasDatapack = !parentGameData.isNull();
Expand Down Expand Up @@ -205,7 +206,7 @@ Qx::Error CPlay::handleEntry(const Fp::AddApp& addApp)

if(Fp::DbError pge = db->queryEntrys(parentResult, parentFilter); pge.isValid())
{
postError(pge);
postDirective<DError>(pge);
return pge;
}

Expand All @@ -232,7 +233,7 @@ Qx::Error CPlay::enqueueAdditionalApp(const Fp::AddApp& addApp, const QString& p
{
if(addApp.appPath() == Fp::Db::Table_Add_App::ENTRY_MESSAGE)
{
TMessage* messageTask = new TMessage(&mCore);
TMessage* messageTask = new TMessage(mCore);
messageTask->setStage(taskStage);
messageTask->setText(addApp.launchCommand());
messageTask->setBlocking(addApp.isWaitExit());
Expand All @@ -241,7 +242,7 @@ Qx::Error CPlay::enqueueAdditionalApp(const Fp::AddApp& addApp, const QString& p
}
else if(addApp.appPath() == Fp::Db::Table_Add_App::ENTRY_EXTRAS)
{
TExtra* extraTask = new TExtra(&mCore);
TExtra* extraTask = new TExtra(mCore);
extraTask->setStage(taskStage);
extraTask->setDirectory(QDir(mCore.fpInstall().extrasDirectory().absolutePath() + '/' + addApp.launchCommand()));

Expand All @@ -254,7 +255,7 @@ Qx::Error CPlay::enqueueAdditionalApp(const Fp::AddApp& addApp, const QString& p
QString param = addApp.launchCommand();
addPassthroughParameters(param);

TExec* addAppTask = new TExec(&mCore);
TExec* addAppTask = new TExec(mCore);
addAppTask->setIdentifier(addApp.name());
addAppTask->setStage(taskStage);
addAppTask->setExecutable(QDir::cleanPath(addAppPathInfo.absoluteFilePath())); // Like canonical but doesn't care if path DNE
Expand Down Expand Up @@ -284,7 +285,7 @@ Qx::Error CPlay::enqueueGame(const Fp::Game& game, const Fp::GameData& gameData,
QString param = !gameData.isNull() ? gameData.launchCommand() : game.launchCommand();
addPassthroughParameters(param);

TExec* gameTask = new TExec(&mCore);
TExec* gameTask = new TExec(mCore);
gameTask->setIdentifier(game.title());
gameTask->setStage(taskStage);
gameTask->setExecutable(QDir::cleanPath(gamePathInfo.absoluteFilePath())); // Like canonical but doesn't care if path DNE
Expand Down Expand Up @@ -320,7 +321,7 @@ Qx::Error CPlay::perform()
if(!urlMatch.hasMatch())
{
CPlayError err(CPlayError::InvalidUrl);
postError(err);
postDirective<DError>(err);
return err;
}

Expand All @@ -341,7 +342,7 @@ Qx::Error CPlay::perform()
Fp::Entry entry;
if(Fp::DbError eErr = db->getEntry(entry, titleId); eErr.isValid())
{
postError(eErr);
postDirective<DError>(eErr);
return eErr;
}

Expand Down
1 change: 1 addition & 0 deletions app/src/command/c-play.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// Project Includes
#include "command/title-command.h"
#include "task/task.h"

class QX_ERROR_TYPE(CPlayError, "CPlayError", 1212)
{
Expand Down
5 changes: 4 additions & 1 deletion app/src/command/c-prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// Qx Includes
#include <qx/core/qx-genericerror.h>

// Project Includes
#include "kernel/core.h"

//===============================================================================================================
// CPREPARE
//===============================================================================================================
Expand All @@ -28,7 +31,7 @@ Qx::Error CPrepare::perform()
Fp::GameData titleGameData;
if(Fp::DbError gdErr = mCore.fpInstall().database()->getGameData(titleGameData, id); gdErr.isValid())
{
postError(gdErr);
postDirective<DError>(gdErr);
return gdErr;
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/command/c-run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "c-run.h"

// Project Includes
#include "kernel/core.h"
#include "task/t-exec.h"

//===============================================================================================================
Expand Down Expand Up @@ -50,7 +51,7 @@ Qx::Error CRun::perform()
QString inputPath = mCore.resolveFullAppPath(mParser.value(CL_OPTION_APP), u""_s); // No way of knowing platform
QFileInfo inputInfo = QFileInfo(inputPath);

TExec* runTask = new TExec(&mCore);
TExec* runTask = new TExec(mCore);
runTask->setIdentifier(NAME + u" program"_s);
runTask->setStage(Task::Stage::Primary);
runTask->setExecutable(QDir::cleanPath(inputInfo.absoluteFilePath())); // Like canonical but doesn't care if path DNE
Expand Down
13 changes: 7 additions & 6 deletions app/src/command/c-share.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <qx/core/qx-system.h>

// Project Includes
#include "kernel/core.h"
#include "task/t-message.h"
#include "utility.h"

Expand Down Expand Up @@ -54,12 +55,12 @@ Qx::Error CShare::perform()
if(!Qx::setDefaultProtocolHandler(SCHEME, SCHEME_NAME))
{
CShareError err(CShareError::RegistrationFailed);
postError(err);
postDirective<DError>(err);
return err;
}

// Enqueue success message task
TMessage* successMsg = new TMessage(&mCore);
TMessage* successMsg = new TMessage(mCore);
successMsg->setStage(Task::Stage::Primary);
successMsg->setText(MSG_REGISTRATION_COMPLETE);
mCore.enqueueSingleTask(successMsg);
Expand All @@ -77,12 +78,12 @@ Qx::Error CShare::perform()
#endif
{
CShareError err(CShareError::UnregistrationFailed);
postError(err);
postDirective<DError>(err);
return err;
}

// Enqueue success message task
TMessage* successMsg = new TMessage(&mCore);
TMessage* successMsg = new TMessage(mCore);
successMsg->setStage(Task::Stage::Primary);
successMsg->setText(MSG_UNREGISTRATION_COMPLETE);
mCore.enqueueSingleTask(successMsg);
Expand All @@ -103,10 +104,10 @@ Qx::Error CShare::perform()
logEvent(LOG_EVENT_URL.arg(shareUrl));

// Add URL to clipboard
mCore.requestClipboardUpdate(shareUrl);
postDirective<DClipboardUpdate>(shareUrl);

// Enqueue message task
TMessage* urlMsg = new TMessage(&mCore);
TMessage* urlMsg = new TMessage(mCore);
urlMsg->setStage(Task::Stage::Primary);
urlMsg->setText(MSG_GENERATED_URL.arg(shareUrl));
urlMsg->setSelectable(true);
Expand Down
Loading

0 comments on commit 67da49b

Please sign in to comment.