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 3, 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
38 gr_vmcircbuf (int size) : d_size (size), d_base (0) {};
41 virtual ~gr_vmcircbuf ();
44 void *pointer_to_first_copy () const { return d_base; }
45 void *pointer_to_second_copy () const { return d_base + d_size; }
49 * \brief abstract factory for creating circular buffers
51 class gr_vmcircbuf_factory {
53 gr_vmcircbuf_factory () {};
54 virtual ~gr_vmcircbuf_factory ();
59 * \brief return name of this factory
61 virtual const char *name () const = 0;
64 * \brief return granularity of mapping, typically equal to page size
66 virtual int granularity () = 0;
69 * \brief return a gr_vmcircbuf, or 0 if unable.
71 * Call this to create a doubly mapped circular buffer.
73 virtual gr_vmcircbuf *make (int size) = 0;
77 * \brief pulls together all implementations of gr_vmcircbuf
79 class gr_vmcircbuf_sysconfig {
83 * \brief return the single instance of the default factory.
85 * returns the default factory to use if it's already defined,
86 * else find the first working factory and use it.
88 static gr_vmcircbuf_factory *get_default_factory ();
91 static int granularity () { return get_default_factory()->granularity(); }
92 static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size); }
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 ();
99 // make this factory the default
100 static void set_default_factory (gr_vmcircbuf_factory *f);
103 * \brief Does this factory really work?
105 * verbose = 0: silent
106 * verbose = 1: names of factories tested and results
107 * verbose = 2: all intermediate results
109 static bool test_factory (gr_vmcircbuf_factory *f, int verbose);
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
117 static bool test_all_factories (int verbose);
121 #endif /* _GR_VMCIRCBUF_H_ */