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

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