GNU Radio 3.5.1 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2003 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef _GR_VMCIRCBUF_H_ 00024 #define _GR_VMCIRCBUF_H_ 00025 00026 #include <gr_core_api.h> 00027 #include <vector> 00028 00029 /*! 00030 * \brief abstract class to implement doubly mapped virtual memory circular buffers 00031 * \ingroup internal 00032 */ 00033 class GR_CORE_API gr_vmcircbuf { 00034 protected: 00035 int d_size; 00036 char *d_base; 00037 00038 // CREATORS 00039 gr_vmcircbuf (int size) : d_size (size), d_base (0) {}; 00040 00041 public: 00042 virtual ~gr_vmcircbuf (); 00043 00044 // ACCESSORS 00045 void *pointer_to_first_copy () const { return d_base; } 00046 void *pointer_to_second_copy () const { return d_base + d_size; } 00047 }; 00048 00049 /*! 00050 * \brief abstract factory for creating circular buffers 00051 */ 00052 class GR_CORE_API gr_vmcircbuf_factory { 00053 protected: 00054 gr_vmcircbuf_factory () {}; 00055 virtual ~gr_vmcircbuf_factory (); 00056 00057 public: 00058 00059 /*! 00060 * \brief return name of this factory 00061 */ 00062 virtual const char *name () const = 0; 00063 00064 /*! 00065 * \brief return granularity of mapping, typically equal to page size 00066 */ 00067 virtual int granularity () = 0; 00068 00069 /*! 00070 * \brief return a gr_vmcircbuf, or 0 if unable. 00071 * 00072 * Call this to create a doubly mapped circular buffer. 00073 */ 00074 virtual gr_vmcircbuf *make (int size) = 0; 00075 }; 00076 00077 /* 00078 * \brief pulls together all implementations of gr_vmcircbuf 00079 */ 00080 class GR_CORE_API gr_vmcircbuf_sysconfig { 00081 public: 00082 00083 /* 00084 * \brief return the single instance of the default factory. 00085 * 00086 * returns the default factory to use if it's already defined, 00087 * else find the first working factory and use it. 00088 */ 00089 static gr_vmcircbuf_factory *get_default_factory (); 00090 00091 00092 static int granularity () { return get_default_factory()->granularity(); } 00093 static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size); } 00094 00095 00096 // N.B. not all factories are guaranteed to work. 00097 // It's too hard to check everything at config time, so we check at runtime 00098 static std::vector<gr_vmcircbuf_factory *> all_factories (); 00099 00100 // make this factory the default 00101 static void set_default_factory (gr_vmcircbuf_factory *f); 00102 00103 /*! 00104 * \brief Does this factory really work? 00105 * 00106 * verbose = 0: silent 00107 * verbose = 1: names of factories tested and results 00108 * verbose = 2: all intermediate results 00109 */ 00110 static bool test_factory (gr_vmcircbuf_factory *f, int verbose); 00111 00112 /*! 00113 * \brief Test all factories, return true if at least one of them works 00114 * verbose = 0: silent 00115 * verbose = 1: names of factories tested and results 00116 * verbose = 2: all intermediate results 00117 */ 00118 static bool test_all_factories (int verbose); 00119 }; 00120 00121 00122 #endif /* _GR_VMCIRCBUF_H_ */