E-MailRelay

Public Member Functions | List of all members
GNet::ClientPtr< T > Class Template Reference

A smart pointer class for GNet::Client or similar. More...

`#include <gclientptr.h>`

Inheritance diagram for GNet::ClientPtr< T >:
[legend]
Collaboration diagram for GNet::ClientPtr< T >:
[legend]

## Public Member Functions
| ClientPtr (T *p=nullptr)
| Constructor. Takes ownership of the new-ed client. More...
| ~ClientPtr () override
| Destructor. More...
bool | busy () const
| Returns true if the pointer is not nullptr. More...
void | reset (T *p)
| Resets the pointer. More...
void | reset (std::unique_ptr< T > p)
| Resets the pointer. More...
void | reset () noexcept
| Resets the pointer. More...
T * | get () noexcept
| Returns the pointer, or nullptr if deleted. More...
const T * | get () const noexcept
| Returns the pointer, or nullptr if deleted. More...
T * | operator-> ()
| Returns the pointer. Throws if deleted. More...
const T * | operator-> () const
| Returns the pointer. Throws if deleted. More...
bool | hasConnected () const noexcept
| Returns true if any Client owned by this smart pointer has ever successfully connected. More...
| ClientPtr (const ClientPtr &)=delete
| ClientPtr (ClientPtr &&) noexcept
ClientPtr & | operator= (const ClientPtr &)=delete
ClientPtr & | operator= (ClientPtr &&) noexcept
Public Member Functions inherited from GNet::ClientPtrBase
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & | eventSignal () noexcept
| A signal that is linked to the contained client's eventSignal(). More...
G::Slot::Signal< const std::string & > & | deleteSignal () noexcept
| A signal that is triggered as the client is deleted following an exception handled by this class. More...
G::Slot::Signal< const std::string & > & | deletedSignal () noexcept
| A signal that is triggered after deleteSignal() once the client has been deleted and the ClientPtr is empty. More...
| ClientPtrBase (const ClientPtrBase &)=delete
| ClientPtrBase (ClientPtrBase &&)=delete
ClientPtrBase & | operator= (const ClientPtrBase &)=delete
ClientPtrBase & | operator= (ClientPtrBase &&)=delete
Public Member Functions inherited from GNet::ExceptionHandler
virtual | ~ExceptionHandler ()
| Destructor. More...
virtual void | onException (ExceptionSource *source, std::exception &e, bool done)=0
| Called by the event loop when an exception is thrown out of an event loop callback. More...
| ExceptionHandler (const ExceptionHandler &)=delete
| ExceptionHandler (ExceptionHandler &&)=default
ExceptionHandler & | operator= (const ExceptionHandler &)=delete
ExceptionHandler & | operator= (ExceptionHandler &&)=default
Public Member Functions inherited from GNet::ExceptionSource
virtual | ~ExceptionSource ()
| Destructor.
| ExceptionSource (const ExceptionSource &)=delete
| ExceptionSource (ExceptionSource &&)=delete
ExceptionSource & | operator= (const ExceptionSource &)=delete
ExceptionSource & | operator= (ExceptionSource &&)=delete

## Additional Inherited Members
Protected Member Functions inherited from GNet::ClientPtrBase
| ClientPtrBase ()
| Default constructor.
void | eventSlot (const std::string &, const std::string &, const std::string &)
| Emits an eventSignal(). More...

## Detailed Description

template<typename T>
class GNet::ClientPtr< T >

A smart pointer class for GNet::Client or similar.

The ClientPtr is-a ExceptionHandler, so it should be the ExceptionHandler part of the Client's EventState:

m_client_ptr.reset( new Client( m_es.eh(m_client_ptr) , ... ) ) ;

If that is done then the contained Client object will get deleted as the result of an exception thrown out of a network event handler (including GNet::Done) with internal notification to the Client's onDelete() method and external notification via the smart pointer's deleteSignal(). If the Client is deleted from the smart pointer's destructor then there are no notifications.

If the Client is given some higher-level object as its ExceptionHandler then the ClientPtr will not do any notification and the higher-level object must ensure that the Client object is deleted or disconnected when an exception is thrown:

void Foo::fn()
{
m_client_ptr.reset( new Client( m_es.eh(this,&m_client_ptr) , ... ) ) ;
}
void Foo::onException( ExceptionSource * esrc , std::exception & e , bool done )
{
if( esrc == &m_client_ptr )
{
m_client_ptr->doOnDelete( e.what() , done ) ;
m_client_ptr.reset() ; // or m_client_ptr->disconnect() ;
}
}

Failure to delete the client from within the higher-level object's exception handler will result in bad event handling, with the event loop raising events that are never cleared.

Definition at line 143 of file gclientptr.h.

## Constructor & Destructor Documentation

## ◆ ClientPtr()

template<typename T >

GNet::ClientPtr< T >::ClientPtr | ( | T * | p = `nullptr` | ) |
| explicit

Constructor. Takes ownership of the new-ed client.

Definition at line 208 of file gclientptr.h.

## ◆ ~ClientPtr()

template<typename T >

GNet::ClientPtr< T >::~ClientPtr
| override

Destructor.

Definition at line 218 of file gclientptr.h.

## Member Function Documentation

## ◆ busy()

template<typename T >

bool GNet::ClientPtr< T >::busy

Returns true if the pointer is not nullptr.

Definition at line 311 of file gclientptr.h.

## ◆ get() [1/2]

template<typename T >

const T * GNet::ClientPtr< T >::get
| noexcept

Returns the pointer, or nullptr if deleted.

Definition at line 305 of file gclientptr.h.

## ◆ get() [2/2]

template<typename T >

T * GNet::ClientPtr< T >::get
| noexcept

Returns the pointer, or nullptr if deleted.

Definition at line 299 of file gclientptr.h.

## ◆ hasConnected()

template<typename T >

bool GNet::ClientPtr< T >::hasConnected
| noexcept

Returns true if any Client owned by this smart pointer has ever successfully connected.

Returns false if T is-not-a Client.

Definition at line 317 of file gclientptr.h.

## ◆ operator->() [1/2]

template<typename T >

T * GNet::ClientPtr< T >::operator->

Returns the pointer. Throws if deleted.

Definition at line 323 of file gclientptr.h.

## ◆ operator->() [2/2]

template<typename T >

const T * GNet::ClientPtr< T >::operator->

Returns the pointer. Throws if deleted.

Definition at line 331 of file gclientptr.h.

## ◆ reset() [1/3]

template<typename T >

void GNet::ClientPtr< T >::reset
| noexcept

Resets the pointer.

There is no call to onDelete() and no emitted signals.

Definition at line 293 of file gclientptr.h.

## ◆ reset() [2/3]

template<typename T >

void GNet::ClientPtr< T >::reset | ( | std::unique_ptr< T > | p | ) |

Resets the pointer.

There is no call to onDelete() and no emitted signals.

Definition at line 287 of file gclientptr.h.

## ◆ reset() [3/3]

template<typename T >

void GNet::ClientPtr< T >::reset | ( | T * | p | ) |

Resets the pointer.

There is no call to onDelete() and no emitted signals.

Definition at line 281 of file gclientptr.h.

The documentation for this class was generated from the following file:

- /tmp/slackdce/slackrepo.HKsbdz/build_emailrelay/emailrelay-2.6/src/gnet/gclientptr.h