RTI Connext Modern C++ API  Version 5.3.1
 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>

Inherits dds::core::Reference< DELEGATE >.

Public Member Functions

Listenerget ()
 Retrieves the listener.
 
const Listenerget () const
 Retrieves the listener.
 
- Public Member Functions inherited from dds::core::Reference< DELEGATE >
 Reference (dds::core::null_type &)
 
 Reference (const Reference &ref)
 
template<typename D >
 Reference (const Reference< D > &ref)
 
 ~Reference ()
 
template<typename R >
bool operator== (const R &ref) const
 
template<typename R >
bool operator!= (const R &ref) const
 
Reference & operator= (const null_type)
 
bool is_nil () const
 
bool operator== (const null_type) const
 
bool operator!= (const null_type) const
 
const DELEGATE_REF_T & delegate () const OMG_NOEXCEPT
 
DELEGATE_REF_T & delegate () OMG_NOEXCEPT
 
DELEGATE * operator-> () OMG_NOEXCEPT
 
const DELEGATE * operator-> () const OMG_NOEXCEPT
 

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

Ties the association listener/Entity to the existence of references to this type–that is, the constructor sets the listener and creates a reference and when the last reference is destroyed it resets the listener. Depending on how it is created it will also delete the listener or not:

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> reader(subscriber, topic);
{
auto scoped_listener = rti::core::bind_listener(
// reader has a listener set
// ...
} // After this, reader doesn't have a listener
} // reader deleted; if we hadn't used a ListenerBinder,
// reader would not have been deleted

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.

Note
ListenerBinder provides all the operations of a reference type except close() and retain().
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

Retrieves the listener.

Returns
The listener.
template<typename Entity, typename Listener = typename Entity::Listener>
const Listener* rti::core::ListenerBinder< Entity, Listener >::get ( ) 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 5.3.1 Copyright © Mon Feb 19 2018 Real-Time Innovations, Inc