diff options
author | Brett Stottlemyer <bstottle@ford.com> | 2015-03-07 15:26:14 -0500 |
---|---|---|
committer | Brett Stottlemyer <bstottle@ford.com> | 2015-03-10 12:50:11 +0000 |
commit | 2f579c53f41985f4bdb52011b9c51c82f12a24bb (patch) | |
tree | f3f331b1cfabb5842ea0d9232d163752a7fe437e /src/remoteobjects/qremoteobjectregistry.cpp | |
parent | a543216863645e360c85ba1a799291c075fa9632 (diff) |
Enhance Registry
This adds support for creating the Registry Host whenever, it no longer
needs to be created before Registry Replicas are used. It also provides
warnings if a Source is enabled that is already in the Registry.
To support consistency, connections are only made when the Registry is
valid. This prevents the edge case of a locally hosted source getting
connected to and then having a duplicate in the Registry when it connects.
Change-Id: Iffc21a41a72edf5e3c3b4e80d6de23d0b85c4d49
Reviewed-by: Björn Breitmeyer <bjoern.breitmeyer@kdab.com>
Diffstat (limited to 'src/remoteobjects/qremoteobjectregistry.cpp')
-rw-r--r-- | src/remoteobjects/qremoteobjectregistry.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/remoteobjects/qremoteobjectregistry.cpp b/src/remoteobjects/qremoteobjectregistry.cpp index 3cadd97..4aeb409 100644 --- a/src/remoteobjects/qremoteobjectregistry.cpp +++ b/src/remoteobjects/qremoteobjectregistry.cpp @@ -42,11 +42,14 @@ #include "qremoteobjectregistry.h" #include "qremoteobjectreplica_p.h" +#include <QSet> + QT_BEGIN_NAMESPACE QRemoteObjectRegistry::QRemoteObjectRegistry(QObject *parent) : QRemoteObjectReplica(parent) { + connect(this, &QRemoteObjectRegistry::isReplicaValidChanged, this, &QRemoteObjectRegistry::pushToRegistryIfNeeded); } QRemoteObjectRegistry::~QRemoteObjectRegistry() @@ -73,10 +76,20 @@ QRemoteObjectSourceLocations QRemoteObjectRegistry::sourceLocations() const void QRemoteObjectRegistry::addSource(const QRemoteObjectSourceLocation &entry) { - if (!isInitialized()) { - bool res = waitForSource(); - if (!res) - return; //FIX What to do here? + if (hostedSources.contains(entry.first)) { + qCWarning(QT_REMOTEOBJECT) << "Node warning: Ignoring Source" << entry.first + << "as this Node already has a Source by that name."; + return; + } + hostedSources.insert(entry.first, entry.second); + if (!isReplicaValid()) { + return; + } + if (sourceLocations().contains(entry.first)) { + qCWarning(QT_REMOTEOBJECT) << "Node warning: Ignoring Source" << entry.first + << "as another source (" << sourceLocations()[entry.first] + << ") has already registered that name."; + return; } qCDebug(QT_REMOTEOBJECT) << "An entry was added to the registry - Sending to Source" << entry.first << entry.second; // This does not set any data to avoid a coherency problem between client and server @@ -88,10 +101,11 @@ void QRemoteObjectRegistry::addSource(const QRemoteObjectSourceLocation &entry) void QRemoteObjectRegistry::removeSource(const QRemoteObjectSourceLocation &entry) { - if (!isInitialized()) { - bool res = waitForSource(); - if (!res) - return; //FIX What to do here? + if (!hostedSources.contains(entry.first)) + return; + hostedSources.remove(entry.first); + if (!isReplicaValid()) { + return; } qCDebug(QT_REMOTEOBJECT) << "An entry was removed from the registry - Sending to Source" << entry.first << entry.second; // This does not set any data to avoid a coherency problem between client and server @@ -101,4 +115,27 @@ void QRemoteObjectRegistry::removeSource(const QRemoteObjectSourceLocation &entr send(QMetaObject::InvokeMetaMethod, index, args); } +void QRemoteObjectRegistry::pushToRegistryIfNeeded() +{ + if (!isReplicaValid()) + return; + const QSet<QString> myLocs = QSet<QString>::fromList(hostedSources.keys()); + if (myLocs.empty()) + return; + const QSet<QString> registryLocs = QSet<QString>::fromList(sourceLocations().keys()); + foreach (const QString &loc, myLocs & registryLocs) { + qCWarning(QT_REMOTEOBJECT) << "Node warning: Ignoring Source" << loc << "as another source (" + << sourceLocations()[loc] << ") has already registered that name."; + hostedSources.remove(loc); + return; + } + //Sources that need to be pushed to the registry... + foreach (const QString &loc, myLocs - registryLocs) { + static int index = QRemoteObjectRegistry::staticMetaObject.indexOfMethod("addSource(QRemoteObjectSourceLocation)"); + QVariantList args; + args << QVariant::fromValue(QRemoteObjectSourceLocation(loc, hostedSources[loc])); + send(QMetaObject::InvokeMetaMethod, index, args); + } +} + QT_END_NAMESPACE |