| @@ -10,26 +10,26 @@ nodes: | |||
| tick: dora/timer/millis/300 | |||
| outputs: | |||
| - counter | |||
| - id: cxx-node-c-api | |||
| custom: | |||
| source: build/node_c_api | |||
| inputs: | |||
| tick: dora/timer/millis/300 | |||
| outputs: | |||
| - counter | |||
| # - id: cxx-node-c-api | |||
| # custom: | |||
| # source: build/node_c_api | |||
| # inputs: | |||
| # tick: dora/timer/millis/300 | |||
| # outputs: | |||
| # - counter | |||
| - id: runtime-node | |||
| operators: | |||
| - id: operator-rust-api | |||
| shared-library: build/operator_rust_api | |||
| inputs: | |||
| counter_1: cxx-node-c-api/counter | |||
| counter_2: cxx-node-rust-api/counter | |||
| outputs: | |||
| - status | |||
| - id: operator-c-api | |||
| shared-library: build/operator_c_api | |||
| inputs: | |||
| op_status: runtime-node/operator-rust-api/status | |||
| outputs: | |||
| - half-status | |||
| # - id: runtime-node | |||
| # operators: | |||
| # - id: operator-rust-api | |||
| # shared-library: build/operator_rust_api | |||
| # inputs: | |||
| # counter_1: cxx-node-c-api/counter | |||
| # counter_2: cxx-node-rust-api/counter | |||
| # outputs: | |||
| # - status | |||
| # - id: operator-c-api | |||
| # shared-library: build/operator_c_api | |||
| # inputs: | |||
| # op_status: runtime-node/operator-rust-api/status | |||
| # outputs: | |||
| # - half-status | |||
| @@ -1,71 +0,0 @@ | |||
| extern "C" | |||
| { | |||
| #include "../../../apis/c/node/node_api.h" | |||
| } | |||
| #include <iostream> | |||
| #include <vector> | |||
| int run(void *dora_context) | |||
| { | |||
| unsigned char counter = 0; | |||
| for (int i = 0; i < 20; i++) | |||
| { | |||
| auto input = dora_next_input(dora_context); | |||
| if (input == NULL) | |||
| { | |||
| return 0; // end of input | |||
| } | |||
| counter += 1; | |||
| char *id_ptr; | |||
| size_t id_len; | |||
| read_dora_input_id(input, &id_ptr, &id_len); | |||
| std::string id(id_ptr, id_len); | |||
| char *data_ptr; | |||
| size_t data_len; | |||
| read_dora_input_data(input, &data_ptr, &data_len); | |||
| std::vector<unsigned char> data; | |||
| for (size_t i = 0; i < data_len; i++) | |||
| { | |||
| data.push_back(*(data_ptr + i)); | |||
| } | |||
| std::cout | |||
| << "Received input " | |||
| << " (counter: " << (unsigned int)counter << ") data: ["; | |||
| for (unsigned char &v : data) | |||
| { | |||
| std::cout << (unsigned int)v << ", "; | |||
| } | |||
| std::cout << "]" << std::endl; | |||
| free_dora_input(input); | |||
| std::vector<unsigned char> out_vec{counter}; | |||
| std::string out_id = "counter"; | |||
| int result = dora_send_output(dora_context, &out_id[0], out_id.length(), (char *)&counter, 1); | |||
| if (result != 0) | |||
| { | |||
| std::cerr << "failed to send output" << std::endl; | |||
| return 1; | |||
| } | |||
| } | |||
| return 0; | |||
| } | |||
| int main() | |||
| { | |||
| std::cout << "HELLO FROM C++ (using C API)" << std::endl; | |||
| auto dora_context = init_dora_context_from_env(); | |||
| auto ret = run(dora_context); | |||
| free_dora_context(dora_context); | |||
| return ret; | |||
| } | |||
| @@ -13,22 +13,34 @@ int main() | |||
| for (int i = 0; i < 20; i++) | |||
| { | |||
| auto input = next_input(dora_node.inputs); | |||
| if (input.end_of_input) | |||
| auto event = next_event(dora_node.events); | |||
| auto ty = event_type(event); | |||
| if (ty == DoraEventType::AllInputsClosed) | |||
| { | |||
| break; | |||
| } | |||
| counter += 1; | |||
| else if (ty == DoraEventType::Input) | |||
| { | |||
| auto input = event_as_input(std::move(event)); | |||
| std::cout << "Received input " << std::string(input.id) << " (counter: " << (unsigned int)counter << ")" << std::endl; | |||
| counter += 1; | |||
| std::vector<unsigned char> out_vec{counter}; | |||
| rust::Slice<const uint8_t> out_slice{out_vec.data(), out_vec.size()}; | |||
| auto result = send_output(dora_node.send_output, "counter", out_slice); | |||
| auto error = std::string(result.error); | |||
| if (!error.empty()) | |||
| std::cout << "Received input " << std::string(input.id) << " (counter: " << (unsigned int)counter << ")" << std::endl; | |||
| std::vector<unsigned char> out_vec{counter}; | |||
| rust::Slice<const uint8_t> out_slice{out_vec.data(), out_vec.size()}; | |||
| auto result = send_output(dora_node.send_output, "counter", out_slice); | |||
| auto error = std::string(result.error); | |||
| if (!error.empty()) | |||
| { | |||
| std::cerr << "Error: " << error << std::endl; | |||
| return -1; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| std::cerr << "Error: " << error << std::endl; | |||
| std::cerr << "Unknown event type " << static_cast<int>(ty) << std::endl; | |||
| return -1; | |||
| } | |||
| } | |||
| @@ -20,22 +20,6 @@ async fn main() -> eyre::Result<()> { | |||
| tokio::fs::create_dir_all("build").await?; | |||
| let build_dir = Path::new("build"); | |||
| build_package("dora-operator-api-cxx").await?; | |||
| let operator_cxxbridge = target | |||
| .join("cxxbridge") | |||
| .join("dora-operator-api-cxx") | |||
| .join("src"); | |||
| tokio::fs::copy( | |||
| operator_cxxbridge.join("lib.rs.cc"), | |||
| build_dir.join("operator-bridge.cc"), | |||
| ) | |||
| .await?; | |||
| tokio::fs::copy( | |||
| operator_cxxbridge.join("lib.rs.h"), | |||
| build_dir.join("dora-operator-api.h"), | |||
| ) | |||
| .await?; | |||
| build_package("dora-node-api-cxx").await?; | |||
| let node_cxxbridge = target | |||
| .join("cxxbridge") | |||
| @@ -58,7 +42,7 @@ async fn main() -> eyre::Result<()> { | |||
| .await?; | |||
| build_package("dora-node-api-c").await?; | |||
| build_package("dora-operator-api-c").await?; | |||
| // build_package("dora-operator-api-c").await?; | |||
| build_cxx_node( | |||
| root, | |||
| &[ | |||
| @@ -69,45 +53,42 @@ async fn main() -> eyre::Result<()> { | |||
| &["-l", "dora_node_api_cxx"], | |||
| ) | |||
| .await?; | |||
| build_cxx_node( | |||
| root, | |||
| &[&dunce::canonicalize( | |||
| Path::new("node-c-api").join("main.cc"), | |||
| )?], | |||
| "node_c_api", | |||
| &["-l", "dora_node_api_c"], | |||
| ) | |||
| .await?; | |||
| build_cxx_operator( | |||
| &[ | |||
| &dunce::canonicalize(Path::new("operator-rust-api").join("operator.cc"))?, | |||
| &dunce::canonicalize(build_dir.join("operator-bridge.cc"))?, | |||
| ], | |||
| "operator_rust_api", | |||
| &[ | |||
| "-l", | |||
| "dora_operator_api_cxx", | |||
| "-L", | |||
| &root.join("target").join("debug").to_str().unwrap(), | |||
| ], | |||
| ) | |||
| .await?; | |||
| build_cxx_operator( | |||
| &[&dunce::canonicalize( | |||
| Path::new("operator-c-api").join("operator.cc"), | |||
| )?], | |||
| "operator_c_api", | |||
| &[], | |||
| ) | |||
| .await?; | |||
| // build_cxx_node( | |||
| // root, | |||
| // &[&dunce::canonicalize( | |||
| // Path::new("node-c-api").join("main.cc"), | |||
| // )?], | |||
| // "node_c_api", | |||
| // &["-l", "dora_node_api_c"], | |||
| // ) | |||
| // .await?; | |||
| // build_cxx_operator( | |||
| // &[ | |||
| // &dunce::canonicalize(Path::new("operator-rust-api").join("operator.cc"))?, | |||
| // &dunce::canonicalize(build_dir.join("operator-bridge.cc"))?, | |||
| // ], | |||
| // "operator_rust_api", | |||
| // &[ | |||
| // "-l", | |||
| // "dora_operator_api_cxx", | |||
| // "-L", | |||
| // &root.join("target").join("debug").to_str().unwrap(), | |||
| // ], | |||
| // ) | |||
| // .await?; | |||
| // build_cxx_operator( | |||
| // &[&dunce::canonicalize( | |||
| // Path::new("operator-c-api").join("operator.cc"), | |||
| // )?], | |||
| // "operator_c_api", | |||
| // &[], | |||
| // ) | |||
| // .await?; | |||
| build_package("dora-runtime").await?; | |||
| // build_package("dora-runtime").await?; | |||
| dora_coordinator::run(dora_coordinator::Args { | |||
| run_dataflow: Path::new("dataflow.yml").to_owned().into(), | |||
| runtime: Some(root.join("target").join("debug").join("dora-runtime")), | |||
| }) | |||
| .await?; | |||
| let dataflow = Path::new("dataflow.yml").to_owned(); | |||
| dora_daemon::Daemon::run_dataflow(&dataflow).await?; | |||
| Ok(()) | |||
| } | |||