Changeset 36:29e3b676c0c2 in xplra for src/plugin


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

Added a new command to query the versions

Location:
src/plugin/src/xplra
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.