Skip to content

Commit

Permalink
Upgrade up-rust.
Browse files Browse the repository at this point in the history
Signed-off-by: ChenYing Kuo <[email protected]>
  • Loading branch information
evshary committed Apr 10, 2024
1 parent 69122c2 commit 7818841
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 295 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ prost = "0.12"
prost-types = "0.12"
protobuf = { version = "3.3" }
rand = "0.8.5"
up-rust = { git = "https://github.com/eclipse-uprotocol/up-rust", rev = "a30d3655ab13f8d97815280d718f4891f693ed2d" }
up-rust = { git = "https://github.com/eclipse-uprotocol/up-rust", rev = "c705ac97602ad6917a93d23651e8a504ec7bb718" }
zenoh = { version = "0.10.1-rc", features = ["unstable"]}

[dev-dependencies]
Expand Down
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub mod utransport;
use protobuf::{Enum, Message};
use std::{
collections::HashMap,
sync::{atomic::AtomicU64, Arc, Mutex},
sync::{Arc, Mutex},
};
use up_rust::{
UAttributes, UAuthority, UCode, UEntity, UMessage, UPayloadFormat, UPriority, UResourceBuilder,
UStatus, UUri,
ComparableListener, UAttributes, UAuthority, UCode, UEntity, UListener, UPayloadFormat,
UPriority, UResourceBuilder, UStatus, UUri,
};
use zenoh::{
config::Config,
Expand All @@ -31,23 +31,22 @@ use zenoh::{
subscriber::Subscriber,
};

pub type UtransportListener = Box<dyn Fn(Result<UMessage, UStatus>) + Send + Sync + 'static>;

const UATTRIBUTE_VERSION: u8 = 1;

pub struct ZenohListener {}
type SubscriberMap = Arc<Mutex<HashMap<(UUri, ComparableListener), Subscriber<'static, ()>>>>;
type QueryableMap = Arc<Mutex<HashMap<(UUri, ComparableListener), Queryable<'static, ()>>>>;
type QueryMap = Arc<Mutex<HashMap<String, Query>>>;
type RpcCallbackMap = Arc<Mutex<HashMap<UUri, Arc<dyn UListener>>>>;
pub struct UPClientZenoh {
session: Arc<Session>,
// Able to unregister Subscriber
subscriber_map: Arc<Mutex<HashMap<String, Subscriber<'static, ()>>>>,
subscriber_map: SubscriberMap,
// Able to unregister Queryable
queryable_map: Arc<Mutex<HashMap<String, Queryable<'static, ()>>>>,
queryable_map: QueryableMap,
// Save the reqid to be able to send back response
query_map: Arc<Mutex<HashMap<String, Query>>>,
query_map: QueryMap,
// Save the callback for RPC response
rpc_callback_map: Arc<Mutex<HashMap<String, Arc<UtransportListener>>>>,
// Used to identify different callback
callback_counter: AtomicU64,
rpc_callback_map: RpcCallbackMap,
// Source UUri in RPC
source_uuri: UUri,
}
Expand Down Expand Up @@ -117,7 +116,6 @@ impl UPClientZenoh {
queryable_map: Arc::new(Mutex::new(HashMap::new())),
query_map: Arc::new(Mutex::new(HashMap::new())),
rpc_callback_map: Arc::new(Mutex::new(HashMap::new())),
callback_counter: AtomicU64::new(0),
source_uuri,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl RpcClient for UPClientZenoh {

// Create UAttributes and put into Zenoh user attachment
let uattributes = UAttributes::request(
UUIDBuilder::new().build(),
UUIDBuilder::build(),
topic,
self.get_response_uuri(),
options.clone(),
Expand Down
Loading

0 comments on commit 7818841

Please sign in to comment.