• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

cque.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 //
00018 
00019 #ifndef __CQUE_H__
00020 #define __CQUE_H__
00021 
00022 #include <string>
00023 #include <boost/cstdint.hpp>
00024 #include <boost/thread/mutex.hpp>
00025 #include <boost/thread/condition.hpp>
00026 #include <deque>
00027 
00028 #include "getclocktime.hpp"
00029 #include "buffer.h"
00030 #include "network.h"
00031 #include "dsodefs.h" //For DSOEXPORT.
00032 
00033 // _definst_ is the default instance name
00034 namespace gnash
00035 {
00036 
00037 class CQue {
00038 public:
00039     typedef std::deque<boost::shared_ptr<cygnal::Buffer> > que_t;
00040 #ifdef USE_STATS_QUEUE
00041     typedef struct {
00042         struct timespec start;
00043         int             totalbytes;
00044         int             totalin;
00045         int             totalout;
00046     } que_stats_t;
00047 #endif
00048     CQue();
00049     CQue(const std::string &str) { _name = str; };
00050     ~CQue();
00051     // Push data onto the que
00052     bool push(boost::uint8_t *data, int nbytes);
00053     bool push(boost::shared_ptr<cygnal::Buffer> data);
00054     // Pop the first date element off the que
00055     boost::shared_ptr<cygnal::Buffer> DSOEXPORT pop();
00056     // Peek at the first date element witjhout removing it from the que
00057     boost::shared_ptr<cygnal::Buffer> DSOEXPORT peek();
00058     // Get the number of elements in the que
00059     size_t DSOEXPORT size();
00060     // Wait for a condition variable to trigger
00061     void wait();
00062     // Notify a condition variable to trigger
00063     void notify();
00064     // Empty the que of all data. 
00065     void clear();
00066     // Remove a range of elements
00067     void remove(boost::shared_ptr<cygnal::Buffer> begin, boost::shared_ptr<cygnal::Buffer> end);
00068 //     // Remove an element
00069 //    void remove(boost::shared_ptr<cygnal::Buffer> it);
00070     void remove(boost::shared_ptr<cygnal::Buffer> it);
00071     // Merge sucessive buffers into one single larger buffer. This is for some
00072     // protocols, than have very long headers.
00073     boost::shared_ptr<cygnal::Buffer> DSOEXPORT merge(boost::shared_ptr<cygnal::Buffer> begin);
00074     boost::shared_ptr<cygnal::Buffer> DSOEXPORT merge();
00075 
00076     boost::shared_ptr<cygnal::Buffer> operator[] (int index) { return _que[index]; };
00077     
00078     // Dump the data to the terminal
00079     void dump();
00080 #ifdef USE_STATS_QUEUE
00081     que_stats_t *stats() { return &_stats; };
00082 #endif
00083     void setName(const std::string &str) { _name = str; }
00084     const std::string &getName() { return _name; }
00085 private:
00086     // an optional name for the queue, only used for debugging messages to make them unique
00087     std::string         _name;
00088     // The queue itself
00089     que_t               _que;
00090 
00091     // A condition variable used to signal the other thread when the que has data
00092     boost::condition    _cond;
00093     // This is the mutex used by the condition variable. It needs to be separate from the
00094     // one used to lock access to the que.
00095     boost::mutex        _cond_mutex;
00096     // This is the mutex that controls access to the que.
00097     boost::mutex        _mutex;
00098 #ifdef USE_STATS_QUEUE
00099     que_stats_t         _stats;
00100 #endif
00101 };
00102     
00103 } // end of gnash namespace
00104 
00105 #endif // end of __CQUE_H__
00106 
00107 // local Variables:
00108 // mode: C++
00109 // indent-tabs-mode: t
00110 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1