21 #ifndef G_SMTP_CLIENT_PTR_H
22 #define G_SMTP_CLIENT_PTR_H
43 template <
typename TClient>
47 G_EXCEPTION( InvalidState ,
"invalid state of smtp client" ) ;
49 explicit ClientPtr( TClient * p =
nullptr ) ;
58 void reset( TClient * p =
nullptr ) ;
98 void doneSlot( std::string ) ;
99 void eventSlot( std::string , std::string ) ;
100 void connectedSlot() ;
101 void connectSignalsToSlots() ;
102 void disconnectSignals() ;
111 template <
typename TClient>
117 connectSignalsToSlots() ;
126 template <
typename TClient>
131 disconnectSignals() ;
132 m_p->doDelete(std::string()) ;
136 template <
typename TClient>
141 disconnectSignals() ;
146 template <
typename TClient>
151 disconnectSignals() ;
154 p->doDeleteForExit() ;
158 template <
typename TClient>
164 m_p->eventSignal().connect(
G::Slot::slot(*
this,&ClientPtr::eventSlot) ) ;
165 m_p->connectedSignal().connect(
G::Slot::slot(*
this,&ClientPtr::connectedSlot) ) ;
169 template <
typename TClient>
172 disconnectSignals() ;
174 TClient * old = m_p ;
178 old->doDelete( std::string() ) ;
181 connectSignalsToSlots() ;
184 template <
typename TClient>
187 return m_done_signal ;
190 template <
typename TClient>
193 return m_event_signal ;
196 template <
typename TClient>
199 return m_connected_signal ;
202 template <
typename TClient>
205 G_ASSERT( m_p !=
nullptr ) ;
206 disconnectSignals() ;
208 m_done_signal.emit( reason ) ;
211 template <
typename TClient>
212 void ClientPtr<TClient>::disconnectSignals()
216 m_p->doneSignal().disconnect() ;
217 m_p->eventSignal().disconnect() ;
218 m_p->connectedSignal().disconnect() ;
222 template <
typename TClient>
223 void ClientPtr<TClient>::connectedSlot()
225 G_ASSERT( m_p !=
nullptr ) ;
226 m_connected_signal.emit() ;
229 template <
typename TClient>
230 void ClientPtr<TClient>::eventSlot( std::string s1 , std::string s2 )
232 m_event_signal.emit( s1 , s2 ) ;
235 template <
typename TClient>
241 template <
typename TClient>
244 return m_p != nullptr ;
247 template <
typename TClient>
251 throw InvalidState() ;
255 template <
typename TClient>
259 throw InvalidState() ;
TClient * get()
Returns the pointer, or nullptr if deleted.
G::Slot::Signal0 & connectedSignal()
Returns a signal which indicates that the connection has been established successfully.
void releaseForExit()
Can be called on program termination when there may be no TimerList or EventLoop instances.
G::Slot::Signal2< std::string, std::string > & eventSignal()
Returns a signal which indicates something interesting.
void reset(TClient *p=nullptr)
Resets the pointer.
void cleanupForExit()
Can be called on program termination when there may be no TimerList or EventLoop instances.
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
ClientPtr(TClient *p=nullptr)
Constructor. Takes ownership of the new-ed client.
G::Slot::Signal1< std::string > & doneSignal()
Returns a signal which indicates that client processing is complete and the client instance has delet...
A signal class for zero-parameter callbacks.
A smart pointer class for GNet::HeapClient that keeps track of when the contained instance deletes it...
TClient * operator->()
Returns the pointer. Throws if deleted.
bool busy() const
Returns true if the pointer is not nullptr.