Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_vmcircbuf.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef _GR_VMCIRCBUF_H_
24 #define _GR_VMCIRCBUF_H_
25
26 #include <vector>
27
28 /*!
29  * \brief abstract class to implement doubly mapped virtual memory circular buffers
30  * \ingroup internal
31  */
32 class gr_vmcircbuf {
33  protected:
34   int    d_size;
35   char  *d_base;
36
37   // CREATORS
38   gr_vmcircbuf (int size) : d_size (size), d_base (0) {};
39
40  public:
41   virtual ~gr_vmcircbuf ();
42
43   // ACCESSORS
44   void *pointer_to_first_copy ()  const { return d_base; }
45   void *pointer_to_second_copy () const { return d_base + d_size; }
46 };
47
48 /*!
49  * \brief abstract factory for creating circular buffers
50  */
51 class gr_vmcircbuf_factory {
52  protected:
53   gr_vmcircbuf_factory () {};
54   virtual ~gr_vmcircbuf_factory ();
55
56  public:
57
58   /*!
59    * \brief return name of this factory
60    */
61   virtual const char *name () const = 0;
62
63   /*!
64    * \brief return granularity of mapping, typically equal to page size
65    */
66   virtual int granularity () = 0;
67
68   /*!
69    * \brief return a gr_vmcircbuf, or 0 if unable.
70    *
71    * Call this to create a doubly mapped circular buffer.
72    */
73   virtual gr_vmcircbuf *make (int size) = 0;
74 };
75
76 /*
77  * \brief pulls together all implementations of gr_vmcircbuf
78  */
79 class gr_vmcircbuf_sysconfig {
80  public:
81
82   /*
83    * \brief return the single instance of the default factory.
84    *
85    * returns the default factory to use if it's already defined,
86    * else find the first working factory and use it.
87    */
88   static gr_vmcircbuf_factory *get_default_factory ();
89
90     
91   static int granularity ()            { return get_default_factory()->granularity(); }
92   static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size);    }
93   
94
95   // N.B. not all factories are guaranteed to work.
96   // It's too hard to check everything at config time, so we check at runtime
97   static std::vector<gr_vmcircbuf_factory *> all_factories ();
98
99   // make this factory the default
100   static void set_default_factory (gr_vmcircbuf_factory *f);
101
102   /*!
103    * \brief  Does this factory really work?
104    *
105    * verbose = 0: silent
106    * verbose = 1: names of factories tested and results
107    * verbose = 2: all intermediate results
108    */
109   static bool test_factory (gr_vmcircbuf_factory *f, int verbose);
110
111   /*!
112    * \brief Test all factories, return true if at least one of them works
113    * verbose = 0: silent
114    * verbose = 1: names of factories tested and results
115    * verbose = 2: all intermediate results
116    */
117   static bool test_all_factories (int verbose);
118 };
119
120
121 #endif /* _GR_VMCIRCBUF_H_ */