This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathqtrotransportregistry.h
83 lines (59 loc) · 2.09 KB
/
qtrotransportregistry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef QTDATASYNC_QTROTRANSPORTREGISTRY_H
#define QTDATASYNC_QTROTRANSPORTREGISTRY_H
#include <type_traits>
#include <functional>
#include <QtCore/qurl.h>
#include <QtRemoteObjects/qremoteobjectnode.h>
#include "QtDataSync/qtdatasync_global.h"
namespace QtDataSync {
namespace QtRoTransportRegistry
{
class Q_DATASYNC_EXPORT Server
{
public:
virtual ~Server();
virtual bool prepareHostNode(const QUrl &url, QRemoteObjectHostBase *host) = 0;
};
class Q_DATASYNC_EXPORT Client
{
public:
virtual ~Client();
virtual bool prepareClientNode(const QUrl &url, QRemoteObjectNode *node) = 0;
};
Q_DATASYNC_EXPORT void registerTransport(const QString &urlScheme,
Server *server,
Client *client);
template <typename TFuncServer, typename TFuncClient>
void registerTransportFunctions(const QString &urlScheme, TFuncServer &&server, TFuncClient &&client);
Q_DATASYNC_EXPORT bool connectHostBaseNode(const QUrl &url, QRemoteObjectHostBase *node);
Q_DATASYNC_EXPORT void connectHostNode(const QUrl &url, QRemoteObjectHost *node);
Q_DATASYNC_EXPORT bool connectClientNode(const QUrl &url, QRemoteObjectNode *node);
// ------------- GENERIC IMPLEMENTATION -------------
namespace __private {
class Q_DATASYNC_EXPORT FuncServer : public Server
{
public:
FuncServer(std::function<bool(QUrl,QRemoteObjectHostBase*)> &&fn);
bool prepareHostNode(const QUrl &url, QRemoteObjectHostBase *host) override;
private:
std::function<bool(QUrl,QRemoteObjectHostBase*)> _fn;
};
class Q_DATASYNC_EXPORT FuncClient : public Client
{
public:
FuncClient(std::function<bool(QUrl,QRemoteObjectNode*)> &&fn);
bool prepareClientNode(const QUrl &url, QRemoteObjectNode *node) override;
private:
std::function<bool(QUrl,QRemoteObjectNode*)> _fn;
};
}
template <typename TFuncServer, typename TFuncClient>
void registerTransportFunctions(const QString &urlScheme, TFuncServer &&server, TFuncClient &&client)
{
registerTransport(urlScheme,
new __private::FuncServer{std::forward<TFuncServer>(server)},
new __private::FuncClient{std::forward<TFuncClient>(client)});
}
}
}
#endif // QTDATASYNC_QTROTRANSPORTREGISTRY_H