forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit e5e1d6e Author: Antoine C <[email protected]> Date: Thu Oct 17 01:16:02 2024 +0100 fixup! feat: inter controller communication commit 0fe8c3b Author: Antoine C <[email protected]> Date: Mon May 13 16:28:58 2024 +0100 Throw JS error instead of logging and prompting an error message commit a01c37c Author: Antoine C <[email protected]> Date: Mon May 13 14:57:47 2024 +0100 Add namespace isolation to prevent clash commit c960ff9 Author: Antoine C <[email protected]> Date: Fri Mar 29 11:41:15 2024 +0000 Update method naming to have better consistency with existing one commit 14a1a6a Author: Antoine C <[email protected]> Date: Sat Nov 4 20:15:11 2023 +0000 feat: inter controller communication
- Loading branch information
1 parent
cdcbd4e
commit 42f29c1
Showing
21 changed files
with
532 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <controllers/controllershareddata.h> | ||
|
||
#include "moc_controllershareddata.cpp" | ||
|
||
ControllerNamespacedSharedData* ControllerSharedData::namespaced(const QString& ns) { | ||
return new ControllerNamespacedSharedData(this, ns); | ||
} | ||
|
||
ControllerNamespacedSharedData::ControllerNamespacedSharedData( | ||
ControllerSharedData* parent, const QString& ns) | ||
: QObject(parent), | ||
m_namespace(ns) { | ||
connect(parent, | ||
&ControllerSharedData::updated, | ||
this, | ||
[this](const QString& ns, const QVariant& value) { | ||
if (ns != m_namespace) { | ||
return; | ||
} | ||
emit updated(value); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include <QVariant> | ||
|
||
#include "util/assert.h" | ||
|
||
class ControllerNamespacedSharedData; | ||
|
||
/// ControllerSharedData is a wrapper that allows controllers script runtimes | ||
/// to share arbitrary data via a the JavaScript interface. Controllers don't | ||
/// access this object directly, and instead uses the | ||
/// ControllerNamespacedSharedData wrapper to isolate a specific namespace and | ||
/// prevent potential clash | ||
class ControllerSharedData : public QObject { | ||
Q_OBJECT | ||
public: | ||
ControllerSharedData(QObject* parent) | ||
: QObject(parent), | ||
m_value() { | ||
} | ||
|
||
QVariant get(const QString& ns) const { | ||
return m_value.value(ns); | ||
} | ||
|
||
/// @brief Create a a namespace wrapper that can be used by a controller. | ||
/// The caller is owning the wrapper | ||
/// @param ns The namespace to restrict access to | ||
/// @return The pointer to the newly allocated wrapper | ||
ControllerNamespacedSharedData* namespaced(const QString& ns); | ||
|
||
public slots: | ||
void set(const QString& ns, const QVariant& value) { | ||
m_value[ns] = value; | ||
emit updated(ns, m_value[ns]); | ||
} | ||
|
||
signals: | ||
void updated(const QString& ns, const QVariant& value); | ||
|
||
private: | ||
QHash<QString, QVariant> m_value; | ||
}; | ||
|
||
/// ControllerNamespacedSharedData is a wrapper that restrict access to a given | ||
/// namespace. It doesn't hold any data and can safely be deleted at all time, | ||
/// but only provide the namespace abstraction for controller to interact with | ||
/// via a the JavaScript interface | ||
class ControllerNamespacedSharedData : public QObject { | ||
Q_OBJECT | ||
public: | ||
ControllerNamespacedSharedData(ControllerSharedData* parent, const QString& ns); | ||
|
||
QVariant get() const { | ||
return static_cast<ControllerSharedData*>(parent())->get(m_namespace); | ||
} | ||
|
||
public slots: | ||
void set(const QVariant& value) { | ||
static_cast<ControllerSharedData*>(parent())->set(m_namespace, value); | ||
} | ||
|
||
signals: | ||
void updated(const QVariant& value); | ||
|
||
private: | ||
QString m_namespace; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.