DoneEvent Template

[C++]

template <class T>
class DoneEvent : virtual public T
{
public:
  DoneEvent();

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

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

private:
  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;

Members

  • 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.

Remarks

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.

Examples

This example demonstrates the usage of a ProgressEvent class.

[C++]

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

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