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

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