3 * Copyright 2003 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
23 #ifndef _GR_VMCIRCBUF_H_
24 #define _GR_VMCIRCBUF_H_
29 * \brief abstract class to implement doubly mapped virtual memory circular buffers
37 gr_vmcircbuf (int size) : d_size (size), d_base (0) {};
40 virtual ~gr_vmcircbuf ();
43 void *pointer_to_first_copy () const { return d_base; }
44 void *pointer_to_second_copy () const { return d_base + d_size; }
48 * \brief abstract factory for creating circular buffers
50 class gr_vmcircbuf_factory {
52 gr_vmcircbuf_factory () {};
53 virtual ~gr_vmcircbuf_factory ();
58 * \brief return name of this factory
60 virtual const char *name () const = 0;
63 * \brief return granularity of mapping, typically equal to page size
65 virtual int granularity () = 0;
68 * \brief return a gr_vmcircbuf, or 0 if unable.
70 * Call this to create a doubly mapped circular buffer.
72 virtual gr_vmcircbuf *make (int size) = 0;
76 * \brief pulls together all implementations of gr_vmcircbuf
78 class gr_vmcircbuf_sysconfig {
82 * \brief return the single instance of the default factory.
84 * returns the default factory to use if it's already defined,
85 * else find the first working factory and use it.
87 static gr_vmcircbuf_factory *get_default_factory ();
90 static int granularity () { return get_default_factory()->granularity(); }
91 static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size); }
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 ();
98 // make this factory the default
99 static void set_default_factory (gr_vmcircbuf_factory *f);
102 * \brief Does this factory really work?
104 * verbose = 0: silent
105 * verbose = 1: names of factories tested and results
106 * verbose = 2: all intermediate results
108 static bool test_factory (gr_vmcircbuf_factory *f, int verbose);
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
116 static bool test_all_factories (int verbose);
120 #endif /* _GR_VMCIRCBUF_H_ */