~bwy/+junk/gnash-temp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 
//   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//

#ifndef __CQUE_H__
#define __CQUE_H__

#include <string>
#include <boost/cstdint.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <deque>

#include "getclocktime.hpp"
#include "buffer.h"
#include "network.h"
#include "dsodefs.h" //For DSOEXPORT.

// _definst_ is the default instance name
namespace gnash
{

class CQue {
public:
    typedef std::deque<boost::shared_ptr<amf::Buffer> > que_t;
#ifdef USE_STATS_QUEUE
    typedef struct {
	struct timespec start;
	int		totalbytes;
	int		totalin;
	int		totalout;
    } que_stats_t;
#endif
    CQue();
    CQue(const std::string &str) { _name = str; };
    ~CQue();
    // Push data onto the que
    bool push(boost::uint8_t *data, int nbytes);
    bool push(boost::shared_ptr<amf::Buffer> data);
    // Pop the first date element off the que
    boost::shared_ptr<amf::Buffer> DSOEXPORT pop();
    // Peek at the first date element witjhout removing it from the que
    boost::shared_ptr<amf::Buffer> DSOEXPORT peek();
    // Get the number of elements in the que
    size_t DSOEXPORT size();
    // Wait for a condition variable to trigger
    void wait();
    // Notify a condition variable to trigger
    void notify();
    // Empty the que of all data. 
    void clear();
    // Remove a range of elements
    void remove(boost::shared_ptr<amf::Buffer> begin, boost::shared_ptr<amf::Buffer> end);
//     // Remove an element
//    void remove(boost::shared_ptr<amf::Buffer> it);
    void remove(boost::shared_ptr<amf::Buffer> it);
    // Merge sucessive buffers into one single larger buffer. This is for some
    // protocols, than have very long headers.
    boost::shared_ptr<amf::Buffer> DSOEXPORT merge(boost::shared_ptr<amf::Buffer> begin);
    boost::shared_ptr<amf::Buffer> DSOEXPORT merge();

    boost::shared_ptr<amf::Buffer> operator[] (int index) { return _que[index]; };
    
    // Dump the data to the terminal
    void dump();
#ifdef USE_STATS_QUEUE
    que_stats_t *stats() { return &_stats; };
#endif
    void setName(const std::string &str) { _name = str; }
    const std::string &getName() { return _name; }
private:
    // an optional name for the queue, only used for debugging messages to make them unique
    std::string		_name;
    // The queue itself
    que_t		_que;

    // A condition variable used to signal the other thread when the que has data
    boost::condition	_cond;
    // This is the mutex used by the condition variable. It needs to be separate from the
    // one used to lock access to the que.
    boost::mutex	_cond_mutex;
    // This is the mutex that controls access to the que.
    boost::mutex	_mutex;
#ifdef USE_STATS_QUEUE
    que_stats_t		_stats;
#endif
};
    
} // end of gnash namespace

#endif // end of __CQUE_H__

// local Variables:
// mode: C++
// indent-tabs-mode: t
// End: