Comments (3)
Yes, you can indeed implement the multiple listener traits on the same object and use different instances of that object as a listener for different entities. I will close this issue for now as this is working as intended from a Dust DDS perspective.
from dust-dds.
Hi @YeahhhhzZ, the #[actor_interface] macro is not meant to be used outside of the dust_dds implementation crate. As a user of dust_dds you should only depend on the derive functions which are re-exported by dust_dds instead of directly using the dust_dds_derive crate. For reference all those derives are for the traits in type_support.
If I understand correctly you are trying to install a listener on the topic. To do this you first need to create the object which will be the listener and implement the TopicListenerAsync trait on it. Here is an example on how to do that:
struct ExampleTopicListener {
inconsistent_count: i32,
}
impl dust_dds::dds_async::topic_listener::TopicListenerAsync for ExampleTopicListener {
fn on_inconsistent_topic(
&mut self,
_the_topic: dust_dds::dds_async::topic::TopicAsync,
_status: dust_dds::infrastructure::status::InconsistentTopicStatus,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + '_>> {
Box::pin(async {
self.inconsistent_count += 1;
})
}
}
Once you have such object you can install it when creating the topic by passing the optional box and the status kind you want it to react on:
let topic = participant
.create_topic::<UserData>(
"LargeDataTopic",
"UserData",
QosKind::Default,
Some(Box::new(ExampleTopicListener {
inconsistent_count: 0,
})),
&[StatusKind::InconsistentTopic],
)
.await
.unwrap();
from dust-dds.
Hi @YeahhhhzZ, the #[actor_interface] macro is not meant to be used outside of the dust_dds implementation crate. As a user of dust_dds you should only depend on the derive functions which are re-exported by dust_dds instead of directly using the dust_dds_derive crate. For reference all those derives are for the traits in type_support.
If I understand correctly you are trying to install a listener on the topic. To do this you first need to create the object which will be the listener and implement the TopicListenerAsync trait on it. Here is an example on how to do that:
struct ExampleTopicListener { inconsistent_count: i32, } impl dust_dds::dds_async::topic_listener::TopicListenerAsync for ExampleTopicListener { fn on_inconsistent_topic( &mut self, _the_topic: dust_dds::dds_async::topic::TopicAsync, _status: dust_dds::infrastructure::status::InconsistentTopicStatus, ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + '_>> { Box::pin(async { self.inconsistent_count += 1; }) } }Once you have such object you can install it when creating the topic by passing the optional box and the status kind you want it to react on:
let topic = participant .create_topic::<UserData>( "LargeDataTopic", "UserData", QosKind::Default, Some(Box::new(ExampleTopicListener { inconsistent_count: 0, })), &[StatusKind::InconsistentTopic], ) .await .unwrap();
Thanks, I originally want to package different listeners into a structure, like:
struct TopicListener {
listener: xxx,
mask: Vec<StatusKind>,
};
// other Listener struct
// package
struct Listeners {
topic: Option<TopicListener>,
publisher: Option<PublisherListener>,
subscriber: Option<SubscriberListener>,
datawriter: Option<DataWriterListener>,
datareader: Option<DataReaderListener>,
}
and provide it to the user so that the user can customize the listener as needed, and then provide a create_writer/create_reader method, like:
fn create_datawriter(topic_name: &str, listeners: Listeners) -> DDSWriter {}
fn create_datareader(topic_name: &str, listeners: Listeners) -> DDSReader {}
Later, I saw the related usage of actor_interface in the dust_dds_derive document and thought about giving it a try.
Now, let me try again according to your method
from dust-dds.
Related Issues (18)
- Comparison to RustDDS HOT 5
- Inconsistent Behavior with DataWriterQos "HistoryQosPolicyKind::KeepLast" in a Publisher-Subscriber Scenario HOT 1
- Option Serialization Support HOT 4
- Cannot Run DDS Subscriber Within Tokio Context HOT 3
- Interoperability with FastDDS HOT 5
- Remove Sync trait bound for create_datareader, AnyDataReaderListener impl HOT 2
- DurationKind incompatible with json, ron deserialization HOT 1
- Better configuration HOT 2
- Why can't I receive it correctly using the example in the warehouse? HOT 3
- Scope of types supported for dds_gen HOT 1
- Cannot start a runtime from within a runtime HOT 1
- Receive messages from other topics when communicate with cyclonedds HOT 6
- DdsType derivation macro support for nested types HOT 6
- [ENTITYID_BUILTIN_PUBLICATIONS_WRITER] Should we choose to continue processing sub-messages even if the sequence numbers are not consecutive? HOT 3
- IDL generate from another idl file HOT 1
- IDL Gen annotations support HOT 1
- Cyclone interoperability with data types HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dust-dds.