E-MailRelay
|
A smart pointer class for GNet::Client or similar. More...
#include <gclientptr.h>
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 |
![]() | |
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 |
![]() | |
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 |
![]() | |
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 | |
ExceptionSource & | operator= (const ExceptionSource &)=delete |
ExceptionSource & | operator= (ExceptionSource &&)=delete |
Additional Inherited Members | |
![]() | |
ClientPtrBase () | |
Default constructor. | |
void | eventSlot (const std::string &, const std::string &, const std::string &) |
Emits an eventSignal(). More... | |
A smart pointer class for GNet::Client or similar.
The ClientPtr is-a ExceptionHandler, so it should normally be used as the Client's ExceptionSink:
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:
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) (see GNet::ExceptionSource::exceptionSourceId()).
Definition at line 158 of file gclientptr.h.
|
explicit |
Constructor. Takes ownership of the new-ed client.
Definition at line 224 of file gclientptr.h.
|
override |
Destructor.
Definition at line 234 of file gclientptr.h.
bool GNet::ClientPtr< T >::busy |
Returns true if the pointer is not nullptr.
Definition at line 327 of file gclientptr.h.
|
noexcept |
Returns the pointer, or nullptr if deleted.
Definition at line 321 of file gclientptr.h.
|
noexcept |
Returns the pointer, or nullptr if deleted.
Definition at line 315 of file gclientptr.h.
|
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 333 of file gclientptr.h.
T * GNet::ClientPtr< T >::operator-> |
Returns the pointer. Throws if deleted.
Definition at line 339 of file gclientptr.h.
const T * GNet::ClientPtr< T >::operator-> |
Returns the pointer. Throws if deleted.
Definition at line 347 of file gclientptr.h.
|
noexcept |
Resets the pointer.
There is no call to onDelete() and no emitted signals.
Definition at line 309 of file gclientptr.h.
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 303 of file gclientptr.h.
void GNet::ClientPtr< T >::reset | ( | T * | p | ) |
Resets the pointer.
There is no call to onDelete() and no emitted signals.
Definition at line 297 of file gclientptr.h.