Index: src/xplcommon/Failable.h
===================================================================
--- src/xplcommon/Failable.h	(revision 14)
+++ src/xplcommon/Failable.h	(revision 20)
@@ -115,5 +115,5 @@
 
 inline Failable::Failable() :
-    errorCode(NO_ERROR)
+    errorCode(XPL_NO_ERROR)
 {
 }
@@ -123,5 +123,5 @@
 inline bool Failable::failed() const
 {
-    return errorCode!=NO_ERROR;
+    return errorCode!=XPL_NO_ERROR;
 }
 
@@ -137,5 +137,5 @@
 inline void Failable::repair()
 {
-    errorCode = NO_ERROR;
+    errorCode = XPL_NO_ERROR;
 }
 
Index: src/xplcommon/Thread.h
===================================================================
--- src/xplcommon/Thread.h	(revision 7)
+++ src/xplcommon/Thread.h	(revision 20)
@@ -46,4 +46,10 @@
 class Thread
 {
+public:
+    /**
+     * Sleep for the given number of milliseconds.
+     */
+    static void sleep(unsigned millis);
+
 public:
     /**
Index: src/xplcommon/WaitableEvent.h
===================================================================
--- src/xplcommon/WaitableEvent.h	(revision 17)
+++ src/xplcommon/WaitableEvent.h	(revision 20)
@@ -96,7 +96,7 @@
 //------------------------------------------------------------------------------
 
-// #include "win32/WaitableEvent.h"
+#include "win32/WaitableEvent.h"
 
-// namespace xplcommon { typedef win32::WaitableEvent WaitableEvent; }
+namespace xplcommon { typedef win32::WaitableEvent WaitableEvent; }
 
 //------------------------------------------------------------------------------
Index: src/xplcommon/Waiter.h
===================================================================
--- src/xplcommon/Waiter.h	(revision 17)
+++ src/xplcommon/Waiter.h	(revision 20)
@@ -83,7 +83,7 @@
 //------------------------------------------------------------------------------
 
-// #include "win32/Waiter.h"
+#include "win32/Waiter.h"
 
-// namespace xplcommon { typedef win32::Waiter Waiter; }
+namespace xplcommon { typedef win32::Waiter Waiter; }
 
 //------------------------------------------------------------------------------
Index: src/xplcommon/types.h
===================================================================
--- src/xplcommon/types.h	(revision 6)
+++ src/xplcommon/types.h	(revision 20)
@@ -49,5 +49,5 @@
 
 typedef DWORD errorCode_t;
-static const DWORD NO_ERROR = 0;
+static const DWORD XPL_NO_ERROR = 0;
 
 //------------------------------------------------------------------------------
@@ -58,5 +58,5 @@
 
 typedef int errorCode_t;
-static const int NO_ERROR = 0;
+static const int XPL_NO_ERROR = 0;
 
 //------------------------------------------------------------------------------
Index: src/xplcommon/win32/Event.cc
===================================================================
--- src/xplcommon/win32/Event.cc	(revision 20)
+++ src/xplcommon/win32/Event.cc	(revision 20)
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include "Event.h"
+
+#include "Waiter.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::win32::Event;
+
+//------------------------------------------------------------------------------
+
+void Event::addTo(Waiter& w)
+{
+    removeFromWaiter();
+    w.add(this);
+    waiter = &w;
+}
+
+//------------------------------------------------------------------------------
+
+void Event::removeFromWaiter()
+{
+    if (waiter!=0) {
+        waiter->remove(this);
+        waiter = 0;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Event.h
===================================================================
--- src/xplcommon/win32/Event.h	(revision 20)
+++ src/xplcommon/win32/Event.h	(revision 20)
@@ -0,0 +1,175 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WIN32_EVENT_H
+#define XPLCOMMON_WIN32_EVENT_H
+//------------------------------------------------------------------------------
+
+#include "../Failable.h"
+
+#include <windows.h>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace win32 {
+
+//------------------------------------------------------------------------------
+
+class Waiter;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Wrapper for an event.
+ */
+class Event : public ::xplcommon::Failable
+{
+private:
+    /**
+     * The handle of the event.
+     */
+    HANDLE handle;
+
+    /**
+     * The object waiting for the event.
+     */
+    Waiter* waiter;
+
+public:
+    /**
+     * Construct the event.
+     */
+    Event();
+
+    /**
+     * Destroy the event. It will be removed from the waiter if it is
+     * in one.
+     */
+    ~Event();
+
+    /**
+     * Get the handle of the event.
+     */
+    HANDLE getHandle() const;
+
+    /**
+     * Get the waiter.
+     */
+    Waiter* getWaiter() const;
+
+    /**
+     * Register the event with the given waiter. If it is already
+     * registered with a waiter, it will be removed from that.
+     */
+    void addTo(Waiter& w);
+
+    /**
+     * Remove the object from the waiter it is registered with.
+     */
+    void removeFromWaiter();
+
+    /**
+     * Set the event.
+     */
+    void fire();
+
+    /**
+     * Clear the event.
+     *
+     * @return if clearing succeeded.
+     */
+    bool clear();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Event::Event() :
+    handle(CreateEvent(0, true, false, 0)),
+    waiter(0)
+{
+    if (handle==0) setErrorCode(GetLastError());
+}
+
+//------------------------------------------------------------------------------
+
+inline Event::~Event()
+{
+    removeFromWaiter();
+    CloseHandle(handle);
+}
+
+//------------------------------------------------------------------------------
+
+inline HANDLE Event::getHandle() const
+{
+    return handle;
+}
+
+//------------------------------------------------------------------------------
+
+inline Waiter* Event::getWaiter() const
+{
+    return waiter;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Event::fire()
+{
+    if (!SetEvent(handle)) {
+        setErrorCode(GetLastError());
+    }
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Event::clear()
+{
+    if (!ResetEvent(handle)) {
+        setErrorCode(GetLastError());
+        return false;
+    } else {
+        return true;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::win32 */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WIN32_EVENT_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Makefile.am
===================================================================
--- src/xplcommon/win32/Makefile.am	(revision 3)
+++ src/xplcommon/win32/Makefile.am	(revision 20)
@@ -2,7 +2,15 @@
 
 libxplcommon_win32_la_SOURCES =	\
-	Thread.cc
+	Thread.cc		\
+	Event.cc		\
+	Overlapped.cc		\
+	Waiter.cc		\
+	WaitableEvent.cc
 
 include_xplcommon_win32dir=$(includedir)/xplcommon/win32
 include_xplcommon_win32_HEADERS=\
-	Thread.h
+	Thread.h		\
+	Event.h			\
+	Overlapped.h		\
+	Waiter.h		\
+	WaitableEvent.h
Index: src/xplcommon/win32/Overlapped.cc
===================================================================
--- src/xplcommon/win32/Overlapped.cc	(revision 20)
+++ src/xplcommon/win32/Overlapped.cc	(revision 20)
@@ -0,0 +1,52 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include "Overlapped.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::win32::Overlapped;
+
+//------------------------------------------------------------------------------
+
+void Overlapped::reset()
+{
+    memset(&overlapped, 0, sizeof(overlapped));
+    overlapped.hEvent = getHandle();
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Overlapped.h
===================================================================
--- src/xplcommon/win32/Overlapped.h	(revision 20)
+++ src/xplcommon/win32/Overlapped.h	(revision 20)
@@ -0,0 +1,113 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WIN32_OVERLAPPED_H
+#define XPLCOMMON_WIN32_OVERLAPPED_H
+//------------------------------------------------------------------------------
+
+#include "Event.h"
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace win32 {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A wrapper for an OVERLAPPED structure which also has an event
+ * associated with it. Instances of this class can be registered into and
+ * unregistered from a Waiter. The destructor removes the object from
+ * the waiter, if it is registered.
+ */
+class Overlapped : public Event
+{
+private:
+    /**
+     * The Windows OVERLAPPED structure.
+     */
+    OVERLAPPED overlapped;
+
+public:
+    /**
+     * Construct the object. The overlapped structure will be reset to
+     * 0, and the event handle will be set.
+     */
+    Overlapped();
+
+    /**
+     * Reset the overlapped structure and set its event handle.
+     */
+    void reset();
+
+    /**
+     * Get the pointer to the overlapped structure.
+     */
+    OVERLAPPED* get();
+
+    /**
+     * Get the pointer to the overlapped structure.
+     */
+    const OVERLAPPED* get() const;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Overlapped::Overlapped()
+{
+    reset();
+}
+
+//------------------------------------------------------------------------------
+
+inline OVERLAPPED* Overlapped::get()
+{
+    return &overlapped;
+}
+
+//------------------------------------------------------------------------------
+
+inline const OVERLAPPED* Overlapped::get() const
+{
+    return &overlapped;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::win32 */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WIN32_OVERLAPPED_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Thread.h
===================================================================
--- src/xplcommon/win32/Thread.h	(revision 3)
+++ src/xplcommon/win32/Thread.h	(revision 20)
@@ -45,4 +45,10 @@
 class Thread
 {
+public:
+    /**
+     * Sleep for the given number of milliseconds.
+     */
+    static void sleep(unsigned millis);
+
 private:
     /**
@@ -84,4 +90,11 @@
 //------------------------------------------------------------------------------
 
+inline void Thread::sleep(unsigned millis)
+{
+    Sleep(millis);
+}
+
+//------------------------------------------------------------------------------
+
 inline Thread::~Thread()
 {
Index: src/xplcommon/win32/WaitableEvent.cc
===================================================================
--- src/xplcommon/win32/WaitableEvent.cc	(revision 20)
+++ src/xplcommon/win32/WaitableEvent.cc	(revision 20)
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include "WaitableEvent.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::win32::WaitableEvent;
+
+//------------------------------------------------------------------------------
+
+bool WaitableEvent::check()
+{
+    DWORD result = WaitForSingleObject(getHandle(),
+                                       (getWaiter()==0) ? INFINITE : 0);
+    if (result==WAIT_FAILED) {
+        setErrorCode(GetLastError());
+        return false;
+    } else if (result==WAIT_OBJECT_0) {
+        clear();
+        return true;
+    } else {
+        return false;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/WaitableEvent.h
===================================================================
--- src/xplcommon/win32/WaitableEvent.h	(revision 20)
+++ src/xplcommon/win32/WaitableEvent.h	(revision 20)
@@ -0,0 +1,80 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WIN32_WAITABLEEVENT_H
+#define XPLCOMMON_WIN32_WAITABLEEVENT_H
+//------------------------------------------------------------------------------
+
+#include "Event.h"
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace win32 {
+
+//------------------------------------------------------------------------------
+
+/**
+ * An event which can be waited for.
+ */
+class WaitableEvent : public Event
+{
+public:
+    /**
+     * Construct the event.
+     */
+    WaitableEvent(Waiter* waiter = 0);
+
+    /**
+     * Check if the event is fired or not. If so, the fired status
+     * will be cleared.
+     */
+    bool check();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline WaitableEvent::WaitableEvent(Waiter* waiter)
+{
+    if (waiter!=0) addTo(*waiter);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::win32 */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WIN32_WAITABLEEVENT_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Waiter.cc
===================================================================
--- src/xplcommon/win32/Waiter.cc	(revision 20)
+++ src/xplcommon/win32/Waiter.cc	(revision 20)
@@ -0,0 +1,80 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include "Waiter.h"
+
+#include "Event.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::win32::Waiter;
+
+//------------------------------------------------------------------------------
+
+Waiter::~Waiter()
+{
+    while(!events.empty()) {
+        Event* event = *events.begin();
+        event->removeFromWaiter();
+    }
+}
+
+//------------------------------------------------------------------------------
+
+bool Waiter::wait(int timeout)
+{
+    if (numEvents==0) return true;
+
+    HANDLE handles[numEvents];
+    size_t j = 0;
+    for(events_t::const_iterator i = events.begin();
+        i!=events.end(); ++i, ++j)
+    {
+        handles[j] = (*i)->getHandle();
+    }
+
+    DWORD result = WaitForMultipleObjects(numEvents, handles, false,
+                                          (timeout<0) ? INFINITE : timeout);
+    if (result==WAIT_FAILED) {
+        setErrorCode(GetLastError());
+        return false;
+    } else {
+        return result!=WAIT_TIMEOUT;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Waiter.h
===================================================================
--- src/xplcommon/win32/Waiter.h	(revision 20)
+++ src/xplcommon/win32/Waiter.h	(revision 20)
@@ -0,0 +1,143 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WIN32_WAITER_H
+#define XPLCOMMON_WIN32_WAITER_H
+//------------------------------------------------------------------------------
+
+#include "../Failable.h"
+
+#include <set>
+
+#include <cassert>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace win32 {
+
+//------------------------------------------------------------------------------
+
+class Event;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Class that can be used to register OVERLAPPED structures and then
+ * wait for their events.
+ */
+class Waiter : public ::xplcommon::Failable
+{
+private:
+    /**
+     * Type for the mapping of events to overlapped objects.
+     */
+    typedef std::set<Event*> events_t;
+
+    /**
+     * The events to be handled.
+     */
+    events_t events;
+
+    /**
+     * The number of events.
+     */
+    size_t numEvents;
+
+public:
+    /**
+     * Construct the waiter.
+     */
+    Waiter();
+
+    /**
+     * Destroy the waiter. It will be removed from any Event
+     * objects it may be related to.
+     */
+    ~Waiter();
+
+    /**
+     * Wait for an event to occur with the given timeout.
+     *
+     * @return true if any of the events belonging to the Overlapped
+     * objects become ready, false if the timeout occurs.
+     */
+    bool wait(int timeout = -1);
+
+protected:
+    /**
+     * Add the given event to the set of those to be waited for.
+     */
+    void add(Event* event);
+
+    /**
+     * Remove the given event from the set of those to be waited for.
+     */
+    void remove(Event* event);
+
+    friend class Event;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Waiter::Waiter() :
+    numEvents(0)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline void Waiter::add(Event* event)
+{
+    events.insert(event);
+    ++numEvents;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Waiter::remove(Event* event)
+{
+    assert(numEvents>0);
+    --numEvents;
+    events.erase(event);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::win32 */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WIN32_WAITER_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
