mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
add a gen_id method for plugins to generate ids
This commit is contained in:
parent
6421899c29
commit
8839c4eea8
1 changed files with 11 additions and 0 deletions
|
@ -8,6 +8,8 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use std::sync::{RwLock, Arc};
|
use std::sync::{RwLock, Arc};
|
||||||
|
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -73,6 +75,7 @@ pub struct PluginProxyBinding {
|
||||||
dispatcher: Arc<Dispatcher>,
|
dispatcher: Arc<Dispatcher>,
|
||||||
plugin_container: Arc<PluginContainer>,
|
plugin_container: Arc<PluginContainer>,
|
||||||
jid: Jid,
|
jid: Jid,
|
||||||
|
next_id: Arc<AtomicUsize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PluginProxyBinding {
|
impl PluginProxyBinding {
|
||||||
|
@ -81,6 +84,7 @@ impl PluginProxyBinding {
|
||||||
dispatcher: dispatcher,
|
dispatcher: dispatcher,
|
||||||
plugin_container: plugin_container,
|
plugin_container: plugin_container,
|
||||||
jid: jid,
|
jid: jid,
|
||||||
|
next_id: Arc::new(ATOMIC_USIZE_INIT),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +156,13 @@ impl PluginProxy {
|
||||||
binding.jid.clone()
|
binding.jid.clone()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a new id.
|
||||||
|
pub fn gen_id(&self) -> String {
|
||||||
|
self.with_binding(|binding| {
|
||||||
|
format!("{}", binding.next_id.fetch_add(1, Ordering::SeqCst))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait whch all plugins should implement.
|
/// A trait whch all plugins should implement.
|
||||||
|
|
Loading…
Reference in a new issue