Changeset 10:b0048ba6f3ca in xplra for src


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

Implemented the commands querying or setting multiple datarefs directly

Location:
src/xplra
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/xplra/GetMultiDataRefRequest.cc

    r8 r10  
    3939using xplra::GetMultiDataRefRequest;
    4040
     41using xplcommon::DataStream;
    4142using xplcommon::Util;
    4243
    4344//------------------------------------------------------------------------------
    4445
    45 GetMultiDataRefRequest::GetMultiDataRefRequest(uint8_t& result, size_t numTasks,
    46                                                xplcommon::DataStream& stream)
     46GetMultiDataRefRequest::GetMultiDataRefRequest(uint8_t& result,
     47                                               DataStream& stream)
    4748{
    4849    result = Protocol::RESULT_OK;
     50
     51    uint32_t numTasks = stream.readU32();
     52    if (!stream) return;
     53    if (numTasks==0 || numTasks>Protocol::MAX_MULTI_COUNT) {
     54        result = Protocol::RESULT_INVALID_COUNT;
     55        return;
     56    }
     57
    4958    for(size_t i = 0;
    5059        i<numTasks && result==Protocol::RESULT_OK && stream; ++i)
  • src/xplra/GetMultiDataRefRequest.h

    r8 r10  
    5050     * specifications from the given stream.
    5151     */
    52     GetMultiDataRefRequest(uint8_t& result, size_t numTasks,
    53                            xplcommon::DataStream& stream);
     52    GetMultiDataRefRequest(uint8_t& result, xplcommon::DataStream& stream);
    5453
    5554    /**
  • src/xplra/Protocol.h

    r9 r10  
    5050     */
    5151    static const uint8_t COMMAND_SET_SINGLE = 0x02;
     52
     53    /**
     54     * Command: get the value of a multiple datarefs.
     55     */
     56    static const uint8_t COMMAND_GET_MULTI = 0x03;
     57
     58    /**
     59     * Command: set the value of a multiple datarefs.
     60     */
     61    static const uint8_t COMMAND_SET_MULTI = 0x04;
    5262
    5363    /**
  • src/xplra/ServerThread.cc

    r9 r10  
    131131        } else if (command==Protocol::COMMAND_SET_SINGLE) {
    132132            if (!handleSetSingle()) break;
     133        } else if (command==Protocol::COMMAND_GET_MULTI) {
     134            if (!handleGetMulti()) break;
     135        } else if (command==Protocol::COMMAND_SET_MULTI) {
     136            if (!handleSetMulti()) break;
    133137        } else if (command==Protocol::COMMAND_REGISTER_GET_MULTI) {
    134138            if (!handleRegisterGetMulti()) break;
     
    209213//------------------------------------------------------------------------------
    210214
     215bool ServerThread::handleGetMulti()
     216{
     217    uint8_t result = Protocol::RESULT_OK;
     218    GetMultiDataRefRequest* request =
     219        new GetMultiDataRefRequest(result, stream);
     220    if (result!=Protocol::RESULT_OK || !stream) {
     221        delete request;
     222        stream.writeU8(result);
     223        return stream;
     224    }
     225
     226    bool isOK = requestQueue.execute(request);
     227
     228    if (isOK) {
     229        request->writeResult(stream);
     230    }
     231
     232    delete request;
     233
     234    return isOK;
     235}
     236
     237//------------------------------------------------------------------------------
     238
     239bool ServerThread::handleSetMulti()
     240{
     241    uint8_t result = Protocol::RESULT_OK;
     242    SetMultiDataRefRequest* request =
     243        new SetMultiDataRefRequest(result, stream, true);
     244    if (result!=Protocol::RESULT_OK || !stream) {
     245        delete request;
     246        stream.writeU8(result);
     247        return stream;
     248    }
     249
     250    bool isOK = requestQueue.execute(request);
     251
     252    if (isOK) {
     253        request->writeResult(stream);
     254    }
     255
     256    delete request;
     257
     258    return isOK;
     259}
     260
     261//------------------------------------------------------------------------------
     262
    211263bool ServerThread::handleRegisterGetMulti()
    212264{
    213     uint32_t numTasks = stream.readU32();
    214     if (!stream) {
    215         return false;
    216     } else if (numTasks==0 || numTasks>Protocol::MAX_MULTI_COUNT) {
    217         stream.writeU8(Protocol::RESULT_INVALID_COUNT);
    218         return true;
    219     }
    220 
    221265    uint8_t result = Protocol::RESULT_OK;
    222266    GetMultiDataRefRequest* request =
    223         new GetMultiDataRefRequest(result, numTasks, stream);
     267        new GetMultiDataRefRequest(result, stream);
    224268    if (result!=Protocol::RESULT_OK || !stream) {
    225269        delete request;
     
    282326    uint8_t result = Protocol::RESULT_OK;
    283327    SetMultiDataRefRequest* request =
    284         new SetMultiDataRefRequest(result, stream);
     328        new SetMultiDataRefRequest(result, stream, false);
    285329    if (result!=Protocol::RESULT_OK || !stream) {
    286330        delete request;
  • src/xplra/ServerThread.h

    r9 r10  
    173173
    174174    /**
     175     * Handle the COMMAND_GET_MULTI command
     176     *
     177     * @return true, if we can continue, false if the thread should quit
     178     */
     179    bool handleGetMulti();
     180
     181    /**
     182     * Handle the COMMAND_SET_MULTI command
     183     *
     184     * @return true, if we can continue, false if the thread should quit
     185     */
     186    bool handleSetMulti();
     187
     188    /**
    175189     * Handle the COMMAND_REGISTER_GET_MULTI command
    176190     *
  • src/xplra/SetMultiDataRefRequest.cc

    r9 r10  
    4242
    4343SetMultiDataRefRequest::SetMultiDataRefRequest(uint8_t& result,
    44                                                DataStream& stream)
     44                                               DataStream& stream,
     45                                               bool readValues)
    4546{
    4647    result = Protocol::RESULT_OK;
     
    5657        i<numTasks && result==Protocol::RESULT_OK && stream; ++i) {
    5758        SetDataRefTask* task = SetDataRefTask::create(result, stream);
    58         if (task!=0) addTask(task);
     59        if (task!=0) {
     60            if (readValues) {
     61                task->readValue(stream);
     62            }
     63            addTask(task);
     64        }
    5965    }
    6066}
  • src/xplra/SetMultiDataRefRequest.h

    r9 r10  
    5050     * the given stream.
    5151     */
    52     SetMultiDataRefRequest(uint8_t& result, xplcommon::DataStream& stream);
     52    SetMultiDataRefRequest(uint8_t& result, xplcommon::DataStream& stream,
     53                           bool readValues);
    5354
    5455    /**
Note: See TracChangeset for help on using the changeset viewer.