Index: src/client/c/hu/Makefile.am
===================================================================
--- src/client/c/hu/Makefile.am	(revision 13)
+++ src/client/c/hu/Makefile.am	(revision 13)
@@ -0,0 +1,1 @@
+SUBDIRS=varadiistvan
Index: src/client/c/hu/Makefile.am
===================================================================
--- src/client/c/hu/Makefile.am	(revision 13)
+++ 	(revision )
@@ -1,1 +1,0 @@
-SUBDIRS=varadiistvan
Index: src/client/c/hu/varadiistvan/Makefile.am
===================================================================
--- src/client/c/hu/varadiistvan/Makefile.am	(revision 13)
+++ src/client/c/hu/varadiistvan/Makefile.am	(revision 13)
@@ -0,0 +1,1 @@
+SUBDIRS=xplra
Index: src/client/c/hu/varadiistvan/Makefile.am
===================================================================
--- src/client/c/hu/varadiistvan/Makefile.am	(revision 13)
+++ 	(revision )
@@ -1,1 +1,0 @@
-SUBDIRS=xplra
Index: src/client/c/hu/varadiistvan/xplra/.copyright
===================================================================
--- src/client/c/hu/varadiistvan/xplra/.copyright	(revision 13)
+++ src/client/c/hu/varadiistvan/xplra/.copyright	(revision 13)
@@ -0,0 +1,23 @@
+// 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.
Index: src/client/c/hu/varadiistvan/xplra/.copyright
===================================================================
--- src/client/c/hu/varadiistvan/xplra/.copyright	(revision 13)
+++ 	(revision )
@@ -1,23 +1,0 @@
-// 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.
Index: src/client/c/hu/varadiistvan/xplra/.namespace
===================================================================
--- src/client/c/hu/varadiistvan/xplra/.namespace	(revision 13)
+++ src/client/c/hu/varadiistvan/xplra/.namespace	(revision 13)
@@ -0,0 +1,3 @@
+hu
+varadiistvan
+xplra
Index: src/client/c/hu/varadiistvan/xplra/.namespace
===================================================================
--- src/client/c/hu/varadiistvan/xplra/.namespace	(revision 13)
+++ 	(revision )
@@ -1,3 +1,0 @@
-hu
-varadiistvan
-xplra
Index: src/client/c/hu/varadiistvan/xplra/.srcmessage
===================================================================
--- src/client/c/hu/varadiistvan/xplra/.srcmessage	(revision 13)
+++ src/client/c/hu/varadiistvan/xplra/.srcmessage	(revision 13)
@@ -0,0 +1,1 @@
+// This file is part of XPLRA, a remote-access plugin for X-Plane
Index: src/client/c/hu/varadiistvan/xplra/.srcmessage
===================================================================
--- src/client/c/hu/varadiistvan/xplra/.srcmessage	(revision 13)
+++ 	(revision )
@@ -1,1 +1,0 @@
-// This file is part of XPLRA, a remote-access plugin for X-Plane
Index: src/client/c/hu/varadiistvan/xplra/Exception.cc
===================================================================
--- src/client/c/hu/varadiistvan/xplra/Exception.cc	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/Exception.cc	(revision 14)
@@ -0,0 +1,103 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 "Exception.h"
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::xplra::Exception;
+using hu::varadiistvan::xplra::IOException;
+using hu::varadiistvan::xplra::ProtocolException;
+
+//------------------------------------------------------------------------------
+
+const char* Exception::what() const throw()
+{
+    return message.c_str();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+IOException::IOException(errorCode_t errorCode) throw() :
+    errorCode(errorCode)
+{
+    char buf[256];
+    snprintf(buf, sizeof(buf), "xplra::IOException: error code=%lu",
+             errorCode);
+    message = buf;
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+ProtocolException::ProtocolException(errorCode_t errorCode) throw() :
+    errorCode(errorCode)
+{
+    switch (errorCode) {
+      case INVALID_COMMAND:
+        message = "xplra::ProtocolException: invalid command";
+        break;
+      case UNKNOWN_DATAREF:
+        message = "xplra::ProtocolException: unknown dataref";
+        break;
+      case INVALID_TYPE:
+        message = "xplra::ProtocolException: invalid type";
+        break;
+      case INVALID_LENGTH:
+        message = "xplra::ProtocolException: invalid length";
+        break;
+      case INVALID_OFFSET:
+        message = "xplra::ProtocolException: invalid offset";
+        break;
+      case INVALID_COUNT:
+        message = "xplra::ProtocolException: invalid count";
+        break;
+      case INVALID_ID:
+        message = "xplra::ProtocolException: invalid ID";
+        break;
+      case OTHER:
+        message = "xplra::ProtocolException: other error";
+        break;
+      default:
+        message = "xplra::ProtocolException: unknown error";
+        break;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/client/c/hu/varadiistvan/xplra/Exception.h
===================================================================
--- src/client/c/hu/varadiistvan/xplra/Exception.h	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/Exception.h	(revision 14)
@@ -0,0 +1,239 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 HU_VARADIISTVAN_XPLRA_EXCEPTION_H
+#define HU_VARADIISTVAN_XPLRA_EXCEPTION_H
+//------------------------------------------------------------------------------
+
+#include <exception>
+
+#include <string>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace xplra {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for exceptions that can be thrown by the client.
+ */
+class Exception : public std::exception
+{
+protected:
+    /**
+     * The string representation of the error message.
+     */
+    std::string message;
+
+public:
+    /**
+     * Construct the exception with the given message.
+     */
+    Exception(const char* message) throw();
+
+protected:
+    /**
+     * Default constructor for children.
+     */
+    Exception() throw();
+
+public:
+    /**
+     * Destroy the exception
+     */
+    virtual ~Exception() throw();
+
+public:
+    /**
+     * Get a message.
+     */
+    virtual const char* what() const throw();
+};
+
+//------------------------------------------------------------------------------
+
+/**
+ * An I/O exception.
+ */
+class IOException : public Exception
+{
+public:
+    /**
+     * Type for the error code.
+     */
+    typedef unsigned long errorCode_t;
+
+private:
+    /**
+     * The error code.
+     */
+    errorCode_t errorCode;
+
+public:
+    /**
+     * Construct the exception.
+     */
+    IOException(errorCode_t errorCode) throw();
+
+
+    /**
+     * Get the error code.
+     */
+    errorCode_t getErrorCode() const throw();
+};
+
+//------------------------------------------------------------------------------
+
+/**
+ * An exception arising from the invalid use of the protocol, e.g. an
+ * invalid dataref.
+ */
+class ProtocolException : public Exception
+{
+public:
+    /**
+     * Type for the error codes.
+     */
+    typedef enum {
+        /// Invalid command issued
+        INVALID_COMMAND = 1,
+
+        /// Unknown dataref
+        UNKNOWN_DATAREF = 2,
+
+        /// Invalid type
+        INVALID_TYPE = 3,
+
+        /// Invalid length
+        INVALID_LENGTH = 4,
+
+        /// Invalid offset
+        INVALID_OFFSET = 5,
+
+        /// Invalid count
+        INVALID_COUNT = 6,
+
+        /// Invalid ID
+        INVALID_ID = 7,
+
+        /// Other error
+        OTHER = 255
+    } errorCode_t;
+
+private:
+    /**
+     * The error code.
+     */
+    errorCode_t errorCode;
+
+public:
+    /**
+     * Construct the exception.
+     */
+    ProtocolException(errorCode_t errorCode) throw();
+
+    /**
+     * Get the error code.
+     */
+    errorCode_t getErrorCode() const throw();
+};
+
+//------------------------------------------------------------------------------
+
+/**
+ * Exception to signify the fact the we are not connected to the
+ * simulator.
+ */
+class NotConnectedException : public Exception
+{
+public:
+    /**
+     * Construct the exception
+     */
+    NotConnectedException();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Exception::Exception(const char* message) throw() :
+    message(message)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline Exception::Exception() throw()
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline Exception::~Exception() throw()
+{
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+inline IOException::errorCode_t IOException::getErrorCode() const throw()
+{
+    return errorCode;
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+inline ProtocolException::errorCode_t
+ProtocolException::getErrorCode() const throw()
+{
+    return errorCode;
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+inline NotConnectedException::NotConnectedException() :
+    Exception("xplra::NotConnectedException: not connected to the simulator")
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_XPLRA_EXCEPTION_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/client/c/hu/varadiistvan/xplra/Makefile.am
===================================================================
--- src/client/c/hu/varadiistvan/xplra/Makefile.am	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/Makefile.am	(revision 14)
@@ -0,0 +1,20 @@
+AM_CXXFLAGS=$(VSCPL_CFLAGS) -I$(top_srcdir)/src/plugin/src
+
+lib_LTLIBRARIES=libxplra.la
+
+libxplra_la_SOURCES=\
+        XPlane.cc       \
+        Exception.cc    \
+        xplra.cc
+
+libxplra_la_LIBADD=$(VSCPL_LIBS)
+
+if TARGET_API_WIN32
+libxplra_la_LDFLAGS=-no-undefined
+endif
+
+include_xplradir=$(includedir)/hu/varadiistvan/xplra
+include_xplra_HEADERS=\
+        XPlane.h        \
+        Exception.h     \
+        xplra.h
Index: src/client/c/hu/varadiistvan/xplra/Makefile.am
===================================================================
--- src/client/c/hu/varadiistvan/xplra/Makefile.am	(revision 13)
+++ 	(revision )
@@ -1,13 +1,0 @@
-
-lib_LTLIBRARIES=libxplra.la
-
-libxplra_la_SOURCES=\
-        XPlane.cc
-
-if TARGET_API_WIN32
-libxplra_la_LDFLAGS=-no-undefined
-endif
-
-include_xplradir=$(includedir)/hu/varadiistvan/xplra
-include_xplra_HEADERS=\
-        XPlane.h
Index: src/client/c/hu/varadiistvan/xplra/XPlane.cc
===================================================================
--- src/client/c/hu/varadiistvan/xplra/XPlane.cc	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/XPlane.cc	(revision 14)
@@ -0,0 +1,158 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 "XPlane.h"
+
+#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
+#include <hu/varadiistvan/scpl/io/DataStream.h>
+
+#include <xplra/Protocol.h>
+
+#include <memory>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::xplra::XPlane;
+
+using hu::varadiistvan::scpl::io::LocalClientSocket;
+using hu::varadiistvan::scpl::io::LocalConnector;
+using hu::varadiistvan::scpl::io::DataStream;
+
+using xplra::Protocol;
+
+using std::auto_ptr;
+
+//------------------------------------------------------------------------------
+
+inline void XPlane::checkStream() throw(NotConnectedException, IOException)
+{
+    if (stream==0) {
+        throw NotConnectedException();
+    } else if (stream->failed()) {
+        throw IOException(stream->getErrorCode());
+    }
+}
+
+//------------------------------------------------------------------------------
+
+void XPlane::checkResult(uint8_t result) throw(ProtocolException)
+{
+    switch(result) {
+      case Protocol::RESULT_OK:
+        return;
+      case Protocol::RESULT_INVALID_COMMAND:
+        throw ProtocolException(ProtocolException::INVALID_COMMAND);
+      case Protocol::RESULT_UNKNOWN_DATAREF:
+        throw ProtocolException(ProtocolException::UNKNOWN_DATAREF);
+      case Protocol::RESULT_INVALID_TYPE:
+        throw ProtocolException(ProtocolException::INVALID_TYPE);
+      case Protocol::RESULT_INVALID_LENGTH:
+        throw ProtocolException(ProtocolException::INVALID_LENGTH);
+      case Protocol::RESULT_INVALID_OFFSET:
+        throw ProtocolException(ProtocolException::INVALID_OFFSET);
+      case Protocol::RESULT_INVALID_COUNT:
+        throw ProtocolException(ProtocolException::INVALID_COUNT);
+      case Protocol::RESULT_INVALID_ID:
+        throw ProtocolException(ProtocolException::INVALID_ID);
+      case Protocol::RESULT_OTHER_ERROR:
+      default:
+        throw ProtocolException(ProtocolException::OTHER);
+    }
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+XPlane::~XPlane() throw()
+{
+    disconnect();
+}
+
+//------------------------------------------------------------------------------
+
+void XPlane::connect() throw(IOException)
+{
+    if (socket!=0) return;
+
+    auto_ptr<LocalClientSocket> clientSocket(new LocalClientSocket("xplra",
+                                                                   &waiter));
+    LocalConnector& connector = clientSocket->getConnector();
+
+    while (!connector.connect()) {
+        if (connector.failed()) {
+            throw IOException(connector.getErrorCode());
+        }
+        waiter.wait();
+        if (waiter.failed()) {
+            throw IOException(waiter.getErrorCode());
+        }
+    }
+
+    socket = clientSocket.release();
+    stream = new DataStream(*socket);
+}
+
+//------------------------------------------------------------------------------
+
+void XPlane::disconnect() throw()
+{
+    if (socket==0) return;
+
+    delete stream; stream = 0;
+    delete socket; socket = 0;
+}
+
+//------------------------------------------------------------------------------
+
+int XPlane::getInt(const char* name) throw(Exception)
+{
+    checkStream();
+
+    stream->writeU8(Protocol::COMMAND_GET_SINGLE);
+    stream->writeString(name, strlen(name));
+    stream->writeU8(Protocol::TYPE_INT);
+    if (!stream->flush()) checkStream();
+
+    uint8_t result = stream->readU8();
+    checkStream();
+    checkResult(result);
+
+    int value = stream->readS32();
+    checkStream();
+    return value;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/client/c/hu/varadiistvan/xplra/XPlane.cc
===================================================================
--- src/client/c/hu/varadiistvan/xplra/XPlane.cc	(revision 13)
+++ 	(revision )
@@ -1,44 +1,0 @@
-// Copyright (c) 2013 by István Váradi
-
-// This file is part of XPLRA, a remote-access plugin for 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 "XPlane.h"
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::xplra::XPlane;
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/client/c/hu/varadiistvan/xplra/XPlane.h
===================================================================
--- src/client/c/hu/varadiistvan/xplra/XPlane.h	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/XPlane.h	(revision 14)
@@ -0,0 +1,151 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 HU_VARADIISTVAN_XPLRA_XPLANE_H
+#define HU_VARADIISTVAN_XPLRA_XPLANE_H
+//-----------------------------------------------------------------------------
+
+#include "Exception.h"
+
+#include <hu/varadiistvan/scpl/io/Waiter.h>
+
+#include <inttypes.h>
+
+//-----------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+class LocalClientSocket;
+class DataStream;
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace xplra {
+
+//------------------------------------------------------------------------------
+
+/**
+ * The main class to access X-Plane.
+ *
+ * The calls are synchronous and not thread-safe.
+ */
+class XPlane
+{
+private:
+    /**
+     * The waiter to use.
+     */
+    scpl::io::Waiter waiter;
+
+    /**
+     * The local client socket over which we are communicating with X-Plane.
+     */
+    scpl::io::LocalClientSocket* socket;
+
+    /**
+     * The data stream to handle the data conversions.
+     */
+    scpl::io::DataStream* stream;
+
+public:
+    /**
+     * Construct the object. It will not be connected to the simulator
+     * yet.
+     */
+    XPlane() throw();
+
+    /**
+     * Destroy the object. If connected, the connection will be
+     * closed.
+     */
+    ~XPlane() throw();
+
+    /**
+     * Connect to the simulator.
+     */
+    void connect() throw(IOException);
+
+    /**
+     * Check if we are connected to the simulator.
+     */
+    bool isConnected() const throw();
+
+    /**
+     * Disconnect from the simulator.
+     */
+    void disconnect() throw();
+
+    /**
+     * Get the integer value of the dataref with the given name.
+     */
+    int getInt(const char* name) throw(Exception);
+
+private:
+    /**
+     * Check if we have a stream and if it has not failed.
+     */
+    void checkStream() throw(NotConnectedException, IOException);
+
+    /**
+     * Check the given protocol result. If it signifies an error,
+     * throw a ProtocolException with the correct error code.
+     */
+    void checkResult(uint8_t result) throw(ProtocolException);
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline XPlane::XPlane() throw() :
+    socket(0),
+    stream(0)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline bool XPlane::isConnected() const throw()
+{
+    return socket!=0;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_XPLRA_XPLANE_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/client/c/hu/varadiistvan/xplra/XPlane.h
===================================================================
--- src/client/c/hu/varadiistvan/xplra/XPlane.h	(revision 13)
+++ 	(revision )
@@ -1,52 +1,0 @@
-// Copyright (c) 2013 by István Váradi
-
-// This file is part of XPLRA, a remote-access plugin for 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 HU_VARADIISTVAN_XPLRA_XPLANE_H
-#define HU_VARADIISTVAN_XPLRA_XPLANE_H
-//------------------------------------------------------------------------------
-
-namespace hu { namespace varadiistvan { namespace xplra {
-
-//------------------------------------------------------------------------------
-
-class XPlane
-{
-};
-
-//------------------------------------------------------------------------------
-
-} /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
-
-//------------------------------------------------------------------------------
-#endif // HU_VARADIISTVAN_XPLRA_XPLANE_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/client/c/hu/varadiistvan/xplra/xplra.cc
===================================================================
--- src/client/c/hu/varadiistvan/xplra/xplra.cc	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/xplra.cc	(revision 14)
@@ -0,0 +1,63 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 "xplra.h"
+
+#include "XPlane.h"
+#include "Exception.h"
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::xplra::XPlane;
+using hu::varadiistvan::xplra::Exception;
+
+//------------------------------------------------------------------------------
+
+extern "C" int xplra_connect()
+{
+    try {
+        XPlane xplane;
+        return 0;
+    } catch(const Exception& e) {
+        printf("xplra_connect failed: %s\n", e.what());
+        return -1;
+    }
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/client/c/hu/varadiistvan/xplra/xplra.h
===================================================================
--- src/client/c/hu/varadiistvan/xplra/xplra.h	(revision 14)
+++ src/client/c/hu/varadiistvan/xplra/xplra.h	(revision 14)
@@ -0,0 +1,49 @@
+/* Copyright (c) 2013 by István Váradi
+ *
+ * This file is part of XPLRA, a remote-access plugin for 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 HU_VARADIISTVAN_XPLRA_XPLRA_H
+#define HU_VARADIISTVAN_XPLRA_XPLRA_H
+/*----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*----------------------------------------------------------------------------*/
+
+int xplra_connect();
+
+/*----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+/*----------------------------------------------------------------------------*/
+#endif // HU_VARADIISTVAN_XPLRA_XPLRA_H
