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