Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3531077
D4888.id16069.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D4888.id16069.diff
View Options
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -34,4 +34,4 @@
# Nix
result*
-services/backup/rust_lib/target/
+services/backup/blob_client/target/
diff --git a/services/backup/CMakeLists.txt b/services/backup/CMakeLists.txt
--- a/services/backup/CMakeLists.txt
+++ b/services/backup/CMakeLists.txt
@@ -60,7 +60,7 @@
${SOURCE_CODE}
)
-add_library_rust(PATH rust_lib NAMESPACE backup)
+add_library_rust(PATH blob_client NAMESPACE backup)
target_include_directories(
backup
@@ -88,7 +88,7 @@
comm-backup-grpc
comm-services-common
comm-server-base-reactors
- backup::rust_lib
+ backup::blob_client
)
target_link_libraries(
diff --git a/services/backup/rust_lib/Cargo.lock b/services/backup/blob_client/Cargo.lock
rename from services/backup/rust_lib/Cargo.lock
rename to services/backup/blob_client/Cargo.lock
--- a/services/backup/rust_lib/Cargo.lock
+++ b/services/backup/blob_client/Cargo.lock
@@ -8,6 +8,18 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+[[package]]
+name = "blob_client"
+version = "0.1.0"
+dependencies = [
+ "cxx",
+ "cxx-build",
+ "lazy_static",
+ "libc",
+ "tokio",
+ "tokio-stream",
+]
+
[[package]]
name = "cc"
version = "1.0.73"
@@ -144,18 +156,6 @@
"proc-macro2",
]
-[[package]]
-name = "rust_lib"
-version = "0.1.0"
-dependencies = [
- "cxx",
- "cxx-build",
- "lazy_static",
- "libc",
- "tokio",
- "tokio-stream",
-]
-
[[package]]
name = "scratch"
version = "1.0.2"
diff --git a/services/backup/rust_lib/Cargo.toml b/services/backup/blob_client/Cargo.toml
rename from services/backup/rust_lib/Cargo.toml
rename to services/backup/blob_client/Cargo.toml
--- a/services/backup/rust_lib/Cargo.toml
+++ b/services/backup/blob_client/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "rust_lib"
+name = "blob_client"
version = "0.1.0"
edition = "2021"
diff --git a/services/backup/rust_lib/build.rs b/services/backup/blob_client/build.rs
rename from services/backup/rust_lib/build.rs
rename to services/backup/blob_client/build.rs
diff --git a/services/backup/rust_lib/src/constants.rs b/services/backup/blob_client/src/constants.rs
rename from services/backup/rust_lib/src/constants.rs
rename to services/backup/blob_client/src/constants.rs
diff --git a/services/backup/blob_client/src/get_client.rs b/services/backup/blob_client/src/get_client.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/blob_client/src/get_client.rs
@@ -0,0 +1 @@
+
diff --git a/services/backup/blob_client/src/lib.rs b/services/backup/blob_client/src/lib.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/blob_client/src/lib.rs
@@ -0,0 +1,18 @@
+mod constants;
+mod get_client;
+mod put_client;
+
+use put_client::{
+ put_client_blocking_read_cxx, put_client_initialize_cxx,
+ put_client_terminate_cxx, put_client_write_cxx,
+};
+
+#[cxx::bridge]
+mod ffi {
+ extern "Rust" {
+ fn put_client_initialize_cxx() -> ();
+ fn put_client_blocking_read_cxx() -> ();
+ unsafe fn put_client_write_cxx(data: *const c_char) -> ();
+ fn put_client_terminate_cxx() -> ();
+ }
+}
diff --git a/services/backup/blob_client/src/put_client.rs b/services/backup/blob_client/src/put_client.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/blob_client/src/put_client.rs
@@ -0,0 +1,17 @@
+use libc::c_char;
+
+pub fn put_client_initialize_cxx() -> () {
+ unimplemented!();
+}
+
+pub fn put_client_blocking_read_cxx() -> () {
+ unimplemented!();
+}
+
+pub fn put_client_write_cxx(data: *const c_char) -> () {
+ unimplemented!();
+}
+
+pub fn put_client_terminate_cxx() -> () {
+ unimplemented!();
+}
diff --git a/services/backup/rust_lib/src/lib.rs b/services/backup/rust_lib/src/lib.rs
deleted file mode 100644
--- a/services/backup/rust_lib/src/lib.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-#[cxx::bridge]
-mod ffi {
- extern "Rust" {
- fn rust_is_initialized_cxx() -> bool;
- fn rust_initialize_cxx() -> ();
- unsafe fn rust_process_cxx(data: *const c_char) -> ();
- fn rust_terminate_cxx() -> ();
- }
-}
-
-mod constants;
-
-use constants::MPSC_CHANNEL_BUFFER_CAPACITY;
-use tokio::runtime::Runtime;
-use tokio::sync::mpsc;
-use tokio::task::JoinHandle;
-use lazy_static::lazy_static;
-use std::sync::{Arc, Mutex};
-use libc;
-use libc::c_char;
-use std::ffi::CStr;
-
-pub struct Client {
- tx: Option<mpsc::Sender<String>>,
- handle: Option<JoinHandle<()>>,
-}
-
-lazy_static! {
- pub static ref CLIENT: Arc<Mutex<Client>> = Arc::new(Mutex::new(Client {
- tx: None,
- handle: None
- }));
- pub static ref RUNTIME: Runtime = Runtime::new().unwrap();
-}
-
-pub fn rust_is_initialized_cxx() -> bool {
- if CLIENT.lock().expect("access client").tx.is_none() {
- return false;
- }
- if CLIENT.lock().expect("access client").handle.is_none() {
- return false;
- }
- return true;
-}
-
-pub fn rust_initialize_cxx() -> () {
- println!("[RUST] initializing");
- assert!(!rust_is_initialized_cxx(), "client cannot be initialized twice");
- let (tx, mut rx): (mpsc::Sender<String>, mpsc::Receiver<String>) =
- mpsc::channel(MPSC_CHANNEL_BUFFER_CAPACITY);
- let handle = RUNTIME.spawn(async move {
- println!("[RUST] [receiver] begin");
- while let Some(data) = rx.recv().await {
- println!("[RUST] [receiver] data: {}", data);
- }
- println!("[RUST] [receiver] done");
- });
- CLIENT.lock().expect("access client").handle = Some(handle);
- CLIENT.lock().expect("access client").tx = Some(tx);
- println!("[RUST] initialized");
-}
-
-pub fn rust_process_cxx(data: *const c_char) -> () {
- println!("[RUST] [rust_process] begin");
- let data_c_str: &CStr = unsafe { CStr::from_ptr(data) };
- let data_str: String = data_c_str.to_str().unwrap().to_owned();
- println!("[RUST] [rust_process] data string: {}", data_str);
-
- RUNTIME.block_on(async {
- CLIENT
- .lock()
- .expect("access client")
- .tx
- .as_ref()
- .expect("access client's transmitter")
- .send(data_str)
- .await
- .expect("send data to receiver");
- });
- println!("[RUST] [rust_process] end");
-}
-
-pub fn rust_terminate_cxx() -> () {
- println!("[RUST] rust_terminating");
- let handle = CLIENT.lock().expect("access client").handle.take().unwrap();
-
- drop(CLIENT.lock().expect("access client").tx.take().unwrap());
- RUNTIME.block_on(async {
- handle.await.unwrap();
- });
-
- assert!(!rust_is_initialized_cxx(), "client handler released properly");
- println!("[RUST] rust_terminated");
-}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 5:46 AM (11 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2702921
Default Alt Text
D4888.id16069.diff (6 KB)
Attached To
Mode
D4888: [services] Backup - Connect to Blob - split code to diferent files
Attached
Detach File
Event Timeline
Log In to Comment