diff --git a/score/mw/com/impl/rust/com-api/com-api-concept/com_api_concept.rs b/score/mw/com/impl/rust/com-api/com-api-concept/com_api_concept.rs index 08db9a69b..ac1862c46 100644 --- a/score/mw/com/impl/rust/com-api/com-api-concept/com_api_concept.rs +++ b/score/mw/com/impl/rust/com-api/com-api-concept/com_api_concept.rs @@ -269,7 +269,9 @@ impl InstanceSpecifier { specifier: service_name.to_string(), }) } else { - Err(Error::ServiceError(ServiceFailedReason::InstanceSpecifierInvalid)) + Err(Error::ServiceError( + ServiceFailedReason::InstanceSpecifierInvalid, + )) } } } @@ -705,9 +707,9 @@ impl SampleContainer { /// # Errors /// Returns 'Error::AllocateError' if container is already full. pub fn push_back(&mut self, new: S) -> Result<()> { - self.inner.push_back(new).map_err(|_| { - Error::AllocateError(AllocationFailureReason::OutOfMemory) - })?; + self.inner + .push_back(new) + .map_err(|_| Error::AllocateError(AllocationFailureReason::OutOfMemory))?; Ok(()) } @@ -736,6 +738,22 @@ impl SampleContainer { /// Represents a live subscription to an event source with methods for both /// non-blocking polling and asynchronous waiting for new events. /// +/// # Sample Selection Algorithm +/// +/// The internal algorithm for sample delivery works as follows: +/// - Searches for the slot with the largest timestamp in the range `(last_reference_time, upper_limit)` +/// - On each successive call within the same receive operation, `upper_limit` is narrowed to the +/// previously found timestamp, ensuring the next search returns the next-newest sample +/// - After the call completes, `last_reference_time` is advanced to the newest delivered timestamp, +/// preventing those samples from being returned again +/// +/// **Example**: If the producer sent samples with timestamps T1 < T2 < T3 before the first receive, +/// and `max_samples = 2`: +/// - 1st iteration: search `(0, MAX)` → finds T3 +/// - 2nd iteration: search `(0, T3)` → finds T2 +/// - **Result**: Delivers 2 newest samples (T3 and T2). Sample T1 is permanently skipped because +/// `last_reference_time` advances to T3 after this receive call. +/// /// # Type Parameters /// * `T` - The relocatable event data type /// * `R` - The runtime managing the subscription diff --git a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/consumer.rs b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/consumer.rs index d218d55f8..73c8f90f5 100644 --- a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/consumer.rs +++ b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/consumer.rs @@ -16,7 +16,7 @@ //! that can subscribe to events and receive data samples. //! It uses FFI to interact with the underlying C++ implementation. //! Main components include `LolaConsumerInfo`, `SubscribableImpl`, -//! `SubscriberImpl`, `SampleConsumerDiscovery`, and `SampleConsumerBuilder`. +//! `SubscriberImpl`, `LolaConsumerDiscovery`, and `LolaConsumerBuilder`. //! These components work together to enable consumers to discover services, //! subscribe to events, and receive data samples in a type-safe manner. //! The implementation ensures proper memory management and resource handling @@ -35,6 +35,7 @@ use core::marker::PhantomData; use core::mem::ManuallyDrop; use core::ops::{Deref, DerefMut}; use core::panic; +use core::ptr::NonNull; use futures::task::{AtomicWaker, Context, Poll}; use std::cmp::Ordering; use std::pin::Pin; @@ -197,7 +198,7 @@ impl std::fmt::Debug for ProxyInstanceManager { /// it must not expose any mutable access to the proxy instance /// Or must not provide any method to access the proxy instance directly pub struct NativeProxyBase { - proxy: *mut ProxyBase, // Stores the proxy instance + proxy: NonNull, // Stores the proxy instance } //SAFETY: NativeProxyBase is safe to share between threads because: @@ -213,7 +214,7 @@ impl Drop for NativeProxyBase { //SAFETY: It is safe to destroy the proxy because it was created by FFI // and proxy pointer received at the time of create_proxy called unsafe { - bridge_ffi_rs::destroy_proxy(self.proxy); + bridge_ffi_rs::destroy_proxy(self.proxy.as_ptr()); } } } @@ -228,12 +229,10 @@ impl NativeProxyBase { pub fn new(interface_id: &str, handle: &HandleType) -> Result { //SAFETY: It is safe to create the proxy because interface_id and handle are valid //Handle received at the time of get_avaible_instances called with correct interface_id - let proxy = unsafe { bridge_ffi_rs::create_proxy(interface_id, handle) }; - if proxy.is_null() { - return Err(Error::ConsumerError( - ConsumerFailedReason::ProxyCreationFailed, - )); - } + let raw_proxy_ptr = unsafe { bridge_ffi_rs::create_proxy(interface_id, handle) }; + let proxy = std::ptr::NonNull::new(raw_proxy_ptr).ok_or(Error::ConsumerError( + ConsumerFailedReason::ProxyCreationFailed, + ))?; Ok(Self { proxy }) } } @@ -245,7 +244,7 @@ impl NativeProxyBase { /// And the proxy event lifetime is managed safely through Drop of the parent proxy instance /// user can get the raw pointer using 'get_proxy_event_base' method pub struct NativeProxyEventBase { - proxy_event_ptr: *mut ProxyEventBase, + proxy_event_ptr: NonNull, } //SAFETY: NativeProxyEventBase is to send between threads because: @@ -256,14 +255,13 @@ pub struct NativeProxyEventBase { unsafe impl Send for NativeProxyEventBase {} impl NativeProxyEventBase { - pub fn new(proxy: *mut ProxyBase, interface_id: &str, identifier: &str) -> Result { + pub fn new(proxy: &NonNull, interface_id: &str, identifier: &str) -> Result { //SAFETY: It is safe as we are passing valid proxy pointer and interface id to get event // proxy pointer is created during consumer creation - let proxy_event_ptr = - unsafe { bridge_ffi_rs::get_event_from_proxy(proxy, interface_id, identifier) }; - if proxy_event_ptr.is_null() { - return Err(Error::EventError(EventFailedReason::EventCreationFailed)); - } + let raw_event_ptr = + unsafe { bridge_ffi_rs::get_event_from_proxy(proxy.as_ptr(), interface_id, identifier) }; + let proxy_event_ptr = std::ptr::NonNull::new(raw_event_ptr) + .ok_or(Error::EventError(EventFailedReason::EventCreationFailed))?; Ok(Self { proxy_event_ptr }) } @@ -271,11 +269,7 @@ impl NativeProxyEventBase { pub fn get_proxy_event_base(&self) -> &ProxyEventBase { // SAFETY: proxy_event_ptr is valid for the entire lifetime of NativeProxyEventBase // and was created by FFI during get_event_from_proxy() - unsafe { - self.proxy_event_ptr - .as_ref() - .expect("Event pointer is null") - } + unsafe { self.proxy_event_ptr.as_ref() } } } @@ -311,7 +305,7 @@ impl Subscriber for SubscribableImpl fn subscribe(self, max_num_samples: usize) -> Result { let instance_info = self.instance_info.clone(); let event_instance = NativeProxyEventBase::new( - self.proxy_instance.0.proxy, + &self.proxy_instance.0.proxy, self.instance_info.interface_id, self.identifier, )?; @@ -335,7 +329,7 @@ impl Subscriber for SubscribableImpl max_num_samples, instance_info, waker_storage: Arc::default(), - async_init_status: AtomicBool::new(false), + async_init_status: std::sync::Once::new(), _proxy: self.proxy_instance.clone(), _phantom: PhantomData, }) @@ -441,7 +435,7 @@ where max_num_samples: usize, instance_info: LolaConsumerInfo, waker_storage: Arc, - async_init_status: AtomicBool, + async_init_status: std::sync::Once, _proxy: ProxyInstanceManager, _phantom: PhantomData, } @@ -455,9 +449,8 @@ impl Drop for SubscriberImpl { // and then unsubscribe from the event to clean up resources on the C++ side. let mut guard = self.event.get_proxy_event(); unsafe { - if self - .async_init_status - .load(std::sync::atomic::Ordering::Relaxed) + if self.async_init_status.is_completed() + // Check if the async receive callback was initialized { bridge_ffi_rs::clear_event_receive_handler(guard.deref_mut(), T::ID); } @@ -564,18 +557,11 @@ where // on the same subscriber instance. let mut event_guard = self.event.get_proxy_event(); // Initialize the async receive callback only once when the first receive call is made - if !self - .async_init_status - .load(std::sync::atomic::Ordering::Relaxed) - { - if let Err(_e) = self.init_async_receive(&mut event_guard) { - return Err(Error::ReceiveError( - ReceiveFailedReason::InitializationFailed, - )); - } - self.async_init_status - .store(true, std::sync::atomic::Ordering::Relaxed); - } + // We are using std::sync::Once to ensure that the callback is set only once. + self.async_init_status.call_once(|| { + self.init_async_receive(&mut event_guard) + .expect("Failed to initialize async receive callback"); + }); ReceiveFuture { event_guard: Some(event_guard), waker_storage: Arc::clone(&self.waker_storage), @@ -687,12 +673,12 @@ impl std::fmt::Debug for DiscoveryStateData { } } -pub struct SampleConsumerDiscovery { +pub struct LolaConsumerDiscovery { pub instance_specifier: InstanceSpecifier, pub _interface: PhantomData, } -impl SampleConsumerDiscovery { +impl LolaConsumerDiscovery { pub fn new(_runtime: &LolaRuntimeImpl, instance_specifier: InstanceSpecifier) -> Self { Self { instance_specifier, @@ -701,12 +687,12 @@ impl SampleConsumerDiscovery { } } -impl ServiceDiscovery for SampleConsumerDiscovery +impl ServiceDiscovery for LolaConsumerDiscovery where - SampleConsumerBuilder: ConsumerBuilder, + LolaConsumerBuilder: ConsumerBuilder, { - type ConsumerBuilder = SampleConsumerBuilder; - type ServiceEnumerator = Vec>; + type ConsumerBuilder = LolaConsumerBuilder; + type ServiceEnumerator = Vec>; fn get_available_instances(&self) -> Result { //If ANY Support is added in Lola, then we need to return all available instances @@ -726,7 +712,7 @@ where handle_index, interface_id: I::INTERFACE_ID, }; - SampleConsumerBuilder { + LolaConsumerBuilder { instance_info, _interface: PhantomData, } @@ -848,7 +834,7 @@ impl Drop for ServiceDiscoveryFuture { } impl Future for ServiceDiscoveryFuture { - type Output = Result>>; + type Output = Result>>; fn poll( self: std::pin::Pin<&mut Self>, @@ -881,7 +867,7 @@ impl Future for ServiceDiscoveryFuture { handle_index, interface_id: I::INTERFACE_ID, }; - SampleConsumerBuilder { + LolaConsumerBuilder { instance_info, _interface: PhantomData, } @@ -895,20 +881,20 @@ impl Future for ServiceDiscoveryFuture { } } -impl ConsumerBuilder for SampleConsumerBuilder {} +impl ConsumerBuilder for LolaConsumerBuilder {} -impl Builder> for SampleConsumerBuilder { +impl Builder> for LolaConsumerBuilder { fn build(self) -> Result> { Ok(Consumer::new(self.instance_info)) } } -pub struct SampleConsumerBuilder { +pub struct LolaConsumerBuilder { pub instance_info: LolaConsumerInfo, pub _interface: PhantomData, } -impl ConsumerDescriptor for SampleConsumerBuilder { +impl ConsumerDescriptor for LolaConsumerBuilder { fn get_instance_identifier(&self) -> &InstanceSpecifier { //if InstanceSpecifier::ANY support enable by lola //then this API should get InstanceSpecifier from FFI Call @@ -1107,11 +1093,11 @@ mod test { #[test] fn test_sample_consumer_discovery_creation() { - // Test that SampleConsumerDiscovery can be created with valid interface + // Test that LolaConsumerDiscovery can be created with valid interface let instance_specifier = com_api_concept::InstanceSpecifier::new("/test/vehicle") .expect("Failed to create instance specifier"); - let _discovery = super::SampleConsumerDiscovery::::new( + let _discovery = super::LolaConsumerDiscovery::::new( &super::super::LolaRuntimeImpl {}, instance_specifier, ); @@ -1125,7 +1111,7 @@ mod test { let instance_specifier = com_api_concept::InstanceSpecifier::new("/test/vehicle") .expect("Failed to create instance specifier"); - let discovery = super::SampleConsumerDiscovery::::new( + let discovery = super::LolaConsumerDiscovery::::new( &super::super::LolaRuntimeImpl {}, instance_specifier, ); diff --git a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/lib.rs b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/lib.rs index 1d092dc3c..a1c958ff7 100644 --- a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/lib.rs +++ b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/lib.rs @@ -29,9 +29,9 @@ mod consumer; mod producer; mod runtime; -pub use consumer::{LolaConsumerInfo, Sample, SampleConsumerDiscovery, SubscribableImpl}; +pub use consumer::{LolaConsumerInfo, Sample, LolaConsumerDiscovery, SubscribableImpl}; pub use producer::{ - LolaProviderInfo, Publisher, SampleMaybeUninit, SampleMut, SampleProducerBuilder, + LolaProviderInfo, Publisher, SampleMaybeUninit, SampleMut, LolaProducerBuilder, }; pub use runtime::{LolaRuntimeImpl, RuntimeBuilderImpl}; diff --git a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/producer.rs b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/producer.rs index 13c93f5cb..4d9799ac1 100644 --- a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/producer.rs +++ b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/producer.rs @@ -33,6 +33,7 @@ use crate::Debug; use core::marker::PhantomData; use core::mem::ManuallyDrop; use core::ops::{Deref, DerefMut}; +use std::ptr::NonNull; use std::sync::Arc; use com_api_concept::{ @@ -56,8 +57,9 @@ impl ProviderInfo for LolaProviderInfo { fn offer_service(&self) -> Result<()> { //SAFETY: it is safe as we are passing valid skeleton handle to offer service // the skeleton handle is created during building the provider info instance - let status = - unsafe { bridge_ffi_rs::skeleton_offer_service(self.skeleton_handle.0.handle) }; + let status = unsafe { + bridge_ffi_rs::skeleton_offer_service(self.skeleton_handle.0.handle.as_ptr()) + }; if !status { return Err(Error::ServiceError(ServiceFailedReason::OfferServiceFailed)); } @@ -67,7 +69,9 @@ impl ProviderInfo for LolaProviderInfo { fn stop_offer_service(&self) -> Result<()> { //SAFETY: it is safe as we are passing valid skeleton handle to stop offer service // the skeleton handle is created during building the provider info instance - unsafe { bridge_ffi_rs::skeleton_stop_offer_service(self.skeleton_handle.0.handle) }; + unsafe { + bridge_ffi_rs::skeleton_stop_offer_service(self.skeleton_handle.0.handle.as_ptr()) + }; Ok(()) } } @@ -115,9 +119,9 @@ pub struct SampleMut<'a, T> where T: CommData + Debug, { - pub skeleton_event: NativeSkeletonEventBase, - pub allocatee_ptr: AllocateePtrWrapper, - pub lifetime: PhantomData<&'a T>, + skeleton_event: NativeSkeletonEventBase, + allocatee_ptr: AllocateePtrWrapper, + lifetime: PhantomData<&'a T>, } impl<'a, T> SampleMut<'a, T> @@ -182,7 +186,7 @@ where // FFI call will complete before drop run on AllocateePtrWrapper and NativeSkeletonEventBase let status = unsafe { bridge_ffi_rs::skeleton_event_send_sample_allocatee( - self.skeleton_event.skeleton_event_ptr, + self.skeleton_event.skeleton_event_ptr.as_ptr(), T::ID, std::ptr::from_ref(self.allocatee_ptr.as_ref()) as *const std::ffi::c_void, ) @@ -199,9 +203,9 @@ pub struct SampleMaybeUninit<'a, T> where T: CommData + Debug, { - pub skeleton_event: NativeSkeletonEventBase, - pub allocatee_ptr: AllocateePtrWrapper, - pub lifetime: PhantomData<&'a T>, + skeleton_event: NativeSkeletonEventBase, + allocatee_ptr: AllocateePtrWrapper, + lifetime: PhantomData<&'a T>, } impl<'a, T> SampleMaybeUninit<'a, T> @@ -287,7 +291,7 @@ impl std::fmt::Debug for SkeletonInstanceManager { /// And the lifetime is managed correctly /// As it has Send and Sync unsafe impls, it must not expose any mutable access to the skeleton handle pub struct NativeSkeletonHandle { - pub handle: *mut SkeletonBase, + handle: NonNull, } //SAFETY: NativeSkeletonHandle is safe to share between threads because: @@ -300,13 +304,10 @@ unsafe impl Send for NativeSkeletonHandle {} impl NativeSkeletonHandle { pub fn new(interface_id: &str, instance_specifier: &mw_com::InstanceSpecifier) -> Result { //SAFETY: It is safe as we are passing valid type id and instance specifier to create skeleton - let handle = + let raw_handle = unsafe { bridge_ffi_rs::create_skeleton(interface_id, instance_specifier.as_native()) }; - if handle.is_null() { - return Err(Error::ProducerError( - ProducerFailedReason::SkeletonCreationFailed, - )); - } + let handle = std::ptr::NonNull::new(raw_handle) + .ok_or(Error::ProducerError(ProducerFailedReason::SkeletonCreationFailed))?; Ok(Self { handle }) } } @@ -316,7 +317,7 @@ impl Drop for NativeSkeletonHandle { //SAFETY: It is safe as we are passing valid skeleton handle to destroy skeleton // the handle was created using create_skeleton unsafe { - bridge_ffi_rs::destroy_skeleton(self.handle); + bridge_ffi_rs::destroy_skeleton(self.handle.as_ptr()); } } } @@ -325,7 +326,7 @@ impl Drop for NativeSkeletonHandle { /// Manages the lifetime of the SkeletonEventBase pointer /// Drop is not required as the skeleton event lifetime is managed by skeleton instance pub struct NativeSkeletonEventBase { - pub skeleton_event_ptr: *mut SkeletonEventBase, + skeleton_event_ptr: NonNull, } //SAFETY: NativeSkeletonEventBase is safe to send between threads because: @@ -338,18 +339,16 @@ impl NativeSkeletonEventBase { pub fn new(instance_info: &LolaProviderInfo, identifier: &str) -> Result { //SAFETY: It is safe as we are passing valid skeleton handle and interface id to get event // skeleton handle is created during producer offer call - let skeleton_event_ptr = unsafe { + let raw_event_ptr = unsafe { bridge_ffi_rs::get_event_from_skeleton( - instance_info.skeleton_handle.0.handle, + instance_info.skeleton_handle.0.handle.as_ptr(), instance_info.interface_id, identifier, ) }; - if skeleton_event_ptr.is_null() { - return Err(Error::ProducerError( - ProducerFailedReason::SkeletonCreationFailed, - )); - } + let skeleton_event_ptr = std::ptr::NonNull::new(raw_event_ptr).ok_or( + Error::ProducerError(ProducerFailedReason::SkeletonCreationFailed), + )?; Ok(Self { skeleton_event_ptr }) } } @@ -370,10 +369,10 @@ impl std::fmt::Debug for NativeSkeletonEventBase { #[derive(Debug)] pub struct Publisher { - pub identifier: String, - pub skeleton_event: NativeSkeletonEventBase, - pub _data: PhantomData, - pub _skeleton_instance: SkeletonInstanceManager, + _identifier: String, + skeleton_event: NativeSkeletonEventBase, + _data: PhantomData, + _skeleton_instance: SkeletonInstanceManager, } impl com_api_concept::Publisher for Publisher @@ -395,7 +394,7 @@ where let mut sample = core::mem::MaybeUninit::>::uninit(); let status = bridge_ffi_rs::get_allocatee_ptr( - self.skeleton_event.skeleton_event_ptr, + self.skeleton_event.skeleton_event_ptr.as_ptr(), sample.as_mut_ptr() as *mut std::ffi::c_void, T::ID, ); @@ -419,7 +418,7 @@ where fn new(identifier: &str, instance_info: LolaProviderInfo) -> Result { let skeleton_event = NativeSkeletonEventBase::new(&instance_info, identifier)?; Ok(Self { - identifier: identifier.to_string(), + _identifier: identifier.to_string(), skeleton_event, _data: PhantomData, _skeleton_instance: instance_info.skeleton_handle.clone(), @@ -427,12 +426,12 @@ where } } -pub struct SampleProducerBuilder { +pub struct LolaProducerBuilder { pub instance_specifier: InstanceSpecifier, pub _interface: PhantomData, } -impl SampleProducerBuilder { +impl LolaProducerBuilder { pub fn new(_runtime: &LolaRuntimeImpl, instance_specifier: InstanceSpecifier) -> Self { Self { instance_specifier, @@ -441,9 +440,9 @@ impl SampleProducerBuilder { } } -impl ProducerBuilder for SampleProducerBuilder {} +impl ProducerBuilder for LolaProducerBuilder {} -impl Builder> for SampleProducerBuilder { +impl Builder> for LolaProducerBuilder { fn build(self) -> Result> { //Once FFI layer error handling is in place (SWP-253124), we should convert this error to a proper FFI error instead of using map_err here let instance_specifier_runtime = mw_com::InstanceSpecifier::try_from( diff --git a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/runtime.rs b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/runtime.rs index 927051feb..14b7220af 100644 --- a/score/mw/com/impl/rust/com-api/com-api-runtime-lola/runtime.rs +++ b/score/mw/com/impl/rust/com-api/com-api-runtime-lola/runtime.rs @@ -16,7 +16,7 @@ use core::marker::PhantomData; use std::path::{Path, PathBuf}; use crate::{ - LolaConsumerInfo, LolaProviderInfo, Publisher, SampleConsumerDiscovery, SampleProducerBuilder, + LolaConsumerInfo, LolaProviderInfo, Publisher, LolaConsumerDiscovery, LolaProducerBuilder, SubscribableImpl, }; use com_api_concept::{ @@ -26,9 +26,9 @@ use com_api_concept::{ pub struct LolaRuntimeImpl {} impl Runtime for LolaRuntimeImpl { - type ServiceDiscovery = SampleConsumerDiscovery; + type ServiceDiscovery = LolaConsumerDiscovery; type Subscriber = SubscribableImpl; - type ProducerBuilder = SampleProducerBuilder; + type ProducerBuilder = LolaProducerBuilder; type Publisher = Publisher; type ProviderInfo = LolaProviderInfo; type ConsumerInfo = LolaConsumerInfo; @@ -37,7 +37,7 @@ impl Runtime for LolaRuntimeImpl { &self, instance_specifier: FindServiceSpecifier, ) -> Self::ServiceDiscovery { - SampleConsumerDiscovery { + LolaConsumerDiscovery { instance_specifier: match instance_specifier { FindServiceSpecifier::Any => panic!( "FindServiceSpecifier::Any is not supported in LolaRuntimeImpl, @@ -53,7 +53,7 @@ impl Runtime for LolaRuntimeImpl { &self, instance_specifier: InstanceSpecifier, ) -> Self::ProducerBuilder { - SampleProducerBuilder::new(self, instance_specifier) + LolaProducerBuilder::new(self, instance_specifier) } } diff --git a/score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs b/score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs index 16c477405..d099256f3 100644 --- a/score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs +++ b/score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs @@ -63,9 +63,9 @@ pub struct MockConsumerInfo { } impl Runtime for MockRuntimeImpl { - type ServiceDiscovery = SampleConsumerDiscovery; + type ServiceDiscovery = MockConsumerDiscovery; type Subscriber = SubscribableImpl; - type ProducerBuilder = SampleProducerBuilder; + type ProducerBuilder = MockProducerBuilder; type Publisher = Publisher; type ProviderInfo = MockProviderInfo; type ConsumerInfo = MockConsumerInfo; @@ -74,7 +74,7 @@ impl Runtime for MockRuntimeImpl { &self, _instance_specifier: FindServiceSpecifier, ) -> Self::ServiceDiscovery { - SampleConsumerDiscovery { + MockConsumerDiscovery { _interface: PhantomData, } } @@ -83,7 +83,7 @@ impl Runtime for MockRuntimeImpl { &self, instance_specifier: InstanceSpecifier, ) -> Self::ProducerBuilder { - SampleProducerBuilder::new(self, instance_specifier) + MockProducerBuilder::new(self, instance_specifier) } } @@ -383,11 +383,11 @@ where } } -pub struct SampleConsumerDiscovery { +pub struct MockConsumerDiscovery { _interface: PhantomData, } -impl SampleConsumerDiscovery { +impl MockConsumerDiscovery { fn new(_runtime: &MockRuntimeImpl, _instance_specifier: InstanceSpecifier) -> Self { Self { _interface: PhantomData, @@ -395,12 +395,12 @@ impl SampleConsumerDiscovery { } } -impl ServiceDiscovery for SampleConsumerDiscovery +impl ServiceDiscovery for MockConsumerDiscovery where - SampleConsumerBuilder: ConsumerBuilder, + MockConsumerBuilder: ConsumerBuilder, { - type ConsumerBuilder = SampleConsumerBuilder; - type ServiceEnumerator = Vec>; + type ConsumerBuilder = MockConsumerBuilder; + type ServiceEnumerator = Vec>; fn get_available_instances(&self) -> com_api_concept::Result { Ok(Vec::new()) @@ -414,12 +414,12 @@ where } } -pub struct SampleProducerBuilder { +pub struct MockProducerBuilder { instance_specifier: InstanceSpecifier, _interface: PhantomData, } -impl SampleProducerBuilder { +impl MockProducerBuilder { fn new(_runtime: &MockRuntimeImpl, instance_specifier: InstanceSpecifier) -> Self { Self { instance_specifier, @@ -428,9 +428,9 @@ impl SampleProducerBuilder { } } -impl ProducerBuilder for SampleProducerBuilder {} +impl ProducerBuilder for MockProducerBuilder {} -impl Builder> for SampleProducerBuilder { +impl Builder> for MockProducerBuilder { fn build(self) -> Result> { let instance_info = MockProviderInfo { instance_specifier: self.instance_specifier.clone(), @@ -451,20 +451,20 @@ impl Clone for SampleConsumerDescriptor { } } -pub struct SampleConsumerBuilder { +pub struct MockConsumerBuilder { instance_specifier: InstanceSpecifier, _interface: PhantomData, } -impl ConsumerDescriptor for SampleConsumerBuilder { +impl ConsumerDescriptor for MockConsumerBuilder { fn get_instance_identifier(&self) -> &InstanceSpecifier { todo!() } } -impl ConsumerBuilder for SampleConsumerBuilder {} +impl ConsumerBuilder for MockConsumerBuilder {} -impl Builder> for SampleConsumerBuilder { +impl Builder> for MockConsumerBuilder { fn build(self) -> com_api_concept::Result> { let instance_info = MockConsumerInfo { instance_specifier: self.instance_specifier.clone(),