Git Product home page Git Product logo

Comments (3)

jrebelo avatar jrebelo commented on June 27, 2024 1

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.

jrebelo avatar jrebelo commented on June 27, 2024

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.

YeahhhhzZ avatar YeahhhhzZ commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.