Skip to content

Commit

Permalink
moved api to sealed
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Apr 27, 2024
1 parent b16b18d commit fd0ca47
Show file tree
Hide file tree
Showing 52 changed files with 736 additions and 597 deletions.
60 changes: 57 additions & 3 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub mod key_expr {
pub use zenoh_keyexpr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut};
}
pub use crate::sealed::api::key_expr::KeyExpr;
pub use crate::sealed::api::key_expr::KeyExprUndeclaration;
pub use zenoh_keyexpr::keyexpr;
pub use zenoh_keyexpr::OwnedKeyExpr;
pub use zenoh_keyexpr::SetIntersectionLevel;
Expand All @@ -198,24 +199,42 @@ pub mod session {
#[doc(hidden)]
pub use crate::sealed::api::session::init;
pub use crate::sealed::api::session::open;
#[zenoh_macros::unstable]
#[doc(hidden)]
pub use crate::sealed::api::session::InitBuilder;
pub use crate::sealed::api::session::OpenBuilder;
pub use crate::sealed::api::session::Session;
pub use crate::sealed::api::session::SessionDeclarations;
pub use crate::sealed::api::session::SessionRef;
pub use crate::sealed::api::session::Undeclarable;
}

/// Tools to access information about the current zenoh [`Session`](crate::Session).
pub mod info {
pub use crate::sealed::api::info::PeersZidBuilder;
pub use crate::sealed::api::info::RoutersZidBuilder;
pub use crate::sealed::api::info::SessionInfo;
pub use crate::sealed::api::info::ZidBuilder;
}

/// Sample primitives
pub mod sample {
pub use crate::sealed::api::builders::sample::QoSBuilderTrait;
pub use crate::sealed::api::builders::sample::SampleBuilder;
pub use crate::sealed::api::builders::sample::SampleBuilderAny;
pub use crate::sealed::api::builders::sample::SampleBuilderDelete;
pub use crate::sealed::api::builders::sample::SampleBuilderPut;
pub use crate::sealed::api::builders::sample::SampleBuilderTrait;
pub use crate::sealed::api::builders::sample::TimestampBuilderTrait;
pub use crate::sealed::api::builders::sample::ValueBuilderTrait;
#[zenoh_macros::unstable]
pub use crate::sealed::api::sample::Locality;
pub use crate::sealed::api::sample::Sample;
pub use crate::sealed::api::sample::SampleFields;
pub use crate::sealed::api::sample::SampleKind;
#[zenoh_macros::unstable]
pub use crate::sealed::api::sample::SourceInfo;
pub use crate::sealed::api::sample::SourceSn;
}

/// Value primitives
Expand All @@ -231,10 +250,14 @@ pub mod encoding {
/// Payload primitives
pub mod bytes {
pub use crate::sealed::api::bytes::Deserialize;
pub use crate::sealed::api::bytes::OptionZBytes;
pub use crate::sealed::api::bytes::Serialize;
pub use crate::sealed::api::bytes::StringOrBase64;
pub use crate::sealed::api::bytes::ZBytes;
pub use crate::sealed::api::bytes::ZBytesIterator;
pub use crate::sealed::api::bytes::ZBytesReader;
pub use crate::sealed::api::bytes::ZBytesWriter;
pub use crate::sealed::api::bytes::ZDeserializeError;
pub use crate::sealed::api::bytes::ZSerde;
}

Expand All @@ -258,18 +281,33 @@ pub mod subscriber {

/// Publishing primitives
pub mod publication {
pub use crate::sealed::api::builders::publication::PublicationBuilderDelete;
pub use crate::sealed::api::builders::publication::PublicationBuilderPut;
pub use crate::sealed::api::builders::publication::PublisherBuilder;
pub use crate::sealed::api::builders::publication::PublisherDeleteBuilder;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::MatchingListener;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::MatchingListenerBuilder;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::MatchingListenerState;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::MatchingListenerUndeclaration;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::MatchingStatus;
pub use crate::sealed::api::publication::Priority;
pub use crate::sealed::api::publication::Publisher;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::PublisherDeclarations;
#[zenoh_macros::unstable]
pub use crate::sealed::api::publication::PublisherRef;
pub use crate::sealed::api::publication::PublisherUndeclaration;
pub use zenoh_protocol::core::CongestionControl;
}

/// Query primitives
pub mod query {
pub use crate::sealed::api::query::GetBuilder;
pub use crate::sealed::api::query::Reply;
#[zenoh_macros::unstable]
pub use crate::sealed::api::query::ReplyKeyExpr;
Expand All @@ -283,19 +321,31 @@ pub mod queryable {
pub use crate::sealed::api::queryable::Query;
pub use crate::sealed::api::queryable::Queryable;
pub use crate::sealed::api::queryable::QueryableBuilder;
pub use crate::sealed::api::queryable::QueryableUndeclaration;
pub use crate::sealed::api::queryable::ReplyBuilder;
pub use crate::sealed::api::queryable::ReplyBuilderDelete;
pub use crate::sealed::api::queryable::ReplyBuilderPut;
pub use crate::sealed::api::queryable::ReplyErrBuilder;
#[zenoh_macros::unstable]
pub use crate::sealed::api::queryable::ReplySample;
}

/// Callback handler trait
pub mod handlers {
pub use crate::sealed::api::handlers::locked;
pub use crate::sealed::api::handlers::callback::locked;
pub use crate::sealed::api::handlers::callback::Callback;
pub use crate::sealed::api::handlers::callback::CallbackDrop;
pub use crate::sealed::api::handlers::fifo::FifoChannel;
pub use crate::sealed::api::handlers::ring::RingChannel;
pub use crate::sealed::api::handlers::ring::RingChannelHandler;
pub use crate::sealed::api::handlers::DefaultHandler;
pub use crate::sealed::api::handlers::IntoHandler;
pub use crate::sealed::api::handlers::RingChannel;
}

/// Scouting primitives
pub mod scouting {
pub use crate::sealed::api::scouting::scout;
pub use crate::sealed::api::scouting::Scout;
pub use crate::sealed::api::scouting::ScoutBuilder;
/// Constants and helpers for zenoh `whatami` flags.
pub use zenoh_protocol::core::WhatAmI;
Expand All @@ -307,8 +357,11 @@ pub mod scouting {
#[cfg(feature = "unstable")]
pub mod liveliness {
pub use crate::sealed::api::liveliness::Liveliness;
pub use crate::sealed::api::liveliness::LivelinessGetBuilder;
pub use crate::sealed::api::liveliness::LivelinessSubscriberBuilder;
pub use crate::sealed::api::liveliness::LivelinessToken;
pub use crate::sealed::api::liveliness::LivelinessTokenBuilder;
pub use crate::sealed::api::liveliness::LivelinessTokenUndeclaration;
}

/// Timestamp support
Expand All @@ -322,7 +375,7 @@ pub mod time {
#[doc(hidden)]
pub mod runtime {
pub use crate::sealed::net::runtime::RuntimeBuilder;
pub use crate::sealed::net::runtime::{AdminSpace, Runtime};
pub use crate::sealed::net::runtime::{adminspace::AdminSpace, Runtime};
pub use zenoh_runtime::ZRuntime;
}

Expand All @@ -341,6 +394,7 @@ pub mod plugins {
pub use crate::sealed::api::plugins::PluginsManager;
pub use crate::sealed::api::plugins::Response;
pub use crate::sealed::api::plugins::RunningPlugin;
pub use crate::sealed::api::plugins::PLUGIN_PREFIX;
pub use crate::sealed::api::plugins::{RunningPluginTrait, ZenohPlugin};
}

Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! ```
// Reexport API in flat namespace
pub(crate) mod flat {
pub mod flat {
pub use crate::buffers::*;
pub use crate::bytes::*;
pub use crate::config::*;
Expand All @@ -59,7 +59,7 @@ pub(crate) mod flat {
}

// Reexport API in hierarchical namespace
pub(crate) mod mods {
pub mod mods {
pub use crate::buffers;
pub use crate::bytes;
pub use crate::config;
Expand Down
16 changes: 8 additions & 8 deletions zenoh/src/sealed/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lazy_static::lazy_static!(
static ref KE_LINK: &'static keyexpr = ke_for_sure!("link");
);

pub(crate) fn init(session: &Session) {
pub(in crate::sealed) fn init(session: &Session) {
if let Ok(own_zid) = keyexpr::new(&session.zid().to_string()) {
let admin_key = KeyExpr::from(*KE_PREFIX / own_zid / *KE_STARSTAR)
.to_wire(session)
Expand All @@ -63,7 +63,7 @@ pub(crate) fn init(session: &Session) {
}
}

pub(crate) fn on_admin_query(session: &Session, query: Query) {
pub(in crate::sealed) fn on_admin_query(session: &Session, query: Query) {
fn reply_peer(own_zid: &keyexpr, query: &Query, peer: TransportPeer) {
let zid = peer.zid.to_string();
if let Ok(zid) = keyexpr::new(&zid) {
Expand Down Expand Up @@ -119,12 +119,12 @@ pub(crate) fn on_admin_query(session: &Session, query: Query) {
}

#[derive(Clone)]
pub(crate) struct Handler {
pub(crate) session: Arc<Session>,
pub(in crate::sealed) struct Handler {
pub(in crate::sealed) session: Arc<Session>,
}

impl Handler {
pub(crate) fn new(session: Session) -> Self {
pub(in crate::sealed) fn new(session: Session) -> Self {
Self {
session: Arc::new(session),
}
Expand Down Expand Up @@ -190,9 +190,9 @@ impl TransportMulticastEventHandler for Handler {
}
}

pub(crate) struct PeerHandler {
pub(crate) expr: WireExpr<'static>,
pub(crate) session: Arc<Session>,
pub(in crate::sealed) struct PeerHandler {
pub(in crate::sealed) expr: WireExpr<'static>,
pub(in crate::sealed) session: Arc<Session>,
}

impl TransportPeerEventHandler for PeerHandler {
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/sealed/api/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
// ZettaScale Zenoh Team, <[email protected]>
//

pub(crate) mod publication;
pub(crate) mod sample;
pub mod publication;
pub mod sample;
26 changes: 13 additions & 13 deletions zenoh/src/sealed/api/builders/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub type PublisherDeleteBuilder<'a> =

#[derive(Debug, Clone)]
pub struct PublicationBuilderPut {
pub(crate) payload: ZBytes,
pub(crate) encoding: Encoding,
pub(in crate::sealed) payload: ZBytes,
pub(in crate::sealed) encoding: Encoding,
}
#[derive(Debug, Clone)]
pub struct PublicationBuilderDelete;
Expand All @@ -74,13 +74,13 @@ pub struct PublicationBuilderDelete;
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug, Clone)]
pub struct PublicationBuilder<P, T> {
pub(crate) publisher: P,
pub(crate) kind: T,
pub(crate) timestamp: Option<uhlc::Timestamp>,
pub(in crate::sealed) publisher: P,
pub(in crate::sealed) kind: T,
pub(in crate::sealed) timestamp: Option<uhlc::Timestamp>,
#[cfg(feature = "unstable")]
pub(crate) source_info: SourceInfo,
pub(in crate::sealed) source_info: SourceInfo,
#[cfg(feature = "unstable")]
pub(crate) attachment: Option<ZBytes>,
pub(in crate::sealed) attachment: Option<ZBytes>,
}

impl<T> QoSBuilderTrait for PublicationBuilder<PublisherBuilder<'_, '_>, T> {
Expand Down Expand Up @@ -251,12 +251,12 @@ impl AsyncResolve for PublicationBuilder<PublisherBuilder<'_, '_>, PublicationBu
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct PublisherBuilder<'a, 'b: 'a> {
pub(crate) session: SessionRef<'a>,
pub(crate) key_expr: ZResult<KeyExpr<'b>>,
pub(crate) congestion_control: CongestionControl,
pub(crate) priority: Priority,
pub(crate) is_express: bool,
pub(crate) destination: Locality,
pub(in crate::sealed) session: SessionRef<'a>,
pub(in crate::sealed) key_expr: ZResult<KeyExpr<'b>>,
pub(in crate::sealed) congestion_control: CongestionControl,
pub(in crate::sealed) priority: Priority,
pub(in crate::sealed) is_express: bool,
pub(in crate::sealed) destination: Locality,
}

impl<'a, 'b> Clone for PublisherBuilder<'a, 'b> {
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/sealed/api/builders/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<T> SampleBuilder<T> {
}

// Allows to change qos as a whole of [`Sample`]
pub(crate) fn qos(self, qos: QoS) -> Self {
pub(in crate::sealed) fn qos(self, qos: QoS) -> Self {
Self {
sample: Sample { qos, ..self.sample },
_t: PhantomData::<T>,
Expand Down
13 changes: 5 additions & 8 deletions zenoh/src/sealed/api/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@
//

//! Callback handler trait.
mod callback;
mod fifo;
mod ring;

pub use callback::*;
pub use fifo::*;
pub use ring::*;
pub mod callback;
pub mod fifo;
pub mod ring;

use self::{callback::Callback, fifo::FifoChannel};
use crate::sealed::api::session::API_DATA_RECEPTION_CHANNEL_SIZE;

/// An alias for `Arc<T>`.
pub type Dyn<T> = std::sync::Arc<T>;
pub(in crate::sealed) type Dyn<T> = std::sync::Arc<T>;

/// A type that can be converted into a [`Callback`]-Handler pair.
///
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/sealed/api/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use zenoh_protocol::core::{WhatAmI, ZenohId};
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct ZidBuilder<'a> {
pub(crate) session: SessionRef<'a>,
pub(in crate::sealed) session: SessionRef<'a>,
}

impl<'a> Resolvable for ZidBuilder<'a> {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'a> AsyncResolve for ZidBuilder<'a> {
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct RoutersZidBuilder<'a> {
pub(crate) session: SessionRef<'a>,
pub(in crate::sealed) session: SessionRef<'a>,
}

impl<'a> Resolvable for RoutersZidBuilder<'a> {
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'a> AsyncResolve for RoutersZidBuilder<'a> {
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct PeersZidBuilder<'a> {
pub(crate) session: SessionRef<'a>,
pub(in crate::sealed) session: SessionRef<'a>,
}

impl<'a> Resolvable for PeersZidBuilder<'a> {
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'a> AsyncResolve for PeersZidBuilder<'a> {
/// # }
/// ```
pub struct SessionInfo<'a> {
pub(crate) session: SessionRef<'a>,
pub(in crate::sealed) session: SessionRef<'a>,
}

impl SessionInfo<'_> {
Expand Down
10 changes: 5 additions & 5 deletions zenoh/src/sealed/api/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use zenoh_protocol::{
use zenoh_result::ZResult;

#[derive(Clone, Debug)]
pub(crate) enum KeyExprInner<'a> {
pub(in crate::sealed) enum KeyExprInner<'a> {
Borrowed(&'a keyexpr),
BorrowedWire {
key_expr: &'a keyexpr,
Expand All @@ -54,7 +54,7 @@ pub(crate) enum KeyExprInner<'a> {
#[derive(Clone, serde::Deserialize, serde::Serialize)]
#[serde(from = "OwnedKeyExpr")]
#[serde(into = "OwnedKeyExpr")]
pub struct KeyExpr<'a>(pub(crate) KeyExprInner<'a>);
pub struct KeyExpr<'a>(pub(in crate::sealed) KeyExprInner<'a>);
impl std::ops::Deref for KeyExpr<'_> {
type Target = keyexpr;
fn deref(&self) -> &Self::Target {
Expand Down Expand Up @@ -487,10 +487,10 @@ impl std::ops::Div<&keyexpr> for &KeyExpr<'_> {
}

impl<'a> KeyExpr<'a> {
//pub(crate) fn is_optimized(&self, session: &Session) -> bool {
//pub(in crate::sealed) fn is_optimized(&self, session: &Session) -> bool {
// matches!(&self.0, KeyExprInner::Wire { expr_id, session_id, .. } | KeyExprInner::BorrowedWire { expr_id, session_id, .. } if *expr_id != 0 && session.id == *session_id)
//}
pub(crate) fn is_fully_optimized(&self, session: &Session) -> bool {
pub(in crate::sealed) fn is_fully_optimized(&self, session: &Session) -> bool {
match &self.0 {
KeyExprInner::Wire {
key_expr,
Expand All @@ -507,7 +507,7 @@ impl<'a> KeyExpr<'a> {
_ => false,
}
}
pub(crate) fn to_wire(&'a self, session: &Session) -> WireExpr<'a> {
pub(in crate::sealed) fn to_wire(&'a self, session: &Session) -> WireExpr<'a> {
match &self.0 {
KeyExprInner::Wire {
key_expr,
Expand Down
Loading

0 comments on commit fd0ca47

Please sign in to comment.