Changeset 26:77a23a961301 in xplra for src/client


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

The multi-dataref buffers are managed by the XPlane object

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

Legend:

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

    r22 r26  
    141141//------------------------------------------------------------------------------
    142142
     143void MultiBuffer::forgetRegistration() throw()
     144{
     145    registeredID = -1;
     146}
     147
     148//------------------------------------------------------------------------------
     149
    143150inline const MultiBuffer::DataRef* MultiBuffer::getLastDataRef() const throw()
    144151{
  • src/client/c/hu/varadiistvan/xplra/MultiBuffer.h

    r22 r26  
    155155                uint8_t unregisterCommand) throw();
    156156
    157 public:
    158157    /**
    159158     * Destroy the buffer. If it is registered, an attempt will be
     
    162161    virtual ~MultiBuffer() throw(Exception);
    163162
     163public:
    164164    /**
    165165     * Add an integer dataref.
     
    477477
    478478    /**
     479     * Forget the registration of this buffer. This is called from the
     480     * destructor of the XPlane object, since that closes the
     481     * connection anyway, so there is no need to unregister the
     482     * multi-buffers.
     483     */
     484    void forgetRegistration() throw();
     485
     486    /**
    479487     * Get the last dataref, or 0 if there are not datarefs yet.
    480488     */
     
    524532    getArray(size_t id, size_t offset) const
    525533        throw(InvalidIDException, TypeMismatchException);
     534
     535    friend class XPlane;
    526536};
    527537
  • src/client/c/hu/varadiistvan/xplra/MultiGetter.h

    r22 r26  
    4444class MultiGetter : public MultiBuffer
    4545{
    46 public:
     46private:
    4747    /**
    4848     * Construct the object for the given XPlane instance.
     
    6767     */
    6868    void read(const DataRef& dataRef) throw(Exception);
     69
     70    friend class XPlane;
    6971};
    7072
  • src/client/c/hu/varadiistvan/xplra/MultiSetter.h

    r22 r26  
    4444class MultiSetter : public MultiBuffer
    4545{
    46 public:
     46private:
    4747    /**
    4848     * Construct the object for the given XPlane instance.
     
    6767     */
    6868    void write(const DataRef& dataRef) const throw(Exception);
     69
     70    friend class XPlane;
    6971};
    7072
  • src/client/c/hu/varadiistvan/xplra/XPlane.cc

    r19 r26  
    3131#include "XPlane.h"
    3232
     33#include "MultiGetter.h"
     34#include "MultiSetter.h"
     35
    3336#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
    3437#include <hu/varadiistvan/scpl/io/DataStream.h>
     
    4144
    4245using hu::varadiistvan::xplra::XPlane;
     46using hu::varadiistvan::xplra::MultiGetter;
     47using hu::varadiistvan::xplra::MultiSetter;
    4348
    4449using hu::varadiistvan::scpl::io::LocalClientSocket;
     
    104109{
    105110    disconnect();
     111    for(multiBuffers_t::iterator i = multiBuffers.begin();
     112        i!=multiBuffers.end(); ++i)
     113    {
     114        MultiBuffer* buffer = *i;
     115        buffer->forgetRegistration();
     116        delete buffer;
     117    }
    106118}
    107119
     
    138150    delete stream; stream = 0;
    139151    delete socket; socket = 0;
     152}
     153
     154//------------------------------------------------------------------------------
     155
     156MultiGetter& XPlane::createMultiGetter() throw()
     157{
     158    MultiGetter* getter = new MultiGetter(*this);
     159    multiBuffers.insert(getter);
     160    return *getter;
     161}
     162
     163//------------------------------------------------------------------------------
     164
     165MultiSetter& XPlane::createMultiSetter() throw()
     166{
     167    MultiSetter* setter = new MultiSetter(*this);
     168    multiBuffers.insert(setter);
     169    return *setter;
     170}
     171
     172//------------------------------------------------------------------------------
     173
     174bool XPlane::destroyMultiBuffer(MultiBuffer& buffer) throw(Exception)
     175{
     176    multiBuffers_t::iterator i = multiBuffers.find(&buffer);
     177    if (i==multiBuffers.end()) return false;
     178
     179    multiBuffers.erase(i);
     180    delete &buffer;
     181
     182    return true;
    140183}
    141184
  • src/client/c/hu/varadiistvan/xplra/XPlane.h

    r19 r26  
    3535#include <hu/varadiistvan/scpl/io/Waiter.h>
    3636
     37#include <set>
     38
    3739#include <inttypes.h>
    3840
     
    4951
    5052namespace hu { namespace varadiistvan { namespace xplra {
     53
     54//------------------------------------------------------------------------------
     55
     56class MultiBuffer;
     57class MultiGetter;
     58class MultiSetter;
    5159
    5260//------------------------------------------------------------------------------
     
    6169private:
    6270    /**
     71     * Type for the set of multi-dataref buffers.
     72     */
     73    typedef std::set<MultiBuffer*> multiBuffers_t;
     74
     75    /**
    6376     * The waiter to use.
    6477     */
     
    7487     */
    7588    scpl::io::DataStream* stream;
     89
     90    /**
     91     * The buffers created by this object.
     92     */
     93    multiBuffers_t multiBuffers;
    7694
    7795public:
     
    84102    /**
    85103     * Destroy the object. If connected, the connection will be
    86      * closed.
     104     * closed. It destroys all existing buffers, so their references
     105     * become invalid.
    87106     */
    88107    ~XPlane() throw();
     
    102121     */
    103122    void disconnect() throw();
     123
     124    /**
     125     * Create a new getter of multiple datarefs and return a reference
     126     * to it.
     127     */
     128    MultiGetter& createMultiGetter() throw();
     129
     130    /**
     131     * Create a new setter of multiple datarefs and return a reference
     132     * to it.
     133     */
     134    MultiSetter& createMultiSetter() throw();
     135
     136    /**
     137     * Destroy the given getter or setter of multiple datarefs. As the
     138     * buffer is unregistered, if it has been registered previously,
     139     * and  unregistration may fail, this function might throw an
     140     * exception.
     141     *
     142     * @return if the buffer was found and could be destroyed
     143     */
     144    bool destroyMultiBuffer(MultiBuffer& buffer) throw(Exception);
    104145
    105146    /**
Note: See TracChangeset for help on using the changeset viewer.