diff --git a/Cargo.lock b/Cargo.lock index 8bf335be..6b460a9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -696,6 +696,14 @@ dependencies = [ "zenoh-config", ] +[[package]] +name = "dora-node-api-c" +version = "0.1.0" +dependencies = [ + "dora-node-api", + "futures", +] + [[package]] name = "dora-node-api-python" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ff2d58a9..0e740451 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,14 @@ [workspace] members = [ - "apis/rust/node", - "apis/rust/operator", - "apis/rust/operator/macros", + "apis/c/node", "apis/python/node", - "binaries/coordinator", - "binaries/runtime", - "libraries/extensions/message", - "libraries/extensions/telemetry/metrics", - "libraries/extensions/telemetry/tracing", - "libraries/core", + "apis/rust/*", + "apis/rust/operator/macros", + "binaries/*", "examples/example-operator", + "libraries/core", + "libraries/extensions/message", + "libraries/extensions/telemetry/*", + "libraries/extensions/telemetry/*", "libraries/extensions/zenoh-logger", ] diff --git a/apis/c/node/Cargo.toml b/apis/c/node/Cargo.toml new file mode 100644 index 00000000..791ad4d1 --- /dev/null +++ b/apis/c/node/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "dora-node-api-c" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["staticlib"] + +[dependencies] +dora-node-api = { path = "../../rust/node" } +futures = "0.3.21" diff --git a/apis/c/node/src/lib.rs b/apis/c/node/src/lib.rs new file mode 100644 index 00000000..be53ee5f --- /dev/null +++ b/apis/c/node/src/lib.rs @@ -0,0 +1,21 @@ +use std::ptr; + +use dora_node_api::DoraNode; +use futures::executor::block_on; + +pub extern "C" fn init_dora_node_from_env() -> *mut () { + let node = match block_on(DoraNode::init_from_env()) { + Ok(n) => n, + Err(err) => { + eprintln!("{err:?}"); + return ptr::null_mut(); + } + }; + + Box::into_raw(Box::new(node)).cast() +} + +pub extern "C" fn free_dora_node(node: *mut ()) { + let node: Box = unsafe { Box::from_raw(node.cast()) }; + let _ = node; +}