|
| 1 | +#ifndef QTDATASYNC_REMOTECONFIG_H |
| 2 | +#define QTDATASYNC_REMOTECONFIG_H |
| 3 | + |
| 4 | +#include <QtCore/qobject.h> |
| 5 | +#include <QtCore/qurl.h> |
| 6 | +#include <QtCore/qhash.h> |
| 7 | +#include <QtCore/qshareddata.h> |
| 8 | + |
| 9 | +#include "QtDataSync/qtdatasync_global.h" |
| 10 | + |
| 11 | +namespace QtDataSync { |
| 12 | + |
| 13 | +class RemoteConfigPrivate; |
| 14 | +//! A configuration on how to connect to a remote server |
| 15 | +class Q_DATASYNC_EXPORT RemoteConfig |
| 16 | +{ |
| 17 | + Q_GADGET |
| 18 | + |
| 19 | + //! The websocket url of the server to connect to |
| 20 | + Q_PROPERTY(QUrl url READ url WRITE setUrl) |
| 21 | + //! A access secret needed in order to connect to the server |
| 22 | + Q_PROPERTY(QString accessKey READ accessKey WRITE setAccessKey) |
| 23 | + //! A collection of additional HTTP headers to be sent with the request |
| 24 | + Q_PROPERTY(HeaderHash headers READ headers WRITE setHeaders) |
| 25 | + //! The keep alive timeout to be used to send pings to the server |
| 26 | + Q_PROPERTY(int keepaliveTimeout READ keepaliveTimeout WRITE setKeepaliveTimeout) |
| 27 | + |
| 28 | +public: |
| 29 | + //! Typedef for a hash of additional HTTP headers |
| 30 | + typedef QHash<QByteArray, QByteArray> HeaderHash; |
| 31 | + |
| 32 | + //! Default constructor, with optional parameters |
| 33 | + RemoteConfig(const QUrl &url = {}, |
| 34 | + const QString &accessKey = {}, |
| 35 | + const HeaderHash &headers = {}, |
| 36 | + int keepaliveTimeout = 1); //1 minute between ping messages (nginx timeout is 75 seconds be default) |
| 37 | + //! Copy constructor |
| 38 | + RemoteConfig(const RemoteConfig &other); |
| 39 | + ~RemoteConfig(); |
| 40 | + |
| 41 | + //! Assignment operator |
| 42 | + RemoteConfig &operator=(const RemoteConfig &other); |
| 43 | + |
| 44 | + //! @readAcFn{RemoteConfig::url} |
| 45 | + QUrl url() const; |
| 46 | + //! @readAcFn{RemoteConfig::accessKey} |
| 47 | + QString accessKey() const; |
| 48 | + //! @readAcFn{RemoteConfig::headers} |
| 49 | + HeaderHash headers() const; |
| 50 | + //! @readAcFn{RemoteConfig::keepaliveTimeout} |
| 51 | + int keepaliveTimeout() const; |
| 52 | + |
| 53 | + //! @writeAcFn{RemoteConfig::url} |
| 54 | + void setUrl(QUrl url); |
| 55 | + //! @writeAcFn{RemoteConfig::accessKey} |
| 56 | + void setAccessKey(QString accessKey); |
| 57 | + //! @writeAcFn{RemoteConfig::headers} |
| 58 | + void setHeaders(HeaderHash headers); |
| 59 | + //! @writeAcFn{RemoteConfig::keepaliveTimeout} |
| 60 | + void setKeepaliveTimeout(int keepaliveTimeout); |
| 61 | + |
| 62 | +private: |
| 63 | + QSharedDataPointer<RemoteConfigPrivate> d; |
| 64 | + |
| 65 | + friend Q_DATASYNC_EXPORT QDataStream &operator<<(QDataStream &stream, const RemoteConfig &deviceInfo); |
| 66 | + friend Q_DATASYNC_EXPORT QDataStream &operator>>(QDataStream &stream, RemoteConfig &deviceInfo); |
| 67 | +}; |
| 68 | + |
| 69 | +//! Stream operator to stream into a QDataStream |
| 70 | +Q_DATASYNC_EXPORT QDataStream &operator<<(QDataStream &stream, const RemoteConfig &deviceInfo); |
| 71 | +//! Stream operator to stream out of a QDataStream |
| 72 | +Q_DATASYNC_EXPORT QDataStream &operator>>(QDataStream &stream, RemoteConfig &deviceInfo); |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +Q_DECLARE_METATYPE(QtDataSync::RemoteConfig) |
| 77 | +Q_DECLARE_TYPEINFO(QtDataSync::RemoteConfig, Q_MOVABLE_TYPE); |
| 78 | + |
| 79 | + |
| 80 | +#endif // QTDATASYNC_REMOTECONFIG_H |
0 commit comments