Imported Upstream version 3.0
[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 2, 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  */
31 class gr_vmcircbuf {
32  protected:
33   int    d_size;
34   char  *d_base;
35
36   // CREATORS
37   gr_vmcircbuf (int size) : d_size (size), d_base (0) {};
38
39  public:
40   virtual ~gr_vmcircbuf ();
41
42   // ACCESSORS
43   void *pointer_to_first_copy ()  const { return d_base; }
44   void *pointer_to_second_copy () const { return d_base + d_size; }
45 };
46
47 /*!
48  * \brief abstract factory for creating circular buffers
49  */
50 class gr_vmcircbuf_factory {
51  protected:
52   gr_vmcircbuf_factory () {};
53   virtual ~gr_vmcircbuf_factory ();
54
55  public:
56
57   /*!
58    * \brief return name of this factory
59    */
60   virtual const char *name () const = 0;
61
62   /*!
63    * \brief return granularity of mapping, typically equal to page size
64    */
65   virtual int granularity () = 0;
66
67   /*!
68    * \brief return a gr_vmcircbuf, or 0 if unable.
69    *
70    * Call this to create a doubly mapped circular buffer.
71    */
72   virtual gr_vmcircbuf *make (int size) = 0;
73 };
74
75 /*
76  * \brief pulls together all implementations of gr_vmcircbuf
77  */
78 class gr_vmcircbuf_sysconfig {
79  public:
80
81   /*
82    * \brief return the single instance of the default factory.
83    *
84    * returns the default factory to use if it's already defined,
85    * else find the first working factory and use it.
86    */
87   static gr_vmcircbuf_factory *get_default_factory ();
88
89     
90   static int granularity ()            { return get_default_factory()->granularity(); }
91   static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size);    }
92   
93
94   // N.B. not all factories are guaranteed to work.
95   // It's too hard to check everything at config time, so we check at runtime
96   static std::vector<gr_vmcircbuf_factory *> all_factories ();
97
98   // make this factory the default
99   static void set_default_factory (gr_vmcircbuf_factory *f);
100
101   /*!
102    * \brief  Does this factory really work?
103    *
104    * verbose = 0: silent
105    * verbose = 1: names of factories tested and results
106    * verbose = 2: all intermediate results
107    */
108   static bool test_factory (gr_vmcircbuf_factory *f, int verbose);
109
110   /*!
111    * \brief Test all factories, return true if at least one of them works
112    * verbose = 0: silent
113    * verbose = 1: names of factories tested and results
114    * verbose = 2: all intermediate results
115    */
116   static bool test_all_factories (int verbose);
117 };
118
119
120 #endif /* _GR_VMCIRCBUF_H_ */