Skip to content

Commit 00fee50

Browse files
committed
nodepp V1.4.0_5
1 parent 5876f03 commit 00fee50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1983
-1002
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
image.jpg
22
main.exe
33
build
4-
main
4+
main
5+
www
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(Isolated_Modules_System CXX)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
find_package(Threads REQUIRED)
9+
find_package(OpenSSL REQUIRED)
10+
find_package(ZLIB REQUIRED)
11+
12+
set(NODEPP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../include")
13+
14+
add_library(Modules_Lib SHARED
15+
module1.cpp
16+
module2.cpp
17+
)
18+
19+
target_include_directories(Modules_Lib PRIVATE
20+
${NODEPP_INCLUDE_DIR}
21+
${CMAKE_CURRENT_SOURCE_DIR}
22+
)
23+
24+
add_executable(main main.cpp)
25+
26+
target_link_libraries(main PRIVATE
27+
Modules_Lib
28+
Threads::Threads
29+
OpenSSL::SSL
30+
OpenSSL::Crypto
31+
ZLIB::ZLIB
32+
)
33+
34+
target_include_directories(main PRIVATE
35+
${NODEPP_INCLUDE_DIR}
36+
${CMAKE_CURRENT_SOURCE_DIR}
37+
)
38+
39+
target_compile_options(main PRIVATE -fpermissive)
40+
target_compile_options(Modules_Lib PRIVATE -fpermissive)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mkdir -p build
2+
3+
if [ ! -d "./build/_deps" ]; then
4+
( cd build ; cmake .. )
5+
fi
6+
7+
( cd build ; make )
8+
9+
if [ ! $? -eq 0 ]; then
10+
echo "exit error"; exit;
11+
fi
12+
13+
./build/main
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
3+
#include <nodepp/channel.h>
4+
#include <nodepp/encoder.h>
5+
6+
using namespace nodepp;
7+
8+
#include "module1.h"
9+
#include "module2.h"
10+
11+
void onMain(){
12+
13+
pair_t<worker_t,channel_t<coroutine_t>> module2 = module_2_start();
14+
pair_t<worker_t,channel_t<coroutine_t>> module1 = module_1_start();
15+
16+
module2.second.write( coroutine_t( COROUTINE(){
17+
coBegin
18+
19+
while( true ){
20+
console::log( "hello from module 2" );
21+
coDelay(100); }
22+
23+
coFinish
24+
}));
25+
26+
module1.second.write( coroutine_t( COROUTINE(){
27+
coBegin
28+
29+
while( true ){
30+
console::log( "hello from module 1" );
31+
coDelay(300); }
32+
33+
coFinish
34+
}));
35+
36+
process::add( coroutine::add( COROUTINE(){
37+
coBegin
38+
39+
while( true ){
40+
console::log( "<---------------->" );
41+
console::log( "<2>", module2.first.is_closed() );
42+
console::log( "<2>", module1.first.is_closed() );
43+
coDelay(1000); }
44+
45+
coFinish
46+
}));
47+
48+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
3+
#include <nodepp/channel.h>
4+
5+
using namespace nodepp;
6+
7+
#include "module1.h"
8+
9+
pair_t<worker_t,channel_t<coroutine_t>> module_1_start(){
10+
11+
channel_t<coroutine_t> chn;
12+
13+
return { worker::add( coroutine::add( COROUTINE(){
14+
coBegin
15+
16+
while( true ){
17+
if ( !chn.empty() ){
18+
for ( auto &x: chn.read() ){ process::add( x ); }}
19+
if ( process::size() == 0 ){ coDelay(1000); } process::next(); }
20+
21+
coFinish
22+
}) ), chn };
23+
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MODULE_H_1
2+
#define MODULE_H_1
3+
4+
pair_t<worker_t,channel_t<coroutine_t>> module_1_start();
5+
6+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
3+
#include <nodepp/channel.h>
4+
5+
using namespace nodepp;
6+
7+
#include "module2.h"
8+
9+
pair_t<worker_t,channel_t<coroutine_t>> module_2_start(){
10+
11+
channel_t<coroutine_t> chn;
12+
13+
return { worker::add( coroutine::add( COROUTINE(){
14+
coBegin
15+
16+
while( true ){
17+
if ( !chn.empty() ){
18+
for ( auto &x: chn.read() ){ process::add( x ); }}
19+
if ( process::size() == 0 ){ coDelay(1000); } process::next(); }
20+
21+
coFinish
22+
}) ), chn };
23+
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MODULE_H_2
2+
#define MODULE_H_2
3+
4+
pair_t<worker_t,channel_t<coroutine_t>> module_2_start();
5+
6+
#endif

examples/0-stl_interop.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/event.h>
3+
4+
#include <string>
5+
#include <queue>
6+
#include <vector>
7+
#include <functional>
8+
9+
using namespace nodepp;
10+
11+
void onMain(){
12+
13+
ptr_t<int> ptr ( 0UL, 10 ); // as value
14+
// ptr_t<int> ptr ( 1UL, 10 ); // as buffer
15+
16+
std::function<void(int)> clb ([=]( int value ){
17+
console::log( value, *ptr );
18+
});
19+
20+
event_t<int> ev; ev.once( clb );
21+
ev.emit( 100 );
22+
23+
std::string str = "hello world";
24+
console::log( ">>", str );
25+
26+
std::vector<int> arr ({ 10, 20, 30, 40, 50 });
27+
console::log( ">>", array_t<int>( arr ).join() );
28+
29+
std::queue<int> st ({ 10, 20, 30, 40 });
30+
queue_t<int> que ( st );
31+
que.map([=]( int value ){ console::log( "<>", value ); });
32+
33+
}

examples/15-TCP.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/tcp.h>
34
#include <nodepp/fs.h>
45

@@ -74,9 +75,12 @@ void client(){
7475

7576
void onMain() {
7677

77-
if( process::env::get("mode")=="client" )
78-
{ client(); } else { server(); }
78+
worker::add( coroutine::add( COROUTINE(){
79+
coBegin /*--*/ ; server();
80+
process::wait(); coFinish }));
7981

80-
}
82+
worker::add( coroutine::add( COROUTINE(){
83+
coBegin /*--*/ ; client();
84+
process::wait(); coFinish }));
8185

82-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
86+
}

0 commit comments

Comments
 (0)