Navigator2Go  2.0
Manage your local Ocean Navigator installation.
network.h
1 #ifndef NETWORK_H
2 #define NETWORK_H
3 
4 #include <QString>
5 #include <QJsonDocument>
6 #include <QNetworkAccessManager>
7 #include <QRunnable>
8 
9 #include <functional>
10 
11 namespace Network {
12 
13 /***********************************************************************************/
14 // Makes a GET request to a given API URL (usually Dory in our case), and handles
15 // error-checking. The given replyHandler is invoked on success.
16 void MakeAPIRequest(QNetworkAccessManager& nam,
17  const QString& APIURL,
18  std::function<void(QJsonDocument)>&& replyHandler,
19  std::function<void()>&& errorHandler = nullptr
20  );
21 
22 /***********************************************************************************/
24 
25 class URLExistsRunnable : public QObject, public QRunnable {
26  Q_OBJECT
27 public:
28  URLExistsRunnable(const QString& urlString, const quint16 port);
29 
30  void run() override;
31 
32 signals:
33  void urlResult(const bool success);
34 
35 private:
36  const QUrl m_url;
37  const quint16 m_port;
38 };
39 
40 } // namespace Network
41 
42 #endif // NETWORK_H
Queries a remote url on a given port.
Definition: network.h:25
Definition: network.cpp:9