Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UListener interface and UUID builder #24

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
evshary marked this conversation as resolved.
Show resolved Hide resolved
};
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(),
evshary marked this conversation as resolved.
Show resolved Hide resolved
evshary marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading