21 #ifndef G_NET_CLIENT_PTR__H
22 #define G_NET_CLIENT_PTR__H
48 G_EXCEPTION( InvalidState ,
"invalid state of network client handle" ) ;
59 void reset( T * p =
nullptr ) ;
100 void doneSlot( std::string ) ;
101 void eventSlot( std::string , std::string ) ;
102 void connectedSlot() ;
103 void connectSignalsToSlots() ;
104 void disconnectSignals() ;
113 template <
typename T>
119 connectSignalsToSlots() ;
128 template <
typename T>
133 disconnectSignals() ;
134 m_p->doDelete( std::string() ) ;
138 template <
typename T>
141 T * result = nullptr ;
144 disconnectSignals() ;
151 template <
typename T>
157 m_p->eventSignal().connect(
G::Slot::slot(*
this,&ClientPtr::eventSlot) ) ;
158 m_p->connectedSignal().connect(
G::Slot::slot(*
this,&ClientPtr::connectedSlot) ) ;
162 template <
typename T>
165 disconnectSignals() ;
170 old->doDelete( std::string() ) ;
172 connectSignalsToSlots() ;
175 template <
typename T>
178 disconnectSignals() ;
182 p->doDelete( std::string() ) ;
186 template <
typename T>
189 return m_done_signal ;
192 template <
typename T>
195 return m_event_signal ;
198 template <
typename T>
201 return m_connected_signal ;
204 template <
typename T>
207 G_ASSERT( m_p !=
nullptr ) ;
208 disconnectSignals() ;
210 m_done_signal.emit( reason ) ;
213 template <
typename T>
219 m_p->eventSignal().disconnect() ;
220 m_p->connectedSignal().disconnect() ;
224 template <
typename T>
227 G_ASSERT( m_p !=
nullptr ) ;
228 m_connected_signal.emit() ;
231 template <
typename T>
234 m_event_signal.emit( s1 , s2 ) ;
237 template <
typename T>
243 template <
typename T>
246 return m_p != nullptr ;
249 template <
typename T>
253 throw InvalidState() ;
257 template <
typename T>
261 throw InvalidState() ;
G::Slot::Signal2< std::string, std::string > & eventSignal()
Returns a signal which indicates something interesting.
void resetForExit()
Resets the pointer.
T * get()
Returns the pointer, or nullptr if deleted.
ClientPtr(T *p=nullptr)
Constructor. Takes ownership of the new-ed client.
G::Slot::Signal0 & connectedSignal()
Returns a signal which indicates that the connection has been established successfully.
T * release()
Releases the pointer so ownership is transfered to the caller.
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
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.
T * operator->()
Returns the pointer. Throws if deleted.
A smart pointer class for GNet::HeapClient that keeps track of when the contained instance deletes it...
bool busy() const
Returns true if the pointer is not nullptr.
void reset(T *p=nullptr)
Resets the pointer.