Changeset 33:080fa73274f8 in xplra for src/client


Ignore:
Timestamp:
02/09/13 11:19:09 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Using the multi-get and multi-set commands in unregistered multi-dataref getters and setters, respectively

Location:
src/client/c/hu/varadiistvan/xplra
Files:
5 edited

Legend:

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

    r26 r33  
    339339        xplane.checkStream();
    340340
    341         xplane.stream->writeU8(registerCommand);
    342         xplane.stream->writeU32(dataRefs.size());
    343 
    344         for(vector<DataRef>::const_iterator i = dataRefs.begin();
    345             i!=dataRefs.end(); ++i)
    346         {
    347             const DataRef& dataRef = *i;
    348             xplane.stream->writeString(dataRef.name);
    349             xplane.stream->writeU8(dataRef.type);
    350             if (dataRef.isArray()) {
    351                 xplane.stream->writeS32(dataRef.length);
    352                 xplane.stream->writeS32(dataRef.offset);
    353             }
    354         }
    355 
    356         xplane.stream->flush();
    357 
    358         uint8_t result = xplane.stream->readU8();
     341        writeSpec(registerCommand);
     342
    359343        uint32_t id = xplane.stream->readU32();
    360344        xplane.checkStream();
    361         xplane.checkResult(result);
    362345
    363346        registeredID = static_cast<int>(id);
     
    609592//------------------------------------------------------------------------------
    610593
     594void MultiBuffer::writeSpec(uint8_t command) const throw(Exception)
     595{
     596    xplane.stream->writeU8(command);
     597    xplane.stream->writeU32(dataRefs.size());
     598
     599    for(vector<DataRef>::const_iterator i = dataRefs.begin();
     600        i!=dataRefs.end(); ++i)
     601    {
     602        const DataRef& dataRef = *i;
     603        xplane.stream->writeString(dataRef.name);
     604        xplane.stream->writeU8(dataRef.type);
     605        if (dataRef.isArray()) {
     606            xplane.stream->writeS32(dataRef.length);
     607            xplane.stream->writeS32(dataRef.offset);
     608        }
     609    }
     610
     611    xplane.stream->flush();
     612    xplane.checkResult();
     613}
     614
     615//------------------------------------------------------------------------------
     616
    611617// Local Variables:
    612618// mode: C++
  • src/client/c/hu/varadiistvan/xplra/MultiBuffer.h

    r29 r33  
    475475    virtual void doExecuteUnregistered() throw(Exception) = 0;
    476476
     477    /**
     478     * Write the data specification with the given command. It also
     479     * checks the result
     480     */
     481    void writeSpec(uint8_t command) const throw(Exception);
     482
    477483private:
    478484    /**
  • src/client/c/hu/varadiistvan/xplra/MultiGetter.cc

    r22 r33  
    9999    xplane.checkResult();
    100100
    101     for(vector<DataRef>::const_iterator i = dataRefs.begin();
    102         i!=dataRefs.end(); ++i)
    103     {
    104         xplane.checkStream();
    105         const DataRef& dataRef = *i;
    106         read(dataRef);
    107     }
     101    readValues();
    108102}
    109103
     
    113107void MultiGetter::doExecuteUnregistered() throw(Exception)
    114108{
     109    writeSpec(Protocol::COMMAND_GET_MULTI);
     110
     111    readValues();
     112}
     113
     114//------------------------------------------------------------------------------
     115
     116void MultiGetter::readValues() throw(Exception)
     117{
    115118    for(vector<DataRef>::const_iterator i = dataRefs.begin();
    116119        i!=dataRefs.end(); ++i)
    117120    {
     121        xplane.checkStream();
    118122        const DataRef& dataRef = *i;
    119         xplane.stream->writeU8(Protocol::COMMAND_GET_SINGLE);
    120         xplane.stream->writeString(dataRef.name);
    121         xplane.stream->writeU8(dataRef.type);
    122         if (dataRef.isArray()) {
    123             xplane.stream->writeS32(dataRef.length);
    124             xplane.stream->writeS32(dataRef.offset);
    125         }
    126         xplane.stream->flush();
    127         xplane.checkResult();
    128123        read(dataRef);
    129124    }
  • src/client/c/hu/varadiistvan/xplra/MultiGetter.h

    r26 r33  
    6868    void read(const DataRef& dataRef) throw(Exception);
    6969
     70    /**
     71     * Read all the values.
     72     */
     73    void readValues() throw(Exception);
     74
    7075    friend class XPlane;
    7176};
  • src/client/c/hu/varadiistvan/xplra/MultiSetter.cc

    r22 r33  
    106106void MultiSetter::doExecuteUnregistered() throw(Exception)
    107107{
     108    xplane.stream->writeU8(Protocol::COMMAND_SET_MULTI);
     109    xplane.stream->writeU32(dataRefs.size());
    108110    for(vector<DataRef>::const_iterator i = dataRefs.begin();
    109111        i!=dataRefs.end(); ++i)
    110112    {
    111113        const DataRef& dataRef = *i;
    112         xplane.stream->writeU8(Protocol::COMMAND_SET_SINGLE);
    113114        xplane.stream->writeString(dataRef.name);
    114115        xplane.stream->writeU8(dataRef.type);
     
    118119        }
    119120        write(dataRef);
    120         xplane.stream->flush();
    121         xplane.checkResult();
    122121    }
     122    xplane.stream->flush();
     123    xplane.checkResult();
    123124}
    124125
Note: See TracChangeset for help on using the changeset viewer.