diff --git a/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs b/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs --- a/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs +++ b/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs @@ -1,4 +1,6 @@ fn main() { tonic_build::compile_protos("../../protos/blob.proto") .unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e)); + let _cxx_build = + cxx_build::bridge("src/lib.rs").flag_if_supported("-std=c++14"); } diff --git a/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs b/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs --- a/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs +++ b/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs @@ -11,7 +11,7 @@ tonic::include_proto!("blob"); } -const BLOB_SERVICE_SOCKET_ADDR: &str = "http://localhost:50053"; +const BLOB_SERVICE_SOCKET_ADDR: &str = "http://192.168.83.43:50053"; lazy_static! { pub static ref RUNTIME: Runtime = Builder::new_multi_thread() @@ -28,6 +28,29 @@ stream_end: bool, data: Vec, } + + extern "Rust" { + type UploadState; + type DownloadState; + + fn initialize_upload_state_blocking() -> Result>; + fn start_upload_blocking( + state: &mut Box, + holder: String, + hash: String, + ) -> Result<()>; + fn upload_chunk_blocking( + state: &mut Box, + chunk: &[u8], + ) -> Result<()>; + fn complete_upload_blocking(client: Box) -> Result; + fn initialize_download_state_blocking( + holder: String, + ) -> Result>; + fn pull_chunk_blocking( + client: &mut Box, + ) -> Result; + } } pub struct UploadState { @@ -162,3 +185,40 @@ data: vec![], }) } + +pub fn initialize_upload_state_blocking() -> Result, String> { + RUNTIME.block_on(initialize_upload_state()) +} + +pub fn start_upload_blocking( + state: &mut Box, + holder: String, + hash: String, +) -> Result<(), String> { + RUNTIME.block_on(start_upload(state, holder, hash)) +} + +pub fn upload_chunk_blocking( + state: &mut Box, + chunk: &[u8], +) -> Result<(), String> { + RUNTIME.block_on(upload_chunk(state, chunk)) +} + +pub fn complete_upload_blocking( + client: Box, +) -> Result { + RUNTIME.block_on(complete_upload(client)) +} + +pub fn initialize_download_state_blocking( + holder: String, +) -> Result, String> { + RUNTIME.block_on(initialize_download_state(holder)) +} + +pub fn pull_chunk_blocking( + client: &mut Box, +) -> Result { + RUNTIME.block_on(pull_chunk(client)) +}