Changeset 17:2b7d9b08ce3f in xplra for src/client/c/hu


Ignore:
Timestamp:
01/31/13 16:56:18 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Setting of scalar values works

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

Legend:

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

    r16 r17  
    9090
    9191//------------------------------------------------------------------------------
     92
     93inline void XPlane::checkResult() throw(ProtocolException)
     94{
     95    uint8_t result = stream->readU8();
     96    checkStream();
     97    checkResult(result);
     98}
     99
     100//------------------------------------------------------------------------------
    92101//------------------------------------------------------------------------------
    93102
     
    142151    if (!stream->flush()) checkStream();
    143152
    144     uint8_t result = stream->readU8();
    145     checkStream();
    146     checkResult(result);
     153    checkResult();
    147154}
    148155
     
    285292//------------------------------------------------------------------------------
    286293
     294void XPlane::setScalar(const char* name, uint8_t type) throw(Exception)
     295{
     296    stream->writeU8(Protocol::COMMAND_SET_SINGLE);
     297    stream->writeString(name, strlen(name));
     298    stream->writeU8(type);
     299}
     300
     301//------------------------------------------------------------------------------
     302
     303void XPlane::setInt(const char* name, int value) throw(Exception)
     304{
     305    setScalar(name, Protocol::TYPE_INT);
     306    stream->writeS32(value);
     307    stream->flush();
     308    checkResult();
     309}
     310
     311//------------------------------------------------------------------------------
     312
     313void XPlane::setFloat(const char* name, float value) throw(Exception)
     314{
     315    setScalar(name, Protocol::TYPE_FLOAT);
     316    stream->writeFloat(value);
     317    stream->flush();
     318    checkResult();
     319}
     320
     321//------------------------------------------------------------------------------
     322
     323void XPlane::setDouble(const char* name, double value) throw(Exception)
     324{
     325    setScalar(name, Protocol::TYPE_DOUBLE);
     326    stream->writeDouble(value);
     327    stream->flush();
     328    checkResult();
     329}
     330
     331//------------------------------------------------------------------------------
     332
    287333// Local Variables:
    288334// mode: C++
  • src/client/c/hu/varadiistvan/xplra/XPlane.h

    r16 r17  
    183183    std::string getString(const char* name, size_t offset = 0) throw(Exception);
    184184
     185    /**
     186     * Set the given dataref to the given integer value.
     187     */
     188    void setInt(const char* name, int value) throw(Exception);
     189
     190    /**
     191     * Set the given dataref to the given float value.
     192     */
     193    void setFloat(const char* name, float value) throw(Exception);
     194
     195    /**
     196     * Set the given dataref to the given double value.
     197     */
     198    void setDouble(const char* name, double value) throw(Exception);
     199
    185200private:
    186201    /**
     
    194209     */
    195210    void checkResult(uint8_t result) throw(ProtocolException);
     211
     212    /**
     213     * Read and check the result.  If it signifies an error,
     214     * throw a ProtocolException with the correct error code.
     215     */
     216    void checkResult() throw(ProtocolException);
    196217
    197218    /**
     
    211232                    ssize_t length, size_t offset) throw(Exception);
    212233
     234
     235    /**
     236     * Issue the command to set a scalar value of the given type.
     237     */
     238    void setScalar(const char* name, uint8_t type) throw(Exception);
    213239};
    214240
Note: See TracChangeset for help on using the changeset viewer.