Skip to content

Commit

Permalink
Mark questionable API items as unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Sep 16, 2024
1 parent 16ade3c commit b08afba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions zenoh/src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ impl Config {
.map_err(InsertionError)
}

#[zenoh_macros::unstable]
pub fn get<'a>(&'a self, key: &str) -> Result<&'a dyn Any, LookupError> {
<zenoh_config::Config as validated_struct::ValidatedMap>::get(&self.0, key)
.map_err(LookupError)
}

#[zenoh_macros::unstable]
pub fn remove<K: AsRef<str>>(&mut self, key: K) -> ZResult<()> {
self.0.remove(key)
}
Expand Down Expand Up @@ -92,23 +94,29 @@ impl fmt::Display for Config {
}
}

#[zenoh_macros::unstable]
pub type Notification = Arc<str>;

struct NotifierInner<T> {
inner: Mutex<T>,
subscribers: Mutex<Vec<flume::Sender<Notification>>>,
}

#[zenoh_macros::unstable]
pub struct Notifier<T> {
inner: Arc<NotifierInner<T>>,
}

impl<T> Clone for Notifier<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}

impl Notifier<Config> {
#[zenoh_macros::unstable]
pub fn new(inner: Config) -> Self {
Notifier {
inner: Arc::new(NotifierInner {
Expand All @@ -118,12 +126,14 @@ impl Notifier<Config> {
}
}

#[zenoh_macros::unstable]
pub fn subscribe(&self) -> flume::Receiver<Notification> {
let (tx, rx) = flume::unbounded();
self.lock_subscribers().push(tx);
rx
}

#[zenoh_macros::unstable]
pub fn notify<K: AsRef<str>>(&self, key: K) {
let key = key.as_ref();
let key: Arc<str> = Arc::from(key);
Expand All @@ -141,6 +151,7 @@ impl Notifier<Config> {
}
}

#[zenoh_macros::unstable]
pub fn lock(&self) -> MutexGuard<Config> {
self.lock_config()
}
Expand All @@ -159,16 +170,19 @@ impl Notifier<Config> {
.expect("acquiring Notifier's Config Mutex should not fail")
}

#[zenoh_macros::unstable]
pub fn remove<K: AsRef<str>>(&self, key: K) -> ZResult<()> {
self.lock_config().remove(key.as_ref())?;
self.notify(key);
Ok(())
}

#[zenoh_macros::unstable]
pub fn insert_json5(&self, key: &str, value: &str) -> Result<(), InsertionError> {
self.lock_config().insert_json5(key, value)
}

#[zenoh_macros::unstable]
pub fn get<'a>(&'a self, key: &str) -> Result<LookupGuard<'a, Config>, LookupError> {
let config = self.lock_config();
// SAFETY: MutexGuard pins the mutex behind which the value is held.
Expand All @@ -180,6 +194,7 @@ impl Notifier<Config> {
}
}

#[zenoh_macros::unstable]
pub struct LookupGuard<'a, T> {
_guard: MutexGuard<'a, T>,
subref: *const dyn Any,
Expand Down
1 change: 1 addition & 0 deletions zenoh/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ impl Session {
/// let _ = session.config().insert_json5("connect/endpoints", r#"["tcp/127.0.0.1/7447"]"#);
/// # }
/// ```
#[zenoh_macros::unstable]
pub fn config(&self) -> &Notifier<Config> {
self.0.runtime.config()
}
Expand Down

0 comments on commit b08afba

Please sign in to comment.