##// END OF EJS Templates
Add execute skelleton Network
perrinel -
r386:be6d704a1f9a
parent child
Show More
@@ -1,153 +1,153
1
1
2 ## core - CMakeLists.txt
2 ## core - CMakeLists.txt
3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
4 SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}")
4 SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}")
5 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/")
5 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/")
6 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
6 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
7
7
8 # Include core directory
8 # Include core directory
9 include_directories("${INCLUDES_DIR}")
9 include_directories("${INCLUDES_DIR}")
10
10
11 # Set a variable to display a warning in the version files.
11 # Set a variable to display a warning in the version files.
12 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
12 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
13 # Generate the version file from the cmake version variables. The version
13 # Generate the version file from the cmake version variables. The version
14 # variables are defined in the cmake/sciqlop_version.cmake file.
14 # variables are defined in the cmake/sciqlop_version.cmake file.
15 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in"
15 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in"
16 "${INCLUDES_DIR}/Version.h")
16 "${INCLUDES_DIR}/Version.h")
17 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in"
17 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in"
18 "${SOURCES_DIR}/Version.cpp")
18 "${SOURCES_DIR}/Version.cpp")
19
19
20 # Find dependent modules
20 # Find dependent modules
21 find_package(sciqlop-plugin)
21 find_package(sciqlop-plugin)
22 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
22 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
23
23
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
31 #
31 #
32 FILE (GLOB_RECURSE MODULE_SOURCES
32 FILE (GLOB_RECURSE MODULE_SOURCES
33 ${INCLUDES_DIR}/*.h
33 ${INCLUDES_DIR}/*.h
34 ${SOURCES_DIR}/*.c
34 ${SOURCES_DIR}/*.c
35 ${SOURCES_DIR}/*.cpp
35 ${SOURCES_DIR}/*.cpp
36 ${SOURCES_DIR}/*.h)
36 ${SOURCES_DIR}/*.h)
37
37
38 ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES})
38 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}
46 LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
46 LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
47 ARCHIVE DESTINATION ${INSTALL_LIBRARY_DIR}
47 ARCHIVE DESTINATION ${INSTALL_LIBRARY_DIR}
48 )
48 )
49
49
50 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
50 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
51 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
51 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
52 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
52 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
53 IF(BUILD_SHARED_LIBS)
53 IF(BUILD_SHARED_LIBS)
54 SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
54 SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
55 ELSE()
55 ELSE()
56 TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
56 TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
57 ENDIF()
57 ENDIF()
58
58
59 # Set the variable to parent scope so that the other projects can copy the
59 # Set the variable to parent scope so that the other projects can copy the
60 # dependent shared libraries
60 # dependent shared libraries
61 SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME)
61 SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME)
62
62
63 # Copy extern shared libraries to the lib folder
63 # Copy extern shared libraries to the lib folder
64 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
64 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
65
65
66 # Add the files to the list of files to be analyzed
66 # Add the files to the list of files to be analyzed
67 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
67 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
68 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
68 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
69 # Vera++ exclusion files
69 # Vera++ exclusion files
70 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
70 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
71 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
71 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
72
72
73 #
73 #
74 # Compile the tests
74 # Compile the tests
75 #
75 #
76 IF(BUILD_TESTS)
76 IF(BUILD_TESTS)
77 INCLUDE_DIRECTORIES(${SOURCES_DIR})
77 INCLUDE_DIRECTORIES(${SOURCES_DIR})
78 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
78 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
79 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
79 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
80 SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME})
80 SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME})
81
81
82 SET(TARGETS_COV)
82 SET(TARGETS_COV)
83 FOREACH( testFile ${TESTS_SOURCES} )
83 FOREACH( testFile ${TESTS_SOURCES} )
84 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
84 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
85 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
85 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
86
86
87 # Add to the list of sources files all the sources in the same
87 # Add to the list of sources files all the sources in the same
88 # directory that aren't another test
88 # directory that aren't another test
89 FILE (GLOB currentTestSources
89 FILE (GLOB currentTestSources
90 ${testDirectory}/*.c
90 ${testDirectory}/*.c
91 ${testDirectory}/*.cpp
91 ${testDirectory}/*.cpp
92 ${testDirectory}/*.h)
92 ${testDirectory}/*.h)
93 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
93 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
94 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
94 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
95
95
96 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
96 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
97 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
97 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
98 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
98 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
99 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
99 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
100 qt5_use_modules(${testName} Test)
100 qt5_use_modules(${testName} Test)
101
101
102 ADD_TEST( NAME ${testName} COMMAND ${testName} )
102 ADD_TEST( NAME ${testName} COMMAND ${testName} )
103
103
104 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
104 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
105 set(Coverage_NAME ${testName})
105 set(Coverage_NAME ${testName})
106 if(UNIX)
106 if(UNIX)
107 SETUP_TARGET_FOR_COVERAGE(TARGET ${testName}_coverage OUTPUT ${testFile}-path NAME ${testFile} EXECUTABLE ${testName})
107 SETUP_TARGET_FOR_COVERAGE(TARGET ${testName}_coverage OUTPUT ${testFile}-path NAME ${testFile} EXECUTABLE ${testName})
108 LIST( APPEND TARGETS_COV ${testName}_coverage)
108 LIST( APPEND TARGETS_COV ${testName}_coverage)
109 endif(UNIX)
109 endif(UNIX)
110
110
111 ENDFOREACH( testFile )
111 ENDFOREACH( testFile )
112
112
113 add_custom_target(coverage)
113 add_custom_target(coverage)
114
114
115 FOREACH( target_cov ${TARGETS_COV} )
115 FOREACH( target_cov ${TARGETS_COV} )
116 add_custom_command(TARGET coverage PRE_BUILD COMMAND make ${target_cov})
116 add_custom_command(TARGET coverage PRE_BUILD COMMAND make ${target_cov})
117 ENDFOREACH( target_cov )
117 ENDFOREACH( target_cov )
118
118
119 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
119 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
120 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
120 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
121 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
121 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
122 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
122 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
123 ENDIF(BUILD_TESTS)
123 ENDIF(BUILD_TESTS)
124
124
125 #
125 #
126 # Set the files that must be formatted by clang-format.
126 # Set the files that must be formatted by clang-format.
127 #
127 #
128 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
128 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
129 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
129 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
130
130
131 #
131 #
132 # Set the directories that doxygen must browse to generate the
132 # Set the directories that doxygen must browse to generate the
133 # documentation.
133 # documentation.
134 #
134 #
135 # Source directories:
135 # Source directories:
136 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
136 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
137 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
137 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
138 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
138 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
139 # Source directories to exclude from the documentation generation
139 # Source directories to exclude from the documentation generation
140 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
140 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
141 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
141 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
142
142
143 #
143 #
144 # Set the directories with the sources to analyze and propagate the
144 # Set the directories with the sources to analyze and propagate the
145 # modification to the parent scope
145 # modification to the parent scope
146 #
146 #
147 # Source directories to analyze:
147 # Source directories to analyze:
148 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
148 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
149 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
149 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
150 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
150 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
151 # Source directories to exclude from the analysis
151 # Source directories to exclude from the analysis
152 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
152 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
153 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
153 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,30 +1,37
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6
6
7 #include <Common/spimpl.h>
7 #include <Common/spimpl.h>
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 */
14 class NetworkController : public QObject {
16 class NetworkController : public QObject {
15 Q_OBJECT
17 Q_OBJECT
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
26 class NetworkControllerPrivate;
33 class NetworkControllerPrivate;
27 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
34 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
28 };
35 };
29
36
30 #endif // SCIQLOP_NETWORKCONTROLLER_H
37 #endif // SCIQLOP_NETWORKCONTROLLER_H
@@ -1,33 +1,53
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()
19 {
39 {
20 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
40 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
21 impl->m_WorkingMutex.lock();
41 impl->m_WorkingMutex.lock();
22 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
42 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
23 }
43 }
24
44
25 void NetworkController::finalize()
45 void NetworkController::finalize()
26 {
46 {
27 impl->m_WorkingMutex.unlock();
47 impl->m_WorkingMutex.unlock();
28 }
48 }
29
49
30 void NetworkController::waitForFinish()
50 void NetworkController::waitForFinish()
31 {
51 {
32 QMutexLocker locker{&impl->m_WorkingMutex};
52 QMutexLocker locker{&impl->m_WorkingMutex};
33 }
53 }
General Comments 0
You need to be logged in to leave comments. Login now