/*
 * Copyright (C) 2007-2023 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#ifndef BU_DUAL_FILTER_H
#define BU_DUAL_FILTER_H

#include "bu/filter.h"

namespace Bu
{
    template<typename Flt>
    class DualFilter : public Bu::Filter
    {
    public:
        DualFilter( Bu::Stream &rNext ) :
            Bu::Filter( rNext ),
            fRead( rNext ),
            fWrite( rNext )
        {
        }

        virtual ~DualFilter()
        {
        }

        virtual void start()
        {
            fRead.start();
            fWrite.start();
        }

        virtual Bu::size stop()
        {
            return fRead.stop() + fWrite.stop();
        }

        virtual void close()
        {
            Bu::Filter::close();
            fRead.close();
            fWrite.close();
        }

        virtual Bu::size read( void *pBuf, Bu::size iBytes )
        {
            return fRead.read( pBuf, iBytes );
        }

        virtual Bu::size write( void *pBuf, Bu::size iBytes )
        {
            return fWrite.write( pBuf, iBytes );
        }

        Flt &getReadFilter() { return fRead; }
        Flt &getWriteFilter() { return fWrite; }

    private:
        Flt fRead;
        Flt fWrite;
    };
};

#endif
