##// END OF EJS Templates
Add execute skelleton Network
perrinel -
r386:be6d704a1f9a
parent child
Show More
@@ -24,7 +24,7 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
24 #
24 #
25 # Find Qt modules
25 # Find Qt modules
26 #
26 #
27 SCIQLOP_FIND_QT(Core)
27 SCIQLOP_FIND_QT(Core Network)
28
28
29 #
29 #
30 # Compile the library library
30 # Compile the library library
@@ -39,7 +39,7 ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES})
39 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
39 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
40 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
40 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
41 TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME})
41 TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME})
42 qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core)
42 qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core Network)
43
43
44 INSTALL(TARGETS ${SQPCORE_LIBRARY_NAME}
44 INSTALL(TARGETS ${SQPCORE_LIBRARY_NAME}
45 RUNTIME DESTINATION ${INSTALL_BINARY_DIR}
45 RUNTIME DESTINATION ${INSTALL_BINARY_DIR}
@@ -8,6 +8,8
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
10
10
11 class QNetworkReply;
12
11 /**
13 /**
12 * @brief The NetworkController class aims to handle all network connection of SciQlop.
14 * @brief The NetworkController class aims to handle all network connection of SciQlop.
13 */
15 */
@@ -16,10 +18,15 class NetworkController : public QObject {
16 public:
18 public:
17 explicit NetworkController(QObject *parent = 0);
19 explicit NetworkController(QObject *parent = 0);
18
20
21 void execute(QNetworkReply *reply);
22
19
23
20 void initialize();
24 void initialize();
21 void finalize();
25 void finalize();
22
26
27 signals:
28 replyToRead();
29
23 private:
30 private:
24 void waitForFinish();
31 void waitForFinish();
25
32
@@ -1,18 +1,38
1 #include "Network/NetworkController.h"
1 #include "Network/NetworkController.h"
2
2
3 #include <QMutex>
3 #include <QMutex>
4 #include <QNetworkAccessManager>
5 #include <QNetworkReply>
4 #include <QThread>
6 #include <QThread>
5
7
6 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
8 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
7
9
8 struct NetworkController::NetworkControllerPrivate {
10 struct NetworkController::NetworkControllerPrivate {
9 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
11 explicit NetworkControllerPrivate(NetworkController *parent)
12 : m_WorkingMutex{}, m_AccessManager{std::make_unique<QNetworkAccessManager>()}
13 {
14 }
10 QMutex m_WorkingMutex;
15 QMutex m_WorkingMutex;
16
17 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
11 };
18 };
12
19
13 NetworkController::NetworkController(QObject *parent)
20 NetworkController::NetworkController(QObject *parent)
14 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
21 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
15 {
22 {
23
24 }
25
26 void NetworkController::execute(QNetworkReply *reply)
27 {
28 auto replyReadyToRead =[reply, this] () {
29 auto content = reply->readAll();
30
31 emit this->replyToRead();
32 };
33
34 connect(impl->m_Reply, &QNetworkReply::finished, this, replyReadyToRead);
35 connect(impl->m_Reply, &QNetworkReply::aboutToClose, this, replyReadyToRead);
16 }
36 }
17
37
18 void NetworkController::initialize()
38 void NetworkController::initialize()
General Comments 0
You need to be logged in to leave comments. Login now