Changeset 22:e29d792d1b5d in xplra for src/client/c


Ignore:
Timestamp:
02/04/13 18:47:38 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Moved the registration code into MultiBuffer

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

Legend:

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

    r21 r22  
    4646using xplra::Protocol;
    4747
     48using std::vector;
    4849using std::string;
    4950using std::min;
     
    231232//------------------------------------------------------------------------------
    232233
    233 MultiBuffer::MultiBuffer(XPlane& xplane) throw() :
     234MultiBuffer::MultiBuffer(XPlane& xplane, uint8_t registerCommand,
     235                         uint8_t unregisterCommand) throw() :
    234236    data(0),
    235237    xplane(xplane),
    236     unregisterCommand(0),
     238    registerCommand(registerCommand),
     239    unregisterCommand(unregisterCommand),
    237240    registeredID(-1)
    238241{
     
    329332        xplane.checkStream();
    330333
    331         unregisterCommand = doRegister();
     334        xplane.stream->writeU8(registerCommand);
     335        xplane.stream->writeU32(dataRefs.size());
     336
     337        for(vector<DataRef>::const_iterator i = dataRefs.begin();
     338            i!=dataRefs.end(); ++i)
     339        {
     340            const DataRef& dataRef = *i;
     341            xplane.stream->writeString(dataRef.name);
     342            xplane.stream->writeU8(dataRef.type);
     343            if (dataRef.isArray()) {
     344                xplane.stream->writeS32(dataRef.length);
     345                xplane.stream->writeS32(dataRef.offset);
     346            }
     347        }
    332348
    333349        xplane.stream->flush();
  • src/client/c/hu/varadiistvan/xplra/MultiBuffer.h

    r19 r22  
    133133
    134134    /**
     135     * The command to use for registering the buffer.
     136     */
     137    uint8_t registerCommand;
     138
     139    /**
    135140     * The command to unregister the buffer.
    136141     */
     
    147152     * Construct an empty buffer for the given XPlane instance.
    148153     */
    149     MultiBuffer(XPlane& xplane) throw();
     154    MultiBuffer(XPlane& xplane, uint8_t registerCommand,
     155                uint8_t unregisterCommand) throw();
    150156
    151157public:
     
    452458
    453459protected:
    454     /**
    455      * Perform the first part of the registration depending on the
    456      * actual type.
    457      */
    458     virtual uint8_t doRegister() throw(Exception) = 0;
    459 
    460460    /**
    461461     * Perform the main part of the execution if the buffer is
  • src/client/c/hu/varadiistvan/xplra/MultiGetter.cc

    r19 r22  
    5050//------------------------------------------------------------------------------
    5151
     52MultiGetter::MultiGetter(XPlane& xplane) throw() :
     53    MultiBuffer(xplane, Protocol::COMMAND_REGISTER_GET_MULTI,
     54                Protocol::COMMAND_UNREGISTER_GET_MULTI)
     55{
     56}
     57
     58//------------------------------------------------------------------------------
     59
    5260inline void MultiGetter::read(const DataRef& dataRef) throw(Exception)
    5361{
     
    7987      }
    8088    }
    81 }
    82 
    83 //------------------------------------------------------------------------------
    84 
    85 uint8_t MultiGetter::doRegister() throw(Exception)
    86 {
    87     xplane.stream->writeU8(Protocol::COMMAND_REGISTER_GET_MULTI);
    88     xplane.stream->writeU32(dataRefs.size());
    89 
    90     for(vector<DataRef>::const_iterator i = dataRefs.begin();
    91         i!=dataRefs.end(); ++i)
    92     {
    93         const DataRef& dataRef = *i;
    94         xplane.stream->writeString(dataRef.name);
    95         xplane.stream->writeU8(dataRef.type);
    96         if (dataRef.isArray()) {
    97             xplane.stream->writeS32(dataRef.length);
    98             xplane.stream->writeS32(dataRef.offset);
    99         }
    100     }
    101 
    102     return Protocol::COMMAND_UNREGISTER_GET_MULTI;
    10389}
    10490
  • src/client/c/hu/varadiistvan/xplra/MultiGetter.h

    r19 r22  
    5252protected:
    5353    /**
    54      * @see MultiBuffer::doRegister
    55      */
    56     virtual uint8_t doRegister() throw(Exception);
    57 
    58     /**
    5954     * @see MultiBuffer::doExecute
    6055     */
     
    7570
    7671//------------------------------------------------------------------------------
    77 // Inline definitions
    78 //------------------------------------------------------------------------------
    79 
    80 inline MultiGetter::MultiGetter(XPlane& xplane) throw() :
    81     MultiBuffer(xplane)
    82 {
    83 }
    84 
    85 //------------------------------------------------------------------------------
    8672
    8773} /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
  • src/client/c/hu/varadiistvan/xplra/MultiSetter.cc

    r21 r22  
    4747
    4848//------------------------------------------------------------------------------
     49
     50MultiSetter::MultiSetter(XPlane& xplane) throw() :
     51    MultiBuffer(xplane, Protocol::COMMAND_REGISTER_SET_MULTI,
     52                Protocol::COMMAND_UNREGISTER_SET_MULTI)
     53{
     54}
     55
    4956//------------------------------------------------------------------------------
    5057
     
    7683      }
    7784    }
    78 }
    79 
    80 //------------------------------------------------------------------------------
    81 
    82 uint8_t MultiSetter::doRegister() throw(Exception)
    83 {
    84     // FIXME: only the commands differ from those of MultiGetter
    85     xplane.stream->writeU8(Protocol::COMMAND_REGISTER_SET_MULTI);
    86     xplane.stream->writeU32(dataRefs.size());
    87 
    88     for(vector<DataRef>::const_iterator i = dataRefs.begin();
    89         i!=dataRefs.end(); ++i)
    90     {
    91         const DataRef& dataRef = *i;
    92         xplane.stream->writeString(dataRef.name);
    93         xplane.stream->writeU8(dataRef.type);
    94         if (dataRef.isArray()) {
    95             xplane.stream->writeS32(dataRef.length);
    96             xplane.stream->writeS32(dataRef.offset);
    97         }
    98     }
    99 
    100     return Protocol::COMMAND_UNREGISTER_SET_MULTI;
    10185}
    10286
  • src/client/c/hu/varadiistvan/xplra/MultiSetter.h

    r21 r22  
    5252protected:
    5353    /**
    54      * @see MultiBuffer::doRegister
    55      */
    56     virtual uint8_t doRegister() throw(Exception);
    57 
    58     /**
    5954     * @see MultiBuffer::doExecute
    6055     */
     
    7570
    7671//------------------------------------------------------------------------------
    77 // Inline definitions
    78 //------------------------------------------------------------------------------
    79 
    80 inline MultiSetter::MultiSetter(XPlane& xplane) throw() :
    81     MultiBuffer(xplane)
    82 {
    83 }
    84 
    85 //------------------------------------------------------------------------------
    8672
    8773} /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
Note: See TracChangeset for help on using the changeset viewer.