-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #553 from XxChang/update_dora_new
Update dora new
- Loading branch information
Showing
25 changed files
with
701 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
project(cxx-dataflow LANGUAGES C) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_FLAGS "-fPIC") | ||
|
||
set(DORA_ROOT_DIR "__DORA_PATH__" CACHE FILEPATH "Path to the root of dora") | ||
|
||
set(dora_c_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/c") | ||
if(DORA_ROOT_DIR) | ||
include(ExternalProject) | ||
ExternalProject_Add(Dora | ||
SOURCE_DIR ${DORA_ROOT_DIR} | ||
BUILD_IN_SOURCE True | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND | ||
cargo build | ||
--package dora-node-api-c | ||
INSTALL_COMMAND "" | ||
) | ||
|
||
add_custom_command(OUTPUT ${dora_c_include_dir} | ||
WORKING_DIRECTORY ${DORA_ROOT_DIR} | ||
DEPENDS Dora | ||
COMMAND | ||
mkdir ${CMAKE_CURRENT_BINARY_DIR}/include/c -p | ||
&& | ||
cp apis/c/node ${CMAKE_CURRENT_BINARY_DIR}/include/c -r | ||
) | ||
|
||
add_custom_target(Dora_c DEPENDS ${dora_c_include_dir}) | ||
set(dora_link_dirs ${DORA_ROOT_DIR}/target/debug) | ||
else() | ||
include(ExternalProject) | ||
ExternalProject_Add(Dora | ||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dora | ||
GIT_REPOSITORY https://github.com/dora-rs/dora.git | ||
GIT_TAG main | ||
BUILD_IN_SOURCE True | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND | ||
cargo build | ||
--package dora-node-api-c | ||
--target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target | ||
INSTALL_COMMAND "" | ||
) | ||
|
||
add_custom_command(OUTPUT ${dora_c_include_dir} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target | ||
DEPENDS Dora | ||
COMMAND | ||
mkdir ${CMAKE_CURRENT_BINARY_DIR}/include/c -p | ||
&& | ||
cp ../apis/c/node ${CMAKE_CURRENT_BINARY_DIR}/include/c -r | ||
) | ||
|
||
set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target/debug) | ||
|
||
add_custom_target(Dora_c DEPENDS ${dora_c_include_dir}) | ||
endif() | ||
|
||
link_directories(${dora_link_dirs}) | ||
|
||
add_executable(talker_1 talker_1/node.c) | ||
add_dependencies(talker_1 Dora_c) | ||
target_include_directories(talker_1 PRIVATE ${dora_c_include_dir}) | ||
target_link_libraries(talker_1 dora_node_api_c m) | ||
|
||
add_executable(talker_2 talker_2/node.c) | ||
add_dependencies(talker_2 Dora_c) | ||
target_include_directories(talker_2 PRIVATE ${dora_c_include_dir}) | ||
target_link_libraries(talker_2 dora_node_api_c m) | ||
|
||
add_executable(listener_1 listener_1/node.c) | ||
add_dependencies(listener_1 Dora_c) | ||
target_include_directories(listener_1 PRIVATE ${dora_c_include_dir}) | ||
target_link_libraries(listener_1 dora_node_api_c m) | ||
|
||
install(TARGETS listener_1 talker_1 talker_2 DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
nodes: | ||
- id: op_1 | ||
operator: | ||
shared-library: build/op_1 | ||
- id: talker_1 | ||
custom: | ||
source: bin/talker_1 | ||
inputs: | ||
foo: dora/timer/millis/100 | ||
tick: dora/timer/millis/100 | ||
outputs: | ||
- bar | ||
- id: op_2 | ||
operator: | ||
shared-library: build/op_2 | ||
- speech | ||
- id: talker_2 | ||
custom: | ||
source: bin/talker_2 | ||
inputs: | ||
foo: dora/timer/secs/2 | ||
tick: dora/timer/secs/2 | ||
outputs: | ||
- bar | ||
- speech | ||
|
||
- id: custom-node_1 | ||
- id: listener_1 | ||
custom: | ||
source: build/node_1 | ||
source: bin/listener_1 | ||
inputs: | ||
input-1: op_1/bar | ||
input-2: op_2/bar | ||
outputs: | ||
- foo | ||
speech-1: talker_1/speech | ||
speech-2: talker_2/speech |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
#include "node_api.h" | ||
|
||
// sleep | ||
#ifdef _WIN32 | ||
#include <Windows.h> | ||
#else | ||
#include <unistd.h> | ||
#endif | ||
|
||
int main() | ||
{ | ||
void *dora_context = init_dora_context_from_env(); | ||
if (dora_context == NULL) | ||
{ | ||
fprintf(stderr, "[c node] init dora context failed\n"); | ||
return -1; | ||
} | ||
|
||
printf("[c node] dora context initialized\n"); | ||
|
||
for (char i = 0; i < 20; i++) | ||
{ | ||
void *event = dora_next_event(dora_context); | ||
if (event == NULL) | ||
{ | ||
printf("[c node] ERROR: unexpected end of event\n"); | ||
return -1; | ||
} | ||
|
||
enum DoraEventType ty = read_dora_event_type(event); | ||
|
||
if (ty == DoraEventType_Input) | ||
{ | ||
char *id_ptr; | ||
size_t id_len; | ||
read_dora_input_id(event, &id_ptr, &id_len); | ||
|
||
char *data_ptr; | ||
size_t data_len; | ||
read_dora_input_data(event, &data_ptr, &data_len); | ||
|
||
printf("I heard %s from %s\n", data_ptr, id_ptr); | ||
} | ||
else if (ty == DoraEventType_Stop) | ||
{ | ||
printf("[c node] received stop event\n"); | ||
free_dora_event(event); | ||
break; | ||
} | ||
else if (ty == DoraEventType_InputClosed) { | ||
printf("[c node] received input closed event\n"); | ||
} | ||
else | ||
{ | ||
printf("[c node] received unexpected event: %d\n", ty); | ||
free_dora_event(event); | ||
break; | ||
} | ||
|
||
free_dora_event(event); | ||
} | ||
|
||
free_dora_context(dora_context); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.