Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project structure rearranged. #20

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 15 additions & 14 deletions CMakeLists.txt
Expand Up @@ -32,14 +32,26 @@ set(my_sources
)

if(PROMISE_BUILD_SHARED OR BUILD_SHARED_LIBS)
add_definitions(-DPROMISE_BUILD_SHARED)
target_compile_definitions(promise PUBLIC -DPROMISE_BUILD_SHARED)
add_library(promise SHARED ${my_sources} ${my_headers})
else()
add_library(promise STATIC ${my_sources} ${my_headers})
endif()

target_include_directories(promise PUBLIC include)

find_package(Boost)
if(NOT Boost_FOUND)
message(WARNING "Boost not found, so asio projects will not be compiled")
else()
target_include_directories(promise PUBLIC ${Boost_INCLUDE_DIRS})
if(UNIX)
target_link_libraries(promise PUBLIC pthread)
elseif(WIN32)
target_link_libraries(promise PUBLIC -lws2_32 -lmswsock)
endif()
endif()

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets)
if(NOT QT_FOUND)
Expand All @@ -50,7 +62,7 @@ else()
else()
add_library(promise_qt STATIC ./add_ons/qt/promise_qt.cpp ${my_headers})
endif()
target_link_libraries(promise_qt PRIVATE promise Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(promise_qt PUBLIC promise Qt${QT_VERSION_MAJOR}::Widgets)
endif()

if(PROMISE_BUILD_EXAMPLES)
Expand All @@ -71,19 +83,8 @@ if(PROMISE_BUILD_EXAMPLES)

add_executable(chain_defer_test ${my_headers} example/chain_defer_test.cpp)
target_link_libraries(chain_defer_test PRIVATE promise)

find_package(Boost)
if(NOT Boost_FOUND)
message(WARNING "Boost not found, so asio projects will not be compiled")
else()

include_directories(${Boost_INCLUDE_DIRS})
if (UNIX)
link_libraries(pthread)
endif (UNIX)

include_directories(. ./add_ons/asio)

if(Boost_FOUND)
add_executable(asio_benchmark_test ${my_headers} example/asio_benchmark_test.cpp)
target_compile_definitions(asio_benchmark_test PRIVATE BOOST_ALL_NO_LIB)
target_link_libraries(asio_benchmark_test PRIVATE promise)
Expand Down
2 changes: 1 addition & 1 deletion example/asio_benchmark_test.cpp
Expand Up @@ -33,7 +33,7 @@
#include <iostream>
#include <string>
#include <chrono>
#include "add_ons/asio/timer.hpp"
#include <promise-cpp/add_ons/asio/timer.hpp>

using namespace promise;
namespace chrono = std::chrono;
Expand Down
2 changes: 1 addition & 1 deletion example/asio_http_client.cpp
Expand Up @@ -34,7 +34,7 @@
#include <memory>
#include <string>
#include <regex>
#include "add_ons/asio/io.hpp"
#include <promise-cpp/add_ons/asio/io.hpp>

using namespace promise;
namespace asio = boost::asio;
Expand Down
2 changes: 1 addition & 1 deletion example/asio_http_server.cpp
Expand Up @@ -37,7 +37,7 @@
#include <vector>


#include "add_ons/asio/io.hpp"
#include <promise-cpp/add_ons/asio/io.hpp>

using namespace promise;

Expand Down
90 changes: 45 additions & 45 deletions example/asio_timer.cpp
Expand Up @@ -25,29 +25,29 @@
* THE SOFTWARE.
*/

#include "add_ons/asio/timer.hpp"
#include <stdio.h>
#include <boost/asio.hpp>
#include <promise-cpp/add_ons/asio/timer.hpp>
#include <stdio.h>
#include <boost/asio.hpp>

using namespace promise;
namespace asio = boost::asio;
Promise testTimer(asio::io_service &io) {
return delay(io, 3000).then([&] {
printf("timer after 3000 ms!\n");
return delay(io, 1000);
}).then([&] {
printf("timer after 1000 ms!\n");
return delay(io, 12000);
}).then([] {
printf("timer after 12000 ms!\n");
}).fail([] {
printf("timer cancelled!\n");
});
}
void testPromiseRace(asio::io_service &io) {
using namespace promise;
namespace asio = boost::asio;

Promise testTimer(asio::io_service &io) {

return delay(io, 3000).then([&] {
printf("timer after 3000 ms!\n");
return delay(io, 1000);
}).then([&] {
printf("timer after 1000 ms!\n");
return delay(io, 12000);
}).then([] {
printf("timer after 12000 ms!\n");
}).fail([] {
printf("timer cancelled!\n");
});
}

void testPromiseRace(asio::io_service &io) {
auto promise0 = delay(io, 10000).then([] {
printf("race: one resolved\n");
return "one";
Expand All @@ -60,10 +60,10 @@ void testPromiseRace(asio::io_service &io) {
race(promise0, promise1).then([](const char *str) {
printf("race result = %s\n", str);
// Both resolve, but promise1 is faster
});
}
void testPromiseAll(asio::io_service &io) {
});
}

void testPromiseAll(asio::io_service &io) {
auto promise0 = delay(io, 10000).then([] {
printf("all: one resolved\n");
return std::string("one");
Expand All @@ -80,22 +80,22 @@ void testPromiseAll(asio::io_service &io) {
results[i].cast<std::string>().c_str());
}
// Both resolve, but promise1 is faster
});
}
int main() {
asio::io_service io;
testPromiseRace(io);
testPromiseAll(io);
Promise timer = testTimer(io);
delay(io, 4500).then([=] {
printf("clearTimeout\n");
clearTimeout(timer);
});
io.run();
return 0;
}
});
}

int main() {
asio::io_service io;

testPromiseRace(io);
testPromiseAll(io);

Promise timer = testTimer(io);

delay(io, 4500).then([=] {
printf("clearTimeout\n");
clearTimeout(timer);
});

io.run();
return 0;
}
2 changes: 1 addition & 1 deletion example/chain_defer_test.cpp
@@ -1,4 +1,4 @@
#include "promise-cpp/promise.hpp"
#include <promise-cpp/promise.hpp>
#include <sstream>
#include <iostream>

Expand Down
12 changes: 6 additions & 6 deletions example/multithread_test.cpp
Expand Up @@ -24,14 +24,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


#include <stdio.h>
#include <iostream>
#include <string>
#include <chrono>
#include "promise-cpp/promise.hpp"
#include "add_ons/simple_task/simple_task.hpp"
#include <promise-cpp/promise.hpp>
#include <promise-cpp/add_ons/simple_task/simple_task.hpp>

using namespace promise;
namespace chrono = std::chrono;
Expand Down Expand Up @@ -64,8 +64,8 @@ void task(Service &io, int task_id, int count, int *pcoro, Defer defer) {


Promise test_switch(Service &io, int coro) {
steady_clock::time_point start = steady_clock::now();
steady_clock::time_point start = steady_clock::now();

int *pcoro = new int(coro);

return newPromise([=, &io](Defer &defer){
Expand Down
2 changes: 1 addition & 1 deletion example/qt_timer/mainwindow.h
Expand Up @@ -2,7 +2,7 @@
#define MAINWINDOW_H

#include <QMainWindow>
#include "add_ons/qt/promise_qt.hpp"
#include <promise-cpp/add_ons/qt/promise_qt.hpp>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
Expand Down
12 changes: 6 additions & 6 deletions example/simple_benchmark_test.cpp
Expand Up @@ -24,14 +24,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


#include <stdio.h>
#include <iostream>
#include <string>
#include <chrono>
#include "promise-cpp/promise.hpp"
#include "add_ons/simple_task/simple_task.hpp"
#include <promise-cpp/promise.hpp>
#include <promise-cpp/add_ons/simple_task/simple_task.hpp>

using namespace promise;
namespace chrono = std::chrono;
Expand Down Expand Up @@ -64,8 +64,8 @@ void task(Service &io, int task_id, int count, int *pcoro, Defer defer) {


Promise test_switch(Service &io, int coro) {
steady_clock::time_point start = steady_clock::now();
steady_clock::time_point start = steady_clock::now();

int *pcoro = new int(coro);

return newPromise([=, &io](Defer &defer){
Expand Down
4 changes: 2 additions & 2 deletions example/simple_timer.cpp
Expand Up @@ -30,8 +30,8 @@
#include <chrono>
#include <thread>
#include <utility>
#include "promise-cpp/promise.hpp"
#include "add_ons/simple_task/simple_task.hpp"
#include <promise-cpp/promise.hpp>
#include <promise-cpp/add_ons/simple_task/simple_task.hpp>

using namespace promise;

Expand Down