E-MailRelay

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

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

`#include <gclientptr.h>`

Inheritance diagram for GNet::ClientPtr< T >:

## 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) noexcept
| Resets the pointer. More...
void | reset (std::unique_ptr< T > p) noexcept
| Resets the pointer. More...
void | reset () noexcept
| Resets the pointer. More...
T * | get () 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 &&)=delete
void | operator= (const ClientPtr &)=delete
void | operator= (ClientPtr &&)=delete
Public Member Functions inherited from GNet::ClientPtrBase
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & | eventSignal ()
| See GNet::Client::eventSignal(). More...
G::Slot::Signal< const std::string & > & | deleteSignal ()
| 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 ()
| 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
void | operator= (const ClientPtrBase &)=delete
void | 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 &&)=delete
void | operator= (const ExceptionHandler &)=delete
void | operator= (ExceptionHandler &&)=delete
Public Member Functions inherited from GNet::ExceptionSource
virtual std::string | exceptionSourceId () const
| Returns an identifying string for logging purposes, or the empty string. More...
virtual | ~ExceptionSource ()
| Destructor. More...
| ExceptionSource (const ExceptionSource &)=delete
| ExceptionSource (ExceptionSource &&)=delete
void | operator= (const ExceptionSource &)=delete
void | operator= (ExceptionSource &&)=delete

## Additional Inherited Members
Protected Member Functions inherited from GNet::ClientPtrBase
| ClientPtrBase ()
| Default constructor.
void | connectSignals (Client &)
| Connects the given client's signals to this object's slots. More...
void | disconnectSignals (Client &) noexcept
| Disconnects the given client's signals from this object's slots. More...

## Detailed Description

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

A smart pointer class for GNet::Client.

The ClientPtr is-a ExceptionHandler, so it should normally be used as the Client's ExceptionSink:

m_client_ptr.reset( new Client( ExceptionSink(m_client_ptr,m_es.esrc()) , ... ) ) ;

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 ExceptionSink 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( ExceptionSink(*this,&m_client_ptr) , ... ) ) ;
}
void Foo::onException( ExceptionSource * esrc , std::exception & e , bool done )
{
if( esrc == m_client_ptr.get() )
{
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.

Note that the ClientPtr exception handler ignores the ExceptionSource pointer, so it can be set to be the same as the higher-level object, for better event logging (as shown above).

Definition at line 134 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 194 of file gclientptr.h.

## ◆ ~ClientPtr()

template<typename T >

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

Destructor.

Definition at line 202 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 288 of file gclientptr.h.

## ◆ get()

template<typename T >

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

Returns the pointer, or nullptr if deleted.

Definition at line 282 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.

Definition at line 294 of file gclientptr.h.

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

template<typename T >

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

Returns the pointer. Throws if deleted.

Definition at line 300 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 308 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 276 of file gclientptr.h.

## ◆ reset() [2/3]

template<typename T >

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

Resets the pointer.

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

Definition at line 270 of file gclientptr.h.

## ◆ reset() [3/3]

template<typename T >

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

Resets the pointer.

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

Definition at line 264 of file gclientptr.h.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gclientptr.h