DoneEvent Template


template <class T>
class DoneEvent : virtual public T

  HANDLE GetDoneEvent() const;
  bool WaitDone(DWORD timeout = INFINITE) const;
  bool IsDone() const;

  void OnStart() { ResetEvent(m_event); T::OnStart(); }
  void OnDone() { SetEvent(m_event); T::OnDone(); }

  HANDLE m_event;             // a Win32 event

// DoneEvent typedefs
typedef DoneEvent<ProgressHandler>   ProgressEvent;
typedef DoneEvent<ForwardingHandler> ForwardingEvent;
typedef DoneEvent<ReceiveHandler>    ReceiveEvent;
typedef DoneEvent<RealPathHandler>   RealPathEvent;
typedef DoneEvent<StatHandler>       StatEvent;
typedef DoneEvent<SftpHandler>       SftpEvent;
typedef DoneEvent<ListHandler>       ListEvent;
typedef DoneEvent<TransferHandler>   TransferEvent;


  • DoneEvent: Creates a Win32 event associated with this handler object. Throws CreateEventException if it fails.
  • GetDoneEvent: Returns a Win32 event that you can use for your synchronizations. The returned event gets signaled as soon as the request completes.
  • WaitDone: Wait until the request completes or until the specified timeout in milliseconds occurs.
  • IsDone: Is the request completed? This is always true for inactive handler objects.


This template class adds synchronization functionality on top of our handler classes. Its functionality comes in handy if you want to synchronize a request, or if you simply want to wait that a request completes. FlowSshCpp's command-line samples use DoneEvent extensively.


This example demonstrates the usage of a ProgressEvent class.


RefPtr<MyClient> client(new MyClient());
client->SetUserName(L"some name");
RefPtr<ProgressEvent> progress(new ProgressEvent);

if (progress->Success()) ..
else ..