21#ifndef G_NET_CLIENT_PTR_H
22#define G_NET_CLIENT_PTR_H
36 template <
typename T>
class ClientPtr ;
82 void eventSlot(
const std::string & ,
const std::string & ,
const std::string & ) ;
137 G_EXCEPTION( InvalidState ,
"invalid state of network client holder" ) ;
152 void reset( std::unique_ptr<T> p ) noexcept ;
166 const T * operator->() const ;
174 void onException(
ExceptionSource * , std::exception & ,
bool ) override ;
175 std::
string exceptionSourceId() const override ;
180 void operator=( const
ClientPtr & ) = delete ;
181 void operator=(
ClientPtr && ) = delete ;
185 T * set( std::nullptr_t ) noexcept ;
186 T * release() noexcept ;
190 bool m_has_connected{
false} ;
212 G_WARNING(
"GNet::ClientPtr::onException: unhandled exception: " << e.what() ) ;
217 std::string reason = ( done || m_p->finished() ) ? std::string() : std::string(e.what()) ;
219 std::unique_ptr<T> ptr( release() ) ;
220 ptr->doOnDelete( e.what() , done ) ;
221 deleteSignal().emit( reason ) ;
224 deletedSignal().emit( reason ) ;
233 if( m_p->hasConnected() ) m_has_connected = true ;
234 disconnectSignals( *m_p ) ;
238 connectSignals( *p ) ;
240 std::swap( p , m_p ) ;
249 if( m_p->hasConnected() ) m_has_connected = true ;
250 disconnectSignals( *m_p ) ;
260 return set(
nullptr ) ;
272 delete set( p.release() ) ;
278 delete set(
nullptr ) ;
290 return m_p != nullptr ;
296 return m_has_connected ;
303 throw InvalidState() ;
311 throw InvalidState() ;
The non-template part of GNet::ClientPtr.
void connectSignals(Client &)
Connects the given client's signals to this object's slots.
void disconnectSignals(Client &) noexcept
Disconnects the given client's signals from this object's slots.
G::Slot::Signal< const std::string & > & deletedSignal()
A signal that is triggered after deleteSignal() once the client has been deleted and the ClientPtr is...
ClientPtrBase()
Default constructor.
G::Slot::Signal< const std::string & > & deleteSignal()
A signal that is triggered as the client is deleted following an exception handled by this class.
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & eventSignal()
See GNet::Client::eventSignal().
A smart pointer class for GNet::Client.
bool busy() const
Returns true if the pointer is not nullptr.
T * operator->()
Returns the pointer. Throws if deleted.
void reset(T *p) noexcept
Resets the pointer.
ClientPtr(T *p=nullptr)
Constructor. Takes ownership of the new-ed client.
T * get() noexcept
Returns the pointer, or nullptr if deleted.
bool hasConnected() const noexcept
Returns true if any Client owned by this smart pointer has ever successfully connected.
void reset(std::unique_ptr< T > p) noexcept
Resets the pointer.
~ClientPtr() override
Destructor.
void reset() noexcept
Resets the pointer.
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket/future event...
A mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
virtual std::string exceptionSourceId() const
Returns an identifying string for logging purposes, or the empty string.