RTI Connext Modern C++ API  Version 6.1.0
rti::core::ListenerBinder< Entity, Listener > Class Template Reference

<<reference-type>> Automatically manages the association of an Entity and a Listener More...

#include <rti/core/ListenerBinder.hpp>

Inheritance diagram for rti::core::ListenerBinder< Entity, Listener >:
dds::core::Reference< Listener >

Public Member Functions

Listenerget ()
 (Deprecated) Use listener() More...
 
const Listenerget () const
 (Deprecated) Use listener() More...
 
Listenerlistener ()
 Retrieves the listener. More...
 
const Listenerlistener () const
 Retrieves the listener. More...
 
Entity entity () const
 Retrieves the Entity associated with the listener. More...
 

Related Functions

(Note that these are not member functions.)

template<typename Entity , typename Listener >
ListenerBinder< Entity, Listenerbind_listener (Entity entity, Listener *the_listener, dds::core::status::StatusMask mask)
 Sets the listener and creates a ListenerBinder that automatically resets it when all references go out of scope. More...
 
template<typename Entity , typename Listener >
ListenerBinder< Entity, Listenerbind_listener (Entity entity, Listener *the_listener)
 Sets the listener and creates a ListenerBinder that automatically resets it when all references go out of scope. More...
 
template<typename Entity , typename Listener >
ListenerBinder< Entity, Listenerbind_and_manage_listener (Entity entity, Listener *the_listener, dds::core::status::StatusMask mask)
 Sets the listener and creates a ListenerBinder that automatically resets and deletes it when all references go out of scope. More...
 
template<typename Entity , typename Listener >
ListenerBinder< Entity, Listenerbind_and_manage_listener (Entity entity, Listener *the_listener)
 Sets the listener and creates a ListenerBinder that automatically resets and deletes it when all references go out of scope. More...
 

Detailed Description

template<typename Entity, typename Listener = typename Entity::Listener>
class rti::core::ListenerBinder< Entity, Listener >

<<reference-type>> Automatically manages the association of an Entity and a Listener

[DEPRECATED] The use of ListenerBinder is no longer required as long as the a std::shared_ptr is used to set an Entity's listener.

Note
A ListenerBinder provides all the functions of a <<reference-type>> except close() and retain().

Ties the association listener/Entity to the existence of references to this type–that is, the constructor sets the listener; when the last reference is destroyed, the entity's listener is unset. Depending on how this type is created, the listener may also be deleted:

The goal is to simplify the destruction of an Entity by the application, which otherwise would have to reset the listener or close the Entity explicitly.

Example:

class MyListener : public DataReaderListener<Foo> { ... };
void f()
{
MyListener listener;
dds::sub::DataReader<Foo> my_reader(subscriber, topic);
{
auto scoped_listener = rti::core::bind_listener(
my_reader,
listener,
// my_reader has a listener
// ...
} // After this, my_reader doesn't have a listener
} // my_reader destroyed; if we hadn't used a ListenerBinder,
// my_reader would not have been destroyed

To create a ListenerBinder use rti::core::bind_listener() or rti::core::bind_and_manage_listener(). To retrieve the listener use ListenerBinder::listener(); to retrieve the entity, use ListenerBinder::entity().

If the Entity changes its listener while references to this ListenerBinder still exist, the ListenerBinder will not reset the listener.

Template Parameters
EntityA subclass of dds::core::Entity
ListenerThe listener type, by default Entity::Listener
See also
Reference types, for an explanation of how reference types work and the reasons why an Entity may be retained.

Member Function Documentation

◆ get() [1/2]

template<typename Entity, typename Listener = typename Entity::Listener>
Listener* rti::core::ListenerBinder< Entity, Listener >::get ( )
inline

(Deprecated) Use listener()

◆ get() [2/2]

template<typename Entity, typename Listener = typename Entity::Listener>
const Listener* rti::core::ListenerBinder< Entity, Listener >::get ( ) const
inline

(Deprecated) Use listener()

◆ listener() [1/2]

template<typename Entity, typename Listener = typename Entity::Listener>
Listener* rti::core::ListenerBinder< Entity, Listener >::listener ( )
inline

Retrieves the listener.

Returns
The listener.

◆ listener() [2/2]

template<typename Entity, typename Listener = typename Entity::Listener>
const Listener* rti::core::ListenerBinder< Entity, Listener >::listener ( ) const
inline

Retrieves the listener.

◆ entity()

template<typename Entity, typename Listener = typename Entity::Listener>
Entity rti::core::ListenerBinder< Entity, Listener >::entity ( ) const
inline

Retrieves the Entity associated with the listener.

Referenced by rti::core::bind_and_manage_listener(), and rti::core::bind_listener().

Friends And Related Function Documentation

◆ bind_listener() [1/2]

template<typename Entity , typename Listener >
ListenerBinder< Entity, Listener > bind_listener ( Entity  entity,
Listener the_listener,
dds::core::status::StatusMask  mask 
)
related

Sets the listener and creates a ListenerBinder that automatically resets it when all references go out of scope.

[DEPRECATED] The use of ListenerBinder is no longer required as long as the a std::shared_ptr is used to set an Entity's listener.

The ListenerBinder created from this function does not delete the listener, it simply sets the listener back to NULL in the Entity. The application is responsible for the life-cycle of the listener.

To also delete the listener when all references go out of scope, see bind_and_manage_listener().

MyListener my_listener;
dds::sub::DataReader<Foo> reader(subscriber, topic);
// reader will have no listener after scoped_listener (and any other
// references created from scoped_listener) go out of scope--note that
// my_listener is a stack variable so scoped_listener should not delete it
auto scoped_listener = bind_listener(

◆ bind_listener() [2/2]

template<typename Entity , typename Listener >
ListenerBinder< Entity, Listener > bind_listener ( Entity  entity,
Listener the_listener 
)
related

Sets the listener and creates a ListenerBinder that automatically resets it when all references go out of scope.

[DEPRECATED] The use of ListenerBinder is no longer required as long as the a std::shared_ptr is used to set an Entity's listener.

This overload works for listeners that don't use a mask

See also
bind_listener(Entity, Listener*, dds::core::status::StatusMask)

◆ bind_and_manage_listener() [1/2]

template<typename Entity , typename Listener >
ListenerBinder< Entity, Listener > bind_and_manage_listener ( Entity  entity,
Listener the_listener,
dds::core::status::StatusMask  mask 
)
related

Sets the listener and creates a ListenerBinder that automatically resets and deletes it when all references go out of scope.

[DEPRECATED] The use of ListenerBinder is no longer required as long as the a std::shared_ptr is used to set an Entity's listener.

Example:

dds::sub::DataReader<Foo> reader(subscriber, topic);
// The instance of MyListener we are creating and attaching to reader will be
// unset and deleted when scoped_listener (and any other references create
from
// scoped_listener) go out of scope
auto scoped_listener = bind_and_manage_listener(
reader, new MyListener(),
See also
bind_listener()

◆ bind_and_manage_listener() [2/2]

template<typename Entity , typename Listener >
ListenerBinder< Entity, Listener > bind_and_manage_listener ( Entity  entity,
Listener the_listener 
)
related

Sets the listener and creates a ListenerBinder that automatically resets and deletes it when all references go out of scope.

[DEPRECATED] The use of ListenerBinder is no longer required as long as the a std::shared_ptr is used to set an Entity's listener.

This overload works for listeners that don't use a mask

See also
bind_and_manage_listener(Entity, Listener*, dds::core::status::StatusMask)