#pragma once

#include <stdexcept>

#include "DllDefines.h"

class UTILITYDLL CMyWaitTimeoutException : public std::exception
{
public:
    CMyWaitTimeoutException();
    virtual ~CMyWaitTimeoutException();
};

class UTILITYDLL CMyWaitInterruptedException : public std::exception
{
public:
    CMyWaitInterruptedException();
    virtual ~CMyWaitInterruptedException();
};

class UTILITYDLL CMyWait
{
public:
    CMyWait();
    virtual ~CMyWait();
    // ************************************
    // Method:    Wait
    // FullName:  CMyWait::Wait
    // Access:    public
    // Returns:   DWORD
    // Qualifier:
    // Parameter: HANDLE handle
    // Parameter: DWORD dwTimeout
    // ************************************
    ///////////////////////////////////////////////////////////////////////////////
    // return : 0 -> timeout or error
    //          1 -> first event signal
    static DWORD Wait(HANDLE handle, DWORD dwTimeout);
    ///////////////////////////////////////////////////////////////////////////////
    // return : 1 -> first event signal
    //          throw exception on timeout or error
    static DWORD WaitEx(HANDLE handle, DWORD dwTimeout);
    ///////////////////////////////////////////////////////////////////////////////
    // return : 0 -> timeout or error
    //          1 -> first event signal
    //          n -> n th event signal
    static DWORD Wait(LPHANDLE handle, BOOL bWaitForAll, DWORD dwTimeout, int nNoOfHandle);
    ///////////////////////////////////////////////////////////////////////////////
    // return : 1 -> first event signal
    //          n -> n th event signal
    //          throw exception on timeout or error
    static DWORD WaitEx(LPHANDLE handle, BOOL bWaitForAll, DWORD dwTimeout, int nNoOfHandle);
    static void Interrupt(DWORD threadId);

    // This sleep function will return after the delay in millis and
    // continue to process messages send to the Main UI message pump
    static void Sleep(DWORD millis);
};
