Skip to content

Commit

Permalink
make Selector::key_expr pub(crate) and add corresponding accessor (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Apr 13, 2024
1 parent d6da7a8 commit 14a2036
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ci/valgrind-check/src/queryable_get/bin/z_queryable_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() {
zenoh_runtime::ZRuntime::Application.block_in_place(async move {
query
.reply(
query.selector().key_expr,
query.selector().key_expr(),
query.value().unwrap().payload().clone(),
)
.res()
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() {
let query = query.unwrap();
println!(">> [Queryable ] Received Query '{}'", query.selector());
for (stored_name, sample) in stored.iter() {
if query.selector().key_expr.intersects(unsafe {keyexpr::from_str_unchecked(stored_name)}) {
if query.selector().key_expr().intersects(unsafe {keyexpr::from_str_unchecked(stored_name)}) {
query.reply(sample.key_expr().clone(), sample.payload().clone()).res().await.unwrap();
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/zenoh-plugin-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async fn run(runtime: Runtime, selector: KeyExpr<'_>, flag: Arc<AtomicBool>) {
let query = query.unwrap();
info!("Handling query '{}'", query.selector());
for (key_expr, sample) in stored.iter() {
if query.selector().key_expr.intersects(unsafe{keyexpr::from_str_unchecked(key_expr)}) {
if query.selector().key_expr().intersects(unsafe{keyexpr::from_str_unchecked(key_expr)}) {
query.reply_sample(sample.clone()).res().await.unwrap();
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/zenoh-plugin-rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl RunningPluginTrait for RunningPlugin {
with_extended_string(&mut key, &["/version"], |key| {
if keyexpr::new(key.as_str())
.unwrap()
.intersects(&selector.key_expr)
.intersects(selector.key_expr())
{
responses.push(zenoh::plugins::Response::new(
key.clone(),
Expand All @@ -285,7 +285,7 @@ impl RunningPluginTrait for RunningPlugin {
with_extended_string(&mut key, &["/port"], |port_key| {
if keyexpr::new(port_key.as_str())
.unwrap()
.intersects(&selector.key_expr)
.intersects(selector.key_expr())
{
responses.push(zenoh::plugins::Response::new(
port_key.clone(),
Expand Down
8 changes: 4 additions & 4 deletions plugins/zenoh-plugin-storage-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl RunningPluginTrait for StorageRuntime {
with_extended_string(&mut key, &["/version"], |key| {
if keyexpr::new(key.as_str())
.unwrap()
.intersects(&selector.key_expr)
.intersects(selector.key_expr())
{
responses.push(zenoh::plugins::Response::new(
key.clone(),
Expand All @@ -319,7 +319,7 @@ impl RunningPluginTrait for StorageRuntime {
with_extended_string(key, &["/__path__"], |key| {
if keyexpr::new(key.as_str())
.unwrap()
.intersects(&selector.key_expr)
.intersects(selector.key_expr())
{
responses.push(zenoh::plugins::Response::new(
key.clone(),
Expand All @@ -329,7 +329,7 @@ impl RunningPluginTrait for StorageRuntime {
});
if keyexpr::new(key.as_str())
.unwrap()
.intersects(&selector.key_expr)
.intersects(selector.key_expr())
{
responses.push(zenoh::plugins::Response::new(
key.clone(),
Expand All @@ -345,7 +345,7 @@ impl RunningPluginTrait for StorageRuntime {
with_extended_string(key, &[storage], |key| {
if keyexpr::new(key.as_str())
.unwrap()
.intersects(&selector.key_expr)
.intersects(selector.key_expr())
{
if let Ok(value) = task::block_on(async {
let (tx, rx) = async_std::channel::bounded(1);
Expand Down
6 changes: 3 additions & 3 deletions zenoh-ext/src/publication_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl<'a> PublicationCache<'a> {
// on query, reply with cach content
query = quer_recv.recv_async() => {
if let Ok(query) = query {
if !query.selector().key_expr.as_str().contains('*') {
if let Some(queue) = cache.get(query.selector().key_expr.as_keyexpr()) {
if !query.selector().key_expr().as_str().contains('*') {
if let Some(queue) = cache.get(query.selector().key_expr().as_keyexpr()) {
for sample in queue {
if let (Ok(Some(time_range)), Some(timestamp)) = (query.selector().time_range(), sample.timestamp()) {
if !time_range.contains(timestamp.get_time().to_system_time()){
Expand All @@ -220,7 +220,7 @@ impl<'a> PublicationCache<'a> {
}
} else {
for (key_expr, queue) in cache.iter() {
if query.selector().key_expr.intersects(unsafe{ keyexpr::from_str_unchecked(key_expr) }) {
if query.selector().key_expr().intersects(unsafe{ keyexpr::from_str_unchecked(key_expr) }) {
for sample in queue {
if let (Ok(Some(time_range)), Some(timestamp)) = (query.selector().time_range(), sample.timestamp()) {
if !time_range.contains(timestamp.get_time().to_system_time()){
Expand Down
8 changes: 6 additions & 2 deletions zenoh/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ use std::{
#[derive(Clone, PartialEq, Eq)]
pub struct Selector<'a> {
/// The part of this selector identifying which keys should be part of the selection.
pub key_expr: KeyExpr<'a>,
/// the part of this selector identifying which values should be part of the selection.
pub(crate) key_expr: KeyExpr<'a>,
/// The part of this selector identifying which values should be part of the selection.
pub(crate) parameters: Cow<'a, str>,
}

pub const TIME_RANGE_KEY: &str = "_time";
impl<'a> Selector<'a> {
/// Gets the key-expression.
pub fn key_expr(&'a self) -> &KeyExpr<'a> {
&self.key_expr
}
/// Gets the parameters as a raw string.
pub fn parameters(&self) -> &str {
&self.parameters
Expand Down

0 comments on commit 14a2036

Please sign in to comment.