Skip to content

Commit bf13491

Browse files
committed
📌 Nodepp | Bugs Fixed | V1.4.1 📌
1 parent 5876f03 commit bf13491

Some content is hidden

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

101 files changed

+2104
-1146
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
/*-----*/
17+
18+
std::function<void(int)> clb ([=]( int value ){
19+
console::log( value, *ptr );
20+
});
21+
22+
/*-----*/
23+
24+
event_t<int> ev; ev.once( clb );
25+
ev.emit( 100 );
26+
27+
/*-----*/
28+
29+
std::string str = "hello world";
30+
console::log( ">>", str );
31+
32+
/*-----*/
33+
34+
std::vector<int> arr ({ 10, 20, 30, 40, 50 });
35+
console::log( ">>", array_t<int>( arr ).join() );
36+
37+
/*-----*/
38+
39+
std::queue<int> st ({ 10, 20, 30, 40 });
40+
queue_t<int> que ( st );
41+
que.map([=]( int value ){ console::log( "<>", value ); });
42+
43+
/*-----*/
44+
45+
std::string str2 = "hello world";
46+
ptr_t<std::string> ptr1 ( 0UL );
47+
*ptr1 = type::move( str2 );
48+
console::log( *ptr1 );
49+
50+
/*----*/
51+
52+
std::vector<int> vec ({ 10, 20, 30 });
53+
ptr_t<int> ptr2 ( 3UL );
54+
type::move( vec.begin(), vec.end(), ptr2.begin() );
55+
console::log( array_t<int>( ptr2 ).join() ); // <- cheap for the CPU
56+
57+
}

examples/0-zero-copy.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <nodepp/nodepp.h>
2+
3+
using namespace nodepp;
4+
5+
void onMain(){
6+
7+
ptr_t<char> ptr ( 13UL, 0x00 );
8+
memcpy( ptr.get(), "hello world!", 12 );
9+
10+
array_t<char> arr = ptr;
11+
string_t /**/ str = arr.ptr();
12+
13+
for( auto &x: str ){ x = string::to_upper( x ); }
14+
15+
console::log( "0>", arr.join( string::null() ) );
16+
console::log( "1>", ptr.get() );
17+
console::log( "2>", str );
18+
19+
}

0 commit comments

Comments
 (0)