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:declarations-only
4
5#ifndef QREMOTEOBJECTSOURCEIO_P_H
6#define QREMOTEOBJECTSOURCEIO_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qconnectionfactories_p.h"
20#include "qtremoteobjectglobal.h"
21#include "qremoteobjectpacket_p.h"
22
23#include <QtCore/qiodevice.h>
24#include <QtCore/qscopedpointer.h>
25#include <QtNetwork/qlocalserver.h>
26
27QT_BEGIN_NAMESPACE
28
29class QRemoteObjectSourceBase;
30class QRemoteObjectRootSource;
31class SourceApiMap;
32class QRemoteObjectHostBase;
33
34class QRemoteObjectSourceIo : public QObject
35{
36 Q_OBJECT
37public:
38 explicit QRemoteObjectSourceIo(const QUrl &address, QObject *parent = nullptr);
39 explicit QRemoteObjectSourceIo(QObject *parent = nullptr);
40 ~QRemoteObjectSourceIo() override;
41
42 bool startListening();
43 bool enableRemoting(QObject *object, const QMetaObject *meta, const QString &name,
44 const QString &typeName);
45 bool enableRemoting(QObject *object, const SourceApiMap *api, QObject *adapter = nullptr);
46 bool disableRemoting(QObject *object);
47 void newConnection(QtROIoDeviceBase *conn);
48 void setSocketOptions(QLocalServer::SocketOptions options);
49
50 QUrl serverAddress() const;
51
52public Q_SLOTS:
53 void handleConnection();
54 void onServerDisconnect(QObject *obj = nullptr);
55 void onServerRead(QObject *obj);
56
57Q_SIGNALS:
58 void remoteObjectAdded(const QRemoteObjectSourceLocation &);
59 void remoteObjectRemoved(const QRemoteObjectSourceLocation &);
60 void serverRemoved(const QUrl& url);
61
62public:
63 void registerSource(QRemoteObjectSourceBase *source);
64 void unregisterSource(QRemoteObjectSourceBase *source);
65
66 QHash<QIODevice*, quint32> m_readSize;
67 QSet<QtROIoDeviceBase*> m_connections;
68 QHash<QObject *, QRemoteObjectRootSource*> m_objectToSourceMap;
69 QMap<QString, QRemoteObjectSourceBase*> m_sourceObjects;
70 QMap<QString, QRemoteObjectRootSource*> m_sourceRoots;
71 QHash<QtROIoDeviceBase*, QUrl> m_registryMapping;
72 QScopedPointer<QConnectionAbstractServer> m_server;
73 // TODO should have some sort of manager for the codec
74 QScopedPointer<QRemoteObjectPackets::CodecBase> m_codec{new QRemoteObjectPackets::QDataStreamCodec};
75 QString m_rxName;
76 QVariantList m_rxArgs;
77 QUrl m_address;
78};
79
80QT_END_NAMESPACE
81
82#endif
83

source code of qtremoteobjects/src/remoteobjects/qremoteobjectsourceio_p.h