Changeset 36:29e3b676c0c2 in xplra


Ignore:
Timestamp:
02/10/13 08:21:47 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added a new command to query the versions

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/client/c/hu/varadiistvan/xplra/XPlane.cc

    r30 r36  
    193193//------------------------------------------------------------------------------
    194194
     195void XPlane::getVersions(int& xplaneVersion, int& xplmVersion, int& xplraVersion)
     196    throw(Exception)
     197{
     198    stream->writeU8(Protocol::COMMAND_GET_VERSIONS);
     199    stream->flush();
     200    checkResult();
     201
     202    xplaneVersion = stream->readS32();
     203    xplmVersion = stream->readS32();
     204    xplraVersion = stream->readS32();
     205
     206    checkStream();
     207}
     208
     209//------------------------------------------------------------------------------
     210
    195211void XPlane::getScalar(const char* name, uint8_t type) throw(Exception)
    196212{
  • src/client/c/hu/varadiistvan/xplra/XPlane.h

    r30 r36  
    145145
    146146    /**
     147     * Get the versions of X-Plane, XPLM and the XPLRA plugin.
     148     */
     149    void getVersions(int& xplaneVersion, int& xplmVersion, int& xplraVersion) throw(Exception);
     150
     151    /**
    147152     * Get the integer value of the dataref with the given name.
    148153     */
  • src/client/c/hu/varadiistvan/xplra/xplra.cc

    r29 r36  
    498498//------------------------------------------------------------------------------
    499499
     500extern "C"int xplra_get_versions(int connectionID,
     501                                 int* xplaneVersion, int* xplmVersion,
     502                                 int* xplraVersion)
     503{
     504    Connection* connection = ConnectionSlot::getValue(connectionID);
     505    if (connection==0) return -1;
     506    try {
     507        connection->getVersions(*xplaneVersion, *xplmVersion, *xplraVersion);
     508        return 0;
     509    } catch (...) {
     510        connection->handleException();
     511        return -1;
     512    }
     513}
     514
     515//------------------------------------------------------------------------------
     516
    500517extern "C" int xplra_get_int(int* value, int connectionID, const char* name)
    501518{
  • src/client/c/hu/varadiistvan/xplra/xplra.h

    r29 r36  
    130130
    131131/*----------------------------------------------------------------------------*/
     132
     133/**
     134 * Get the versions of X-Plane, the XPLM library and XPLRA
     135 */
     136int xplra_get_versions(int connectionID,
     137                       int* xplaneVersion, int* xplmVersion,
     138                       int* xplraVersion);
     139
     140/*----------------------------------------------------------------------------*/
    132141/* Single dataref support                                                     */
    133142/*----------------------------------------------------------------------------*/
  • src/client/python/xplra.py

    r35 r36  
    2727
    2828COMMAND_EXECUTE_SET_MULTI = 0x23
     29
     30COMMAND_GET_VERSIONS = 0x31
    2931
    3032TYPE_INT = 0x01
     
    135137        """Create a new multi-dataref setter for this X-Plane object."""
    136138        return MultiSetter(self)
     139
     140    def getVersions(self):
     141        """Get the versions of X-Plane, XPLM and XPLRA as a tuple."""
     142        self._writeU8(COMMAND_GET_VERSIONS)
     143        self._flush()
     144        self._checkResult()
     145        return (self._readS32(), self._readS32(), self._readS32())
    137146
    138147    def getInt(self, name):
     
    392401
    393402        self._registeredID = None
     403
     404    @property
     405    def values(self):
     406        """Query the values as a list."""
     407        if self._values is None:
     408            self.finalize()
     409        return self._values
    394410
    395411    def addInt(self, name):
  • src/plugin/src/xplra/ListenThread.cc

    r13 r36  
    5555    while(!quitEvent.check() && !quitEvent.failed() && !acceptor.failed()) {
    5656        if (acceptor.accept()) {
    57             ServerThread* serverThread = new ServerThread(requestQueue,
     57            ServerThread* serverThread = new ServerThread(*this,
     58                                                          requestQueue,
    5859                                                          acceptor);
    5960            serverThread->start();
  • src/plugin/src/xplra/ListenThread.h

    r13 r36  
    5454private:
    5555    /**
     56     * The version of X-Plane.
     57     */
     58    int xplaneVersion;
     59
     60    /**
     61     * The version of the XPLM library.
     62     */
     63    int xplmVersion;
     64
     65    /**
    5666     * The waiter used in the thread.
    5767     */
     
    7383     * Construct the thread.
    7484     */
    75     ListenThread();
     85    ListenThread(int xplaneVersion, int xplmVersion);
     86
     87    /**
     88     * Get the versions
     89     */
     90    void getVersions(int& xplane, int& xplm) const;
    7691
    7792    /**
     
    90105//------------------------------------------------------------------------------
    91106
    92 inline ListenThread::ListenThread() :
     107inline ListenThread::ListenThread(int xplaneVersion, int xplmVersion) :
    93108    Thread(true),
     109    xplaneVersion(xplaneVersion),
     110    xplmVersion(xplmVersion),
    94111    quitEvent(&waiter)
    95112{
     113}
     114
     115//------------------------------------------------------------------------------
     116
     117inline void ListenThread::getVersions(int& xplane, int& xplm) const
     118{
     119    xplane = xplaneVersion;
     120    xplm = xplmVersion;
    96121}
    97122
  • src/plugin/src/xplra/Protocol.h

    r13 r36  
    9292
    9393    /**
     94     * Command: get the versions of the simulator
     95     */
     96    static const uint8_t COMMAND_GET_VERSIONS = 0x31;
     97
     98    /**
    9499     * Data type: int
    95100     */
     
    176181     */
    177182    static const size_t MAX_MULTI_COUNT = 1024;
     183
     184    /**
     185     * The version of the plugin.
     186     */
     187    static const int version = 10;
    178188};
    179189
  • src/plugin/src/xplra/ServerThread.cc

    r13 r36  
    3131#include "ServerThread.h"
    3232
     33#include "ListenThread.h"
    3334#include "RequestQueue.h"
    3435#include "Protocol.h"
     
    7273//------------------------------------------------------------------------------
    7374
    74 ServerThread::ServerThread(RequestQueue& requestQueue, LocalAcceptor& acceptor) :
     75ServerThread::ServerThread(ListenThread& listenThread,
     76                           RequestQueue& requestQueue, LocalAcceptor& acceptor) :
    7577    Thread(true),
     78    listenThread(listenThread),
    7679    requestQueue(requestQueue),
    7780    bufferedStream(acceptor.getSocket(&waiter)),
     
    147150        } else if (command==Protocol::COMMAND_EXECUTE_SET_MULTI) {
    148151            if (!handleExecuteSetMulti()) break;
     152        } else if (command==Protocol::COMMAND_GET_VERSIONS) {
     153            if (!handleGetVersions()) break;
    149154        } else {
    150155            stream.writeU8(Protocol::RESULT_INVALID_COMMAND);
     
    384389//------------------------------------------------------------------------------
    385390
     391bool ServerThread::handleGetVersions()
     392{
     393    int xplaneVersion = 0;
     394    int xplmVersion = 0;
     395
     396    listenThread.getVersions(xplaneVersion, xplmVersion);
     397
     398    stream.writeU8(Protocol::RESULT_OK);
     399    stream.writeS32(xplaneVersion);
     400    stream.writeS32(xplmVersion);
     401    stream.writeS32(Protocol::version);
     402
     403    return true;
     404}
     405
     406//------------------------------------------------------------------------------
     407
    386408// Local Variables:
    387409// mode: C++
  • src/plugin/src/xplra/ServerThread.h

    r13 r36  
    4949//------------------------------------------------------------------------------
    5050
     51class ListenThread;
     52
    5153class RequestQueue;
    5254
     
    9597private:
    9698    /**
     99     * The listen thread this server was started by.
     100     */
     101    ListenThread& listenThread;
     102
     103    /**
    97104     * The request queue to use.
    98105     */
     
    139146     * given acceptor.
    140147     */
    141     ServerThread(RequestQueue& requestQueue,
     148    ServerThread(ListenThread& listenThread, RequestQueue& requestQueue,
    142149                 hu::varadiistvan::scpl::io::LocalAcceptor& acceptor);
    143150
     
    227234     */
    228235    bool handleExecuteSetMulti();
     236
     237    /**
     238     * Handle the COMMAND_GET_VERSIONS command
     239     *
     240     * @return true, if we can continue, false if the thread should quit
     241     */
     242    bool handleGetVersions();
    229243};
    230244
  • src/plugin/src/xplra/plugin.cc

    r13 r36  
    8383    Util::debug("hu.varadiistvan.xplra.XPluginEnable called\n");
    8484    // XPLMRegisterFlightLoopCallback(&callback, 5.0, 0);
    85     listenThread = new ListenThread();
     85
     86    int xplaneVersion = 0;
     87    int xplmVersion = 0;
     88    XPLMHostApplicationID hostID = 0;
     89    XPLMGetVersions(&xplaneVersion, &xplmVersion, &hostID);
     90
     91    listenThread = new ListenThread(xplaneVersion, xplmVersion);
    8692    listenThread->start();
    8793}
  • test/basicctest.c

    r29 r36  
    4242    int retval = 0;
    4343    const char* errorString = 0;
     44
     45    int xplaneVersion = 0;
     46    int xplmVersion = 0;
     47    int xplraVersion = 0;
     48
    4449    int numEngines = 0;
    4550    float spoolTime = 0.0;
     
    6974    }
    7075
     76    printf("Querying the versions...\n");
     77    if (xplra_get_versions(connectionID, &xplaneVersion,
     78                           &xplmVersion, &xplraVersion)<0) goto error;
     79    printf("X-Plane version: %d, XPLM: %d, XPLRA: %03d\n\n",
     80           xplaneVersion, xplmVersion, xplraVersion);
     81
    7182    printf("Querying the number of the engines...\n");
    7283    if (xplra_get_int(&numEngines, connectionID,
  • test/basictest.cc

    r25 r36  
    5353        printf("Connected to X-Plane.\n\n");
    5454
     55        int xplaneVersion = 0;
     56        int xplmVersion = 0;
     57        int xplraVersion = 0;
     58
     59        printf("Querying the versions...\n");
     60        xplane.getVersions(xplaneVersion, xplmVersion, xplraVersion);
     61        printf("X-Plane version: %d, XPLM: %d, XPLRA: %03d\n\n",
     62               xplaneVersion, xplmVersion, xplraVersion);
     63
    5564        printf("Querying the number of the engines...\n");
    5665        int numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines");
  • test/basictest.py

    r35 r36  
    1212        xplane.connect()
    1313        print "Connected to X-Plane."
     14        print
     15
     16        print "Querying the versions..."
     17        (xplaneVersion, xplmVersion, xplraVersion) = xplane.getVersions()
     18        print "X-Plane version: %d, XPLM: %d, XPLRA: %03d" % \
     19               (xplaneVersion, xplmVersion, xplraVersion)
    1420        print
    1521
Note: See TracChangeset for help on using the changeset viewer.