summaryrefslogtreecommitdiffstats
path: root/src/core/nodes
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/nodes')
-rw-r--r--src/core/nodes/qbackendnode.cpp20
-rw-r--r--src/core/nodes/qbackendnode.h4
-rw-r--r--src/core/nodes/qnode.cpp45
-rw-r--r--src/core/nodes/qnode.h5
4 files changed, 74 insertions, 0 deletions
diff --git a/src/core/nodes/qbackendnode.cpp b/src/core/nodes/qbackendnode.cpp
index dc751cb93..65d140067 100644
--- a/src/core/nodes/qbackendnode.cpp
+++ b/src/core/nodes/qbackendnode.cpp
@@ -42,6 +42,7 @@
#include <Qt3DCore/qaspectengine.h>
#include <Qt3DCore/qnode.h>
+#include <Qt3DCore/qnodecommand.h>
#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DCore/private/corelogging_p.h>
@@ -206,6 +207,25 @@ void QBackendNode::notifyObservers(const QSceneChangePtr &e)
d->notifyObservers(e);
}
+QNodeCommand::CommandId QBackendNode::sendCommand(const QString &name,
+ const QVariant &data,
+ QNodeCommand::CommandId replyTo)
+{
+ auto e = QNodeCommandPtr::create(peerId());
+ e->setName(name);
+ e->setData(data);
+ e->setReplyToCommandId(replyTo);
+ e->setDeliveryFlags(QSceneChange::Nodes);
+ notifyObservers(e);
+ return e->commandId();
+}
+
+void QBackendNode::sendReply(const QNodeCommandPtr &command)
+{
+ command->setDeliveryFlags(QSceneChange::Nodes);
+ notifyObservers(command);
+}
+
void QBackendNode::initializeFromPeer(const QNodeCreatedChangeBasePtr &change)
{
Q_UNUSED(change);
diff --git a/src/core/nodes/qbackendnode.h b/src/core/nodes/qbackendnode.h
index d2cae5696..99e483cff 100644
--- a/src/core/nodes/qbackendnode.h
+++ b/src/core/nodes/qbackendnode.h
@@ -42,6 +42,7 @@
#include <Qt3DCore/qnodecreatedchange.h>
#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/qnodecommand.h>
#include <Qt3DCore/qscenechange.h>
#include <Qt3DCore/qt3dcore_global.h>
@@ -90,6 +91,9 @@ protected:
Q_DECLARE_PRIVATE(QBackendNode)
explicit QBackendNode(QBackendNodePrivate &dd);
void notifyObservers(const QSceneChangePtr &e);
+ QNodeCommand::CommandId sendCommand(const QString &name, const QVariant &data,
+ QNodeCommand::CommandId replyTo = QNodeCommand::CommandId());
+ void sendReply(const QNodeCommandPtr &command);
virtual void sceneChangeEvent(const QSceneChangePtr &e);
QBackendNodePrivate *d_ptr;
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index ce5e76a55..58e016cda 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -902,6 +902,51 @@ QNodeCreatedChangeBasePtr QNode::createNodeCreationChange() const
return QNodeCreatedChangeBasePtr::create(this);
}
+/*!
+ * \brief Sends a command messages to the backend node
+ *
+ * Creates a QNodeCommand message and dispatches it to the backend node. The
+ * command is given and a \a name and some \a data which can be used in the
+ * backend node to performe various operations.
+ * This returns a CommandId which can be used to identify the initial command
+ * when receiving a message in reply. If the command message is to be sent in
+ * reply to another command, \a replyTo contains the id of that command.
+ *
+ * \sa QNodeCommand, QNode::sendReply
+ */
+QNodeCommand::CommandId QNode::sendCommand(const QString &name,
+ const QVariant &data,
+ QNodeCommand::CommandId replyTo)
+{
+ Q_D(QNode);
+
+ // Bail out early if we can to avoid operator new
+ if (d->m_blockNotifications)
+ return QNodeCommand::CommandId(0);
+
+ auto e = QNodeCommandPtr::create(d->m_id);
+ e->setName(name);
+ e->setData(data);
+ e->setReplyToCommandId(replyTo);
+ d->notifyObservers(e);
+ return e->commandId();
+}
+
+/*!
+ * \brief Send a command back to the backend node
+ *
+ * Assumes the command is to be to sent back in reply to itself to the backend node
+ *
+ * \sa QNodeCommand, QNode::sendCommand
+ */
+void QNode::sendReply(const QNodeCommandPtr &command)
+{
+ Q_D(QNode);
+ command->setDeliveryFlags(QSceneChange::BackendNodes);
+ d->notifyObservers(command);
+}
+
+
namespace {
/*! \internal */
diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h
index cf3a16301..1fe03f5e0 100644
--- a/src/core/nodes/qnode.h
+++ b/src/core/nodes/qnode.h
@@ -42,6 +42,7 @@
#include <Qt3DCore/qnodecreatedchange.h>
#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/qnodecommand.h>
#include <Qt3DCore/qscenechange.h>
#include <Qt3DCore/qt3dcore_global.h>
#include <QtCore/QObject>
@@ -98,6 +99,10 @@ public:
void clearPropertyTracking(const QString &propertyName);
void clearPropertyTrackings();
+ QNodeCommand::CommandId sendCommand(const QString &name, const QVariant &data = QVariant(),
+ QNodeCommand::CommandId replyTo = QNodeCommand::CommandId());
+ void sendReply(const QNodeCommandPtr &command);
+
public Q_SLOTS:
void setParent(QNode *parent);
void setEnabled(bool isEnabled);