Skip to content

Commit eb5d194

Browse files
authored
expose unstable SourceInfo (#598)
* expose unstable SourceInfo * add missing export
1 parent e1569bc commit eb5d194

File tree

6 files changed

+94
-16
lines changed

6 files changed

+94
-16
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) mod zenoh {
6868
ConsolidationMode, Parameters, Querier, Query, QueryConsolidation, QueryTarget,
6969
Queryable, Reply, ReplyError, Selector,
7070
},
71-
sample::{Locality, Sample, SampleKind},
71+
sample::{Locality, Sample, SampleKind, SourceInfo},
7272
scouting::{scout, Hello, Scout},
7373
session::{open, EntityGlobalId, Session, SessionInfo},
7474
time::{Timestamp, TimestampId},

src/pubsub.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
macros::{build, option_wrapper},
2525
matching::{MatchingListener, MatchingStatus},
2626
qos::{CongestionControl, Priority, Reliability},
27-
sample::Sample,
27+
sample::{Sample, SourceInfo},
2828
time::Timestamp,
2929
utils::{generic, wait},
3030
};
@@ -78,30 +78,37 @@ impl Publisher {
7878
Ok(wait(py, self.get_ref()?.matching_status())?.into())
7979
}
8080

81-
#[pyo3(signature = (payload, *, encoding = None, attachment = None, timestamp = None))]
81+
#[pyo3(signature = (payload, *, encoding = None, attachment = None, timestamp = None, source_info = None))]
8282
fn put(
8383
&self,
8484
py: Python,
8585
#[pyo3(from_py_with = ZBytes::from_py)] payload: ZBytes,
8686
#[pyo3(from_py_with = Encoding::from_py_opt)] encoding: Option<Encoding>,
8787
#[pyo3(from_py_with = ZBytes::from_py_opt)] attachment: Option<ZBytes>,
8888
timestamp: Option<Timestamp>,
89+
source_info: Option<SourceInfo>,
8990
) -> PyResult<()> {
9091
let this = self.get_ref()?;
91-
wait(
92-
py,
93-
build!(this.put(payload), encoding, attachment, timestamp),
94-
)
92+
let builder = build!(
93+
this.put(payload),
94+
encoding,
95+
attachment,
96+
timestamp,
97+
source_info
98+
);
99+
wait(py, builder)
95100
}
96101

97-
#[pyo3(signature = (*, attachment = None, timestamp = None))]
102+
#[pyo3(signature = (*, attachment = None, timestamp = None, source_info = None))]
98103
fn delete(
99104
&self,
100105
py: Python,
101106
#[pyo3(from_py_with = ZBytes::from_py_opt)] attachment: Option<ZBytes>,
102107
timestamp: Option<Timestamp>,
108+
source_info: Option<SourceInfo>,
103109
) -> PyResult<()> {
104-
wait(py, build!(self.get_ref()?.delete(), attachment, timestamp))
110+
let builder = build!(self.get_ref()?.delete(), attachment, timestamp, source_info);
111+
wait(py, builder)
105112
}
106113

107114
#[pyo3(signature = (handler = None))]

src/query.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::{
2626
macros::{build, downcast_or_new, enum_mapper, option_wrapper, wrapper},
2727
matching::{MatchingListener, MatchingStatus},
2828
qos::{CongestionControl, Priority},
29+
sample::SourceInfo,
2930
session::EntityGlobalId,
3031
time::Timestamp,
3132
utils::{generic, wait, IntoPyResult, IntoPython, IntoRust, MapInto},
@@ -351,7 +352,7 @@ impl Querier {
351352
}
352353

353354
#[allow(clippy::too_many_arguments)]
354-
#[pyo3(signature = (handler = None, *, parameters = None, payload = None, encoding = None, attachment = None))]
355+
#[pyo3(signature = (handler = None, *, parameters = None, payload = None, encoding = None, attachment = None, source_info = None))]
355356
fn get(
356357
&self,
357358
py: Python,
@@ -360,10 +361,18 @@ impl Querier {
360361
#[pyo3(from_py_with = ZBytes::from_py_opt)] payload: Option<ZBytes>,
361362
#[pyo3(from_py_with = Encoding::from_py_opt)] encoding: Option<Encoding>,
362363
#[pyo3(from_py_with = ZBytes::from_py_opt)] attachment: Option<ZBytes>,
364+
source_info: Option<SourceInfo>,
363365
) -> PyResult<HandlerImpl<Reply>> {
364366
let this = self.get_ref()?;
365367
let (handler, _) = into_handler(py, handler)?;
366-
let builder = build!(this.get(), parameters, payload, encoding, attachment);
368+
let builder = build!(
369+
this.get(),
370+
parameters,
371+
payload,
372+
encoding,
373+
attachment,
374+
source_info
375+
);
367376
wait(py, builder.with(handler)).map_into()
368377
}
369378

src/sample.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
1414
use pyo3::prelude::*;
15+
use zenoh::sample::SourceSn;
1516

1617
use crate::{
1718
bytes::{Encoding, ZBytes},
1819
key_expr::KeyExpr,
1920
macros::{enum_mapper, wrapper},
2021
qos::{CongestionControl, Priority},
22+
session::EntityGlobalId,
2123
time::Timestamp,
2224
utils::MapInto,
2325
};
@@ -88,7 +90,35 @@ impl Sample {
8890
self.0.attachment().cloned().map_into()
8991
}
9092

93+
#[getter]
94+
fn source_info(&self) -> SourceInfo {
95+
self.0.source_info().clone().into()
96+
}
97+
9198
fn __repr__(&self) -> String {
9299
format!("{:?}", self.0)
93100
}
94101
}
102+
103+
wrapper!(zenoh::sample::SourceInfo: Clone);
104+
105+
#[pymethods]
106+
impl SourceInfo {
107+
#[new]
108+
fn new(source_id: Option<EntityGlobalId>, source_sn: Option<SourceSn>) -> Self {
109+
Self(zenoh::sample::SourceInfo::new(
110+
source_id.map_into(),
111+
source_sn,
112+
))
113+
}
114+
115+
#[getter]
116+
fn source_id(&self) -> Option<EntityGlobalId> {
117+
self.0.source_id().cloned().map_into()
118+
}
119+
120+
#[getter]
121+
fn source_sn(&self) -> Option<SourceSn> {
122+
self.0.source_sn()
123+
}
124+
}

src/session.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{
2929
pubsub::{Publisher, Subscriber},
3030
qos::{CongestionControl, Priority, Reliability},
3131
query::{Querier, QueryConsolidation, QueryTarget, Queryable, Reply, Selector},
32-
sample::Locality,
32+
sample::{Locality, SourceInfo},
3333
time::Timestamp,
3434
utils::{duration, wait, IntoPython, MapInto},
3535
};
@@ -87,7 +87,7 @@ impl Session {
8787
}
8888

8989
#[allow(clippy::too_many_arguments)]
90-
#[pyo3(signature = (key_expr, payload, *, encoding = None, congestion_control = None, priority = None, express = None, attachment = None, timestamp = None, allowed_destination = None))]
90+
#[pyo3(signature = (key_expr, payload, *, encoding = None, congestion_control = None, priority = None, express = None, attachment = None, timestamp = None, allowed_destination = None, source_info = None))]
9191
fn put(
9292
&self,
9393
py: Python,
@@ -100,6 +100,7 @@ impl Session {
100100
#[pyo3(from_py_with = ZBytes::from_py_opt)] attachment: Option<ZBytes>,
101101
timestamp: Option<Timestamp>,
102102
allowed_destination: Option<Locality>,
103+
source_info: Option<SourceInfo>,
103104
) -> PyResult<()> {
104105
let build = build!(
105106
self.0.put(key_expr, payload),
@@ -110,12 +111,13 @@ impl Session {
110111
attachment,
111112
timestamp,
112113
allowed_destination,
114+
source_info,
113115
);
114116
wait(py, build)
115117
}
116118

117119
#[allow(clippy::too_many_arguments)]
118-
#[pyo3(signature = (key_expr, *, congestion_control = None, priority = None, express = None, attachment = None, timestamp = None, allowed_destination = None))]
120+
#[pyo3(signature = (key_expr, *, congestion_control = None, priority = None, express = None, attachment = None, timestamp = None, allowed_destination = None, source_info = None))]
119121
fn delete(
120122
&self,
121123
py: Python,
@@ -126,6 +128,7 @@ impl Session {
126128
#[pyo3(from_py_with = ZBytes::from_py_opt)] attachment: Option<ZBytes>,
127129
timestamp: Option<Timestamp>,
128130
allowed_destination: Option<Locality>,
131+
source_info: Option<SourceInfo>,
129132
) -> PyResult<()> {
130133
let build = build!(
131134
self.0.delete(key_expr),
@@ -135,12 +138,13 @@ impl Session {
135138
attachment,
136139
timestamp,
137140
allowed_destination,
141+
source_info
138142
);
139143
wait(py, build)
140144
}
141145

142146
#[allow(clippy::too_many_arguments)]
143-
#[pyo3(signature = (selector, handler = None, *, target = None, consolidation = None, timeout = None, congestion_control = None, priority = None, express = None, payload = None, encoding = None, attachment = None, allowed_destination = None))]
147+
#[pyo3(signature = (selector, handler = None, *, target = None, consolidation = None, timeout = None, congestion_control = None, priority = None, express = None, payload = None, encoding = None, attachment = None, allowed_destination = None, source_info = None))]
144148
fn get(
145149
&self,
146150
py: Python,
@@ -158,6 +162,7 @@ impl Session {
158162
#[pyo3(from_py_with = Encoding::from_py_opt)] encoding: Option<Encoding>,
159163
#[pyo3(from_py_with = ZBytes::from_py_opt)] attachment: Option<ZBytes>,
160164
allowed_destination: Option<Locality>,
165+
source_info: Option<SourceInfo>,
161166
) -> PyResult<HandlerImpl<Reply>> {
162167
let (handler, _) = into_handler(py, handler)?;
163168
let builder = build!(
@@ -172,6 +177,7 @@ impl Session {
172177
encoding,
173178
attachment,
174179
allowed_destination,
180+
source_info,
175181
);
176182
wait(py, builder.with(handler)).map_into()
177183
}
@@ -317,7 +323,7 @@ impl SessionInfo {
317323
// TODO __repr__
318324
}
319325

320-
wrapper!(zenoh::session::EntityGlobalId);
326+
wrapper!(zenoh::session::EntityGlobalId: Clone);
321327

322328
#[pymethods]
323329
impl EntityGlobalId {

zenoh/__init__.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class Publisher:
512512
encoding: _IntoEncoding | None = None,
513513
attachment: _IntoZBytes | None = None,
514514
timestamp: Timestamp | None = None,
515+
source_info: SourceInfo | None = None,
515516
):
516517
"""Put data."""
517518

@@ -520,6 +521,7 @@ class Publisher:
520521
*,
521522
attachment: _IntoZBytes | None = None,
522523
timestamp: Timestamp | None = None,
524+
source_info: SourceInfo | None = None,
523525
):
524526
"""Delete data."""
525527

@@ -656,6 +658,7 @@ class Querier:
656658
payload: _IntoZBytes | None = None,
657659
encoding: _IntoEncoding | None = None,
658660
attachment: _IntoZBytes | None = None,
661+
source_info: SourceInfo | None = None,
659662
) -> Handler[Reply]:
660663
"""Sends a query."""
661664

@@ -668,6 +671,7 @@ class Querier:
668671
payload: _IntoZBytes | None = None,
669672
encoding: _IntoEncoding | None = None,
670673
attachment: _IntoZBytes | None = None,
674+
source_info: SourceInfo | None = None,
671675
) -> _H:
672676
"""Sends a query."""
673677

@@ -680,6 +684,7 @@ class Querier:
680684
payload: _IntoZBytes | None = None,
681685
encoding: _IntoEncoding | None = None,
682686
attachment: _IntoZBytes | None = None,
687+
source_info: SourceInfo | None = None,
683688
) -> None:
684689
"""Send a query."""
685690

@@ -805,6 +810,9 @@ class Sample:
805810

806811
@property
807812
def attachment(self) -> ZBytes | None: ...
813+
@_unstable
814+
@property
815+
def source_info(self) -> SourceInfo: ...
808816

809817
@final
810818
class Scout(Generic[_H]):
@@ -907,6 +915,7 @@ class Session:
907915
attachment: _IntoZBytes | None = None,
908916
timestamp: Timestamp | None = None,
909917
allowed_destination: Locality | None = None,
918+
source_info: SourceInfo | None = None,
910919
):
911920
"""Put data on zenoh for a given key expression."""
912921

@@ -920,6 +929,7 @@ class Session:
920929
attachment: _IntoZBytes | None = None,
921930
timestamp: Timestamp | None = None,
922931
allowed_destination: Locality | None = None,
932+
source_info: SourceInfo | None = None,
923933
):
924934
"""Delete data for a given key expression."""
925935

@@ -939,6 +949,7 @@ class Session:
939949
encoding: _IntoEncoding | None = None,
940950
attachment: _IntoZBytes | None = None,
941951
allowed_destination: Locality | None = None,
952+
source_info: SourceInfo | None = None,
942953
) -> Handler[Reply]:
943954
"""Query data from the matching queryables in the system.
944955
Unless explicitly requested via GetBuilder::accept_replies, replies are guaranteed to have key expressions that match the requested selector.
@@ -960,6 +971,7 @@ class Session:
960971
encoding: _IntoEncoding | None = None,
961972
attachment: _IntoZBytes | None = None,
962973
allowed_destination: Locality | None = None,
974+
source_info: SourceInfo | None = None,
963975
) -> _H:
964976
"""Query data from the matching queryables in the system.
965977
Unless explicitly requested via GetBuilder::accept_replies, replies are guaranteed to have key expressions that match the requested selector.
@@ -981,6 +993,7 @@ class Session:
981993
encoding: _IntoEncoding | None = None,
982994
attachment: _IntoZBytes | None = None,
983995
allowed_destination: Locality | None = None,
996+
source_info: SourceInfo | None = None,
984997
) -> None:
985998
"""Query data from the matching queryables in the system.
986999
Unless explicitly requested via GetBuilder::accept_replies, replies are guaranteed to have key expressions that match the requested selector.
@@ -1137,6 +1150,19 @@ class MatchingListener(Generic[_H]):
11371150
@overload
11381151
def __iter__(self) -> Never: ...
11391152

1153+
@_unstable
1154+
@final
1155+
class SourceInfo:
1156+
def __new__(
1157+
cls, source_id: EntityGlobalId | None = None, source_sn: SourceSn | None = None
1158+
) -> Self: ...
1159+
@property
1160+
def source_id(self) -> EntityGlobalId | None: ...
1161+
@property
1162+
def source_sn(self) -> SourceSn | None: ...
1163+
1164+
SourceSn = int
1165+
11401166
@final
11411167
class Subscriber(Generic[_H]):
11421168
"""A subscriber that provides data through a Handler.

0 commit comments

Comments
 (0)