Changeset 6:8dd4ca9966d0 in xplra for src/xplra/ServerThread.cc


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

Made all the single query operation work for all types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplra/ServerThread.cc

    r5 r6  
    110110        //             this, command);
    111111
    112         if (command==Protocol::CMD_GET_SINGLE) {
    113             string name = stream.readString();
    114             uint8_t type = stream.readU8();
    115             if (!stream) continue;
    116             // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: name='%s', type=0x%02x\n",
    117             //             this, name.c_str(), type);
    118             if (type==Protocol::TYPE_BYTE_ARRAY) {
    119                 int length = stream.readS32();
    120                 if (!stream) continue;
    121 
    122                 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: length=%lu\n",
    123                 //             this, static_cast<unsigned long>(length));
    124 
    125                 GetByteArrayDataRefTask* task =
    126                     new GetByteArrayDataRefTask(name, length);
    127                 TaskRequest request(task);
    128 
    129                 if (requestQueue.execute(&request)) {
    130                     // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: request executed\n");
    131                     stream.writeU8(Protocol::RESULT_OK);
    132                     int length = task->getLength();
    133                     stream.writeS32(length);
    134                     if (length>0) {
    135                         stream.write(task->getData(), length);
    136                     }
    137                 } else {
    138                     break;
    139                 }
    140             } else {
    141                 stream.writeU8(Protocol::RESULT_OTHER_ERROR);
    142             }
     112        if (command==Protocol::COMMAND_GET_SINGLE) {
     113            if (!handleGetSingle(stream)) break;
    143114        } else {
    144115            stream.writeU8(Protocol::RESULT_INVALID_COMMAND);
     
    152123//------------------------------------------------------------------------------
    153124
     125bool ServerThread::handleGetSingle(xplcommon::DataStream& stream)
     126{
     127    uint8_t result = Protocol::RESULT_OK;
     128
     129    GetDataRefTask* task = GetDataRefTask::create(result, stream);
     130
     131    if (!stream) return false;
     132    else if (task==0) {
     133        stream.writeU8(Protocol::RESULT_INVALID_TYPE);
     134        return true;
     135    }
     136
     137    TaskRequest request(task);
     138    if (!requestQueue.execute(&request)) return false;
     139
     140    if (task->isValid()) {
     141        stream.writeU8(Protocol::RESULT_OK);
     142        task->writeValue(stream);
     143    } else {
     144        stream.writeU8(Protocol::RESULT_UNKNOWN_DATAREF);
     145    }
     146
     147    return true;
     148}
     149
     150//------------------------------------------------------------------------------
     151
    154152// Local Variables:
    155153// mode: C++
Note: See TracChangeset for help on using the changeset viewer.