1// Copyright (C) 2017 Ford Motor Company
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qremoteobjectregistrysource_p.h"
5#include <QtCore/qdatastream.h>
6
7QT_BEGIN_NAMESPACE
8
9QRegistrySource::QRegistrySource(QObject *parent)
10 : QObject(parent)
11{
12}
13
14QRegistrySource::~QRegistrySource()
15{
16}
17
18QRemoteObjectSourceLocations QRegistrySource::sourceLocations() const
19{
20 qCDebug(QT_REMOTEOBJECT) << "sourceLocations property requested on RegistrySource" << m_sourceLocations;
21 return m_sourceLocations;
22}
23
24void QRegistrySource::removeServer(const QUrl &url)
25{
26 for (auto it = m_sourceLocations.begin(), end = m_sourceLocations.end(); it != end; /* erasing */) {
27 if (it.value().hostUrl == url)
28 it = m_sourceLocations.erase(it);
29 else
30 ++it;
31 }
32}
33
34void QRegistrySource::addSource(const QRemoteObjectSourceLocation &entry)
35{
36 qCDebug(QT_REMOTEOBJECT) << "An entry was added to the RegistrySource" << entry;
37 if (m_sourceLocations.contains(key: entry.first)) {
38 if (m_sourceLocations[entry.first].hostUrl == entry.second.hostUrl)
39 qCWarning(QT_REMOTEOBJECT) << "Node warning: Ignoring Source" << entry.first
40 << "as this Node already has a Source by that name.";
41 else
42 qCWarning(QT_REMOTEOBJECT) << "Node warning: Ignoring Source" << entry.first
43 << "as another source (" << m_sourceLocations[entry.first]
44 << ") has already registered that name.";
45 return;
46 }
47 m_sourceLocations[entry.first] = entry.second;
48 emit remoteObjectAdded(entry);
49}
50
51void QRegistrySource::removeSource(const QRemoteObjectSourceLocation &entry)
52{
53 if (m_sourceLocations.contains(key: entry.first) && m_sourceLocations[entry.first].hostUrl == entry.second.hostUrl) {
54 m_sourceLocations.remove(key: entry.first);
55 emit remoteObjectRemoved(entry);
56 }
57}
58
59QT_END_NAMESPACE
60

source code of qtremoteobjects/src/remoteobjects/qremoteobjectregistrysource.cpp