S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_inplace_fifo_mux.h

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
00022  */
00023 
00033 #ifndef S3_INPLACE_FIFO_MUX_H
00034 #define S3_INPLACE_FIFO_MUX_H
00035 
00036 #include <s3fc/s3_inplace_fifo_base.h>
00037 #include <s3fc/s3_fifo_queue.h>
00038 #include <s3fc/s3_mutex.h>
00039 #include <s3fc/s3_condition.h>
00040 #include <vector>
00041 
00047 template<typename T>
00048 class s3_inplace_fifo_mux
00049 {
00050    // stub_queue controls dynamic state (i.e. stuff that changes all the time
00051    // during operation)
00052    // forward declaration required before friend [rfanner]
00053    class stub_queue;
00054    friend class stub_queue;
00055 
00056    // global lock
00057    s3_mutex state_lock;
00058    // queue that we are multiplexing
00059    s3_inplace_fifo_base<T>* queue;
00060    // list of stub queues
00061    std::vector<s3_inplace_fifo_mux<T>::stub_queue*> vqueue_list;
00062    // index of current stub queue in list of stub queues
00063    int current_idx;
00064    // started flag
00065    bool started;
00066    // auto-select flag
00067    bool auto_select;
00068   protected:
00086    class stub_queue : public s3_inplace_fifo_base<T>
00087    {
00088      protected:
00089       // condition used to wait on in disabled state
00090       s3_condition waiter;
00091       // mux that controls us
00092       s3_inplace_fifo_mux<T>* mux;
00093      public:
00098       stub_queue(s3_inplace_fifo_mux<T>* n_mux);
00103       virtual bool empty() const;
00108       virtual bool full() const;
00113       virtual unsigned int size() const;
00118       virtual void push(const T &t);
00123       virtual T pop();
00128       virtual T* open_input();
00133       virtual T* nbl_open_input();
00137       virtual void close_input(const T* t);
00142       virtual T* open_output();
00147       virtual T* nbl_open_output();
00151       virtual void close_output(const T* t);
00152      protected:
00160       void lock_select();
00166       void unlock_next();
00167    };
00168   public:
00177    s3_inplace_fifo_mux();
00183    ~s3_inplace_fifo_mux();
00191    void start();
00198    void stop();
00202    bool is_started() const;
00213    s3_inplace_fifo_base<T>& create_vqueue();
00226    void destroy_vqueue(const s3_inplace_fifo_base<T>& vq);
00227 #if 0
00228 
00240    void select_vqueue(const s3_inplace_fifo_base<T>& vq);
00241 #endif
00242 
00249    void set_queue(s3_inplace_fifo_base<T>& q);
00250 #if 0
00251 
00258    void set_auto_select(bool n_val);
00259 #endif
00260 };
00261 
00262 #include <s3fc/s3_inplace_fifo_mux.tcc>
00263 
00264 #endif

Send comments to: s3fc@stonethree.com SourceForge Logo