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.
- Loading branch information
1 parent
ea98715
commit ff94fa0
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.