-
Notifications
You must be signed in to change notification settings - Fork 0
phase 20c: EventPublisherHandle trait + drop Arc<EventPublisher> requ… #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/phase20b_sd_state_handle
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ mod service_info; | |||||||||||||||||||||||||||||||||
| mod subscription_manager; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| pub use error::Error; | ||||||||||||||||||||||||||||||||||
| pub use event_publisher::EventPublisher; | ||||||||||||||||||||||||||||||||||
| pub use event_publisher::{EventPublisher, EventPublisherHandle, WrappableEventPublisherHandle}; | ||||||||||||||||||||||||||||||||||
| pub use service_info::Subscriber; | ||||||||||||||||||||||||||||||||||
| #[cfg(feature = "std")] | ||||||||||||||||||||||||||||||||||
| pub use service_info::{EventGroupInfo, ServiceInfo}; | ||||||||||||||||||||||||||||||||||
|
|
@@ -143,15 +143,23 @@ where | |||||||||||||||||||||||||||||||||
| /// these as `Arc<Mutex<E2ERegistry>>` / `Arc<RwLock<SubscriptionManager>>` | ||||||||||||||||||||||||||||||||||
| /// / `TokioTransport` / `TokioTimer`. Bare-metal callers use | ||||||||||||||||||||||||||||||||||
| /// [`Self::new_with_deps`] (under `server`) and supply their own. | ||||||||||||||||||||||||||||||||||
| pub struct Server<R, S, F, Tm, H = Arc<<F as TransportFactory>::Socket>, Hsd = Arc<SdStateManager>> | ||||||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||||||
| pub struct Server< | ||||||||||||||||||||||||||||||||||
| R, | ||||||||||||||||||||||||||||||||||
| S, | ||||||||||||||||||||||||||||||||||
| F, | ||||||||||||||||||||||||||||||||||
| Tm, | ||||||||||||||||||||||||||||||||||
| H = Arc<<F as TransportFactory>::Socket>, | ||||||||||||||||||||||||||||||||||
| Hsd = Arc<SdStateManager>, | ||||||||||||||||||||||||||||||||||
| Hep = Arc<EventPublisher<R, S, H>>, | ||||||||||||||||||||||||||||||||||
| > where | ||||||||||||||||||||||||||||||||||
| R: E2ERegistryHandle, | ||||||||||||||||||||||||||||||||||
| S: SubscriptionHandle, | ||||||||||||||||||||||||||||||||||
| F: TransportFactory + 'static, | ||||||||||||||||||||||||||||||||||
| F::Socket: 'static, | ||||||||||||||||||||||||||||||||||
| Tm: Timer + Clone + 'static, | ||||||||||||||||||||||||||||||||||
| H: SocketHandle<Socket = F::Socket>, | ||||||||||||||||||||||||||||||||||
| Hsd: SdStateHandle, | ||||||||||||||||||||||||||||||||||
| Hep: EventPublisherHandle<R, S, H>, | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| config: ServerConfig, | ||||||||||||||||||||||||||||||||||
| /// Socket for receiving subscription requests, behind whatever | ||||||||||||||||||||||||||||||||||
|
|
@@ -163,8 +171,10 @@ where | |||||||||||||||||||||||||||||||||
| sd_socket: H, | ||||||||||||||||||||||||||||||||||
| /// Subscription manager | ||||||||||||||||||||||||||||||||||
| subscriptions: S, | ||||||||||||||||||||||||||||||||||
| /// Event publisher | ||||||||||||||||||||||||||||||||||
| publisher: Arc<EventPublisher<R, S, H>>, | ||||||||||||||||||||||||||||||||||
| /// Event publisher, behind whatever shared-storage `Hep` chose | ||||||||||||||||||||||||||||||||||
| /// (`Arc<EventPublisher<R, S, H>>` on std, | ||||||||||||||||||||||||||||||||||
| /// `&'static EventPublisher<R, S, H>` on bare-metal-no-alloc). | ||||||||||||||||||||||||||||||||||
| publisher: Hep, | ||||||||||||||||||||||||||||||||||
| /// SD session-ID counter and announcement emitter, behind whatever | ||||||||||||||||||||||||||||||||||
| /// shared-storage `Hsd` chose (`Arc<SdStateManager>` on std, | ||||||||||||||||||||||||||||||||||
| /// `&'static SdStateManager` on bare-metal-no-alloc). | ||||||||||||||||||||||||||||||||||
|
|
@@ -282,7 +292,7 @@ impl | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| impl<R, S, F, Tm, H, Hsd> Server<R, S, F, Tm, H, Hsd> | ||||||||||||||||||||||||||||||||||
| impl<R, S, F, Tm, H, Hsd, Hep> Server<R, S, F, Tm, H, Hsd, Hep> | ||||||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||||||
| R: E2ERegistryHandle, | ||||||||||||||||||||||||||||||||||
| S: SubscriptionHandle, | ||||||||||||||||||||||||||||||||||
|
|
@@ -291,6 +301,7 @@ where | |||||||||||||||||||||||||||||||||
| Tm: Timer + Clone + 'static, | ||||||||||||||||||||||||||||||||||
| H: WrappableSocketHandle<Socket = F::Socket>, | ||||||||||||||||||||||||||||||||||
| Hsd: WrappableSdStateHandle, | ||||||||||||||||||||||||||||||||||
| Hep: WrappableEventPublisherHandle<R, S, H>, | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| /// Bare-metal-friendly constructor that takes every dependency | ||||||||||||||||||||||||||||||||||
| /// explicitly via a [`ServerDeps`] bundle. The `server-tokio` | ||||||||||||||||||||||||||||||||||
|
|
@@ -358,7 +369,7 @@ where | |||||||||||||||||||||||||||||||||
| sd::MULTICAST_IP | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let publisher = Arc::new(EventPublisher::new( | ||||||||||||||||||||||||||||||||||
| let publisher = Hep::wrap(EventPublisher::new( | ||||||||||||||||||||||||||||||||||
| subscriptions.clone(), | ||||||||||||||||||||||||||||||||||
| unicast_socket.clone(), | ||||||||||||||||||||||||||||||||||
| e2e_registry.clone(), | ||||||||||||||||||||||||||||||||||
|
|
@@ -428,7 +439,7 @@ where | |||||||||||||||||||||||||||||||||
| sd_placeholder_addr | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let publisher = Arc::new(EventPublisher::new( | ||||||||||||||||||||||||||||||||||
| let publisher = Hep::wrap(EventPublisher::new( | ||||||||||||||||||||||||||||||||||
| subscriptions.clone(), | ||||||||||||||||||||||||||||||||||
| unicast_socket.clone(), | ||||||||||||||||||||||||||||||||||
| e2e_registry.clone(), | ||||||||||||||||||||||||||||||||||
|
|
@@ -450,7 +461,7 @@ where | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| impl<R, S, F, Tm, H, Hsd> Server<R, S, F, Tm, H, Hsd> | ||||||||||||||||||||||||||||||||||
| impl<R, S, F, Tm, H, Hsd, Hep> Server<R, S, F, Tm, H, Hsd, Hep> | ||||||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||||||
| R: E2ERegistryHandle, | ||||||||||||||||||||||||||||||||||
| S: SubscriptionHandle, | ||||||||||||||||||||||||||||||||||
|
|
@@ -459,6 +470,7 @@ where | |||||||||||||||||||||||||||||||||
| Tm: Timer + Clone + 'static, | ||||||||||||||||||||||||||||||||||
| H: SocketHandle<Socket = F::Socket>, | ||||||||||||||||||||||||||||||||||
| Hsd: SdStateHandle, | ||||||||||||||||||||||||||||||||||
| Hep: EventPublisherHandle<R, S, H>, | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| /// Build the periodic-SD-announcement future. | ||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||
|
|
@@ -694,10 +706,14 @@ where | |||||||||||||||||||||||||||||||||
| Ok(()) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Get the event publisher for sending events | ||||||||||||||||||||||||||||||||||
| /// Get a clone of the event-publisher handle for sending events. | ||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||
| /// Returns the [`EventPublisherHandle`] type — `Arc<EventPublisher<R, | ||||||||||||||||||||||||||||||||||
| /// S, H>>` for std users (the default `Hep`), | ||||||||||||||||||||||||||||||||||
| /// `&'static EventPublisher<R, S, H>` for bare-metal-no-alloc. | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+709
to
+713
|
||||||||||||||||||||||||||||||||||
| /// Get a clone of the event-publisher handle for sending events. | |
| /// | |
| /// Returns the [`EventPublisherHandle`] type — `Arc<EventPublisher<R, | |
| /// S, H>>` for std users (the default `Hep`), | |
| /// `&'static EventPublisher<R, S, H>` for bare-metal-no-alloc. | |
| /// Get a clone of the configured event-publisher handle. | |
| /// | |
| /// This returns the generic handle type `Hep` implementing | |
| /// [`EventPublisherHandle`]. For the default handle types this is typically | |
| /// `Arc<EventPublisher<R, S, H>>` on `std` and | |
| /// `&'static EventPublisher<R, S, H>` on bare-metal-no-alloc. | |
| /// | |
| /// Callers using a custom `Hep` implementation should use the | |
| /// [`EventPublisherHandle`] trait to borrow/access the underlying | |
| /// [`EventPublisher`] before calling publisher methods such as | |
| /// `publish_event`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs/examples here assume callers can do
server.publisher().publish_event(...), butServer::publisher()now returns the genericHephandle andEventPublisherHandledoes not requireDeref<Target = EventPublisher<...>>. That call pattern only works for the built-inArc<_>/&'static _handles (via deref), and will not compile for other valid handle types. Consider updating the docs to show the trait-based access pattern (e.g., borrowing viaEventPublisherHandle::publisher()), or alternatively add aDerefbound if direct method calls on the handle are intended to be a guaranteed API.