RTI Connext Modern C++ API  Version 6.0.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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()
 
const Listenerget () const
 (Deprecated) Use listener()
 
Listenerlistener ()
 Retrieves the listener.
 
const Listenerlistener () const
 Retrieves the listener.
 

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.
 
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.
 
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.
 
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.
 

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

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::get().

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

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

(Deprecated) Use listener()

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

(Deprecated) Use listener()

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

Retrieves the listener.

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

Retrieves the listener.

Friends And Related Function Documentation

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.

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(
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.

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

See Also
bind_listener(Entity, Listener*, dds::core::status::StatusMask)
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.

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(), dds::core::status::StatusMask::data_available());
See Also
bind_listener()
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.

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

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

RTI Connext Modern C++ API Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc