Changeset 7:bafe58db1509 in xplra for src


Ignore:
Timestamp:
01/04/13 12:50:45 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 3 'hg:/home/ivaradi/xplane/hg/xplra' '/'>, 'public')
Message:

Added support for setting values

Location:
src/xplra
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/xplra/GetDataRefTask.cc

    r6 r7  
    6969        if (!stream) return 0;
    7070
     71        if (length>Protocol::MAX_LENGTH) {
     72            result = Protocol::RESULT_INVALID_LENGTH;
     73            return 0;
     74        }
     75        if (offset<0) {
     76            result = Protocol::RESULT_INVALID_OFFSET;
     77            return 0;
     78        }
     79
    7180        if (type==Protocol::TYPE_FLOAT_ARRAY) {
    7281            return new GetFloatArrayDataRefTask(name, length, offset);
  • src/xplra/Makefile.am

    r6 r7  
    3030        TaskRequest.cc          \
    3131        DataRefTask.cc          \
    32         GetDataRefTask.cc
     32        GetDataRefTask.cc       \
     33        SetDataRefTask.cc
    3334
    3435libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS)
     
    4344        TaskRequest.h           \
    4445        DataRefTask.h           \
    45         GetDataRefTask.h
     46        GetDataRefTask.h        \
     47        SetDataRefTask.h
  • src/xplra/Protocol.h

    r6 r7  
    4545     */
    4646    static const uint8_t COMMAND_GET_SINGLE = 0x01;
     47
     48    /**
     49     * Command: set the value of a single dataref.
     50     */
     51    static const uint8_t COMMAND_SET_SINGLE = 0x02;
    4752
    4853    /**
     
    97102
    98103    /**
     104     * Result code: invalid length
     105     */
     106    static const uint8_t RESULT_INVALID_LENGTH = 0x04;
     107
     108    /**
     109     * Result code: invalid offset
     110     */
     111    static const uint8_t RESULT_INVALID_OFFSET = 0x05;
     112
     113    /**
    99114     * Result code: other error
    100115     */
    101116    static const uint8_t RESULT_OTHER_ERROR = 0xff;
     117
     118    /**
     119     * The maximal length we accept (in order to protect ourselves).
     120     */
     121    static const int MAX_LENGTH = 2048;
    102122};
    103123
  • src/xplra/ServerThread.cc

    r6 r7  
    3434#include "Protocol.h"
    3535#include "GetDataRefTask.h"
     36#include "SetDataRefTask.h"
    3637#include "TaskRequest.h"
    3738
     
    111112
    112113        if (command==Protocol::COMMAND_GET_SINGLE) {
    113             if (!handleGetSingle(stream)) break;
     114            if (!handleGetSingle()) break;
     115        } else if (command==Protocol::COMMAND_SET_SINGLE) {
     116            if (!handleSetSingle()) break;
    114117        } else {
    115118            stream.writeU8(Protocol::RESULT_INVALID_COMMAND);
     
    123126//------------------------------------------------------------------------------
    124127
    125 bool ServerThread::handleGetSingle(xplcommon::DataStream& stream)
     128bool ServerThread::handleGetSingle()
    126129{
    127130    uint8_t result = Protocol::RESULT_OK;
    128 
    129131    GetDataRefTask* task = GetDataRefTask::create(result, stream);
    130132
    131133    if (!stream) return false;
    132134    else if (task==0) {
    133         stream.writeU8(Protocol::RESULT_INVALID_TYPE);
     135        stream.writeU8(result);
    134136        return true;
    135137    }
     
    150152//------------------------------------------------------------------------------
    151153
     154bool ServerThread::handleSetSingle()
     155{
     156    uint8_t result = Protocol::RESULT_OK;
     157    SetDataRefTask* task = SetDataRefTask::create(result, stream);
     158
     159    if (!stream) return false;
     160    else if (task==0) {
     161        stream.writeU8(result);
     162        return true;
     163    }
     164
     165    TaskRequest request(task);
     166    if (!requestQueue.execute(&request)) return false;
     167
     168    stream.writeU8(task->isValid() ? Protocol::RESULT_OK :
     169                   Protocol::RESULT_UNKNOWN_DATAREF);
     170    return true;
     171}
     172
     173//------------------------------------------------------------------------------
     174
    152175// Local Variables:
    153176// mode: C++
  • src/xplra/ServerThread.h

    r6 r7  
    129129     * @return true, if we can continue, false if the thread should quit
    130130     */
    131     bool handleGetSingle(xplcommon::DataStream& stream);
     131    bool handleGetSingle();
     132
     133    /**
     134     * Handle the COMMAND_SET_SINGLE command
     135     *
     136     * @return true, if we can continue, false if the thread should quit
     137     */
     138    bool handleSetSingle();
    132139};
    133140
Note: See TracChangeset for help on using the changeset viewer.