From 062040ae70d6d340d1ff5df5456953ae63ce73fe Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sat, 26 Oct 2013 21:03:03 +0200 Subject: [PATCH] gr-fosphor: Move to the _impl paradigm Signed-off-by: Sylvain Munaut --- include/gnuradio/fosphor/glfw_sink_c.h | 41 +---------- lib/CMakeLists.txt | 2 +- lib/{glfw_sink_c.cc => glfw_sink_c_impl.cc} | 31 ++++---- lib/glfw_sink_c_impl.h | 79 +++++++++++++++++++++ 4 files changed, 97 insertions(+), 56 deletions(-) rename lib/{glfw_sink_c.cc => glfw_sink_c_impl.cc} (84%) create mode 100644 lib/glfw_sink_c_impl.h diff --git a/include/gnuradio/fosphor/glfw_sink_c.h b/include/gnuradio/fosphor/glfw_sink_c.h index ca43ca4..65ddd9c 100644 --- a/include/gnuradio/fosphor/glfw_sink_c.h +++ b/include/gnuradio/fosphor/glfw_sink_c.h @@ -25,46 +25,16 @@ #include #include -#include - -struct fosphor; -struct GLFWwindow; namespace gr { namespace fosphor { - class fifo; - /*! - * \brief Main fosphor sink for GL spectrum display + * \brief Main fosphor sink for GL spectrum display (GLFW version) * \ingroup fosphor */ - class GR_FOSPHOR_API glfw_sink_c : public gr::sync_block + class GR_FOSPHOR_API glfw_sink_c : virtual public gr::sync_block { - private: - glfw_sink_c(); - - void worker(); - static void _worker(glfw_sink_c *obj); - - void glfw_render(void); - void glfw_cb_reshape(int w, int h); - void glfw_cb_key(int key, int scancode, int action, int mods); - - static void _glfw_cb_reshape(GLFWwindow *wnd, int w, int h); - static void _glfw_cb_key(GLFWwindow *wnd, int key, int scancode, int action, int mods); - - gr::thread::thread d_worker; - bool d_active; - - GLFWwindow *d_window; - - fifo *d_fifo; - struct fosphor *d_fosphor; - int d_width, d_height; - int d_db_ref, d_db_per_div_idx; - static const int k_db_per_div[]; - public: typedef boost::shared_ptr sptr; @@ -77,13 +47,6 @@ namespace gr { * creating new instances. */ static sptr make(); - - ~glfw_sink_c(); - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; } // namespace fosphor diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 442848e..9633a72 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -58,7 +58,7 @@ list(APPEND fosphor_sources fosphor/resource.c fosphor/resource_data.c fifo.cc - glfw_sink_c.cc + glfw_sink_c_impl.cc ) add_library(gnuradio-fosphor SHARED ${fosphor_sources}) diff --git a/lib/glfw_sink_c.cc b/lib/glfw_sink_c_impl.cc similarity index 84% rename from lib/glfw_sink_c.cc rename to lib/glfw_sink_c_impl.cc index 62059f3..3f6740d 100644 --- a/lib/glfw_sink_c.cc +++ b/lib/glfw_sink_c_impl.cc @@ -29,11 +29,10 @@ #include #include -#include - #include #include "fifo.h" +#include "glfw_sink_c_impl.h" extern "C" { #include "fosphor/fosphor.h" @@ -46,12 +45,12 @@ namespace gr { glfw_sink_c::sptr glfw_sink_c::make() { - return gnuradio::get_initial_sptr(new glfw_sink_c()); + return gnuradio::get_initial_sptr(new glfw_sink_c_impl()); } -const int glfw_sink_c::k_db_per_div[] = {1, 2, 5, 10, 20}; +const int glfw_sink_c_impl::k_db_per_div[] = {1, 2, 5, 10, 20}; -glfw_sink_c::glfw_sink_c() +glfw_sink_c_impl::glfw_sink_c_impl() : gr::sync_block("glfw_sink_c", gr::io_signature::make(1, 1, sizeof(gr_complex)), gr::io_signature::make(0, 0, 0)), @@ -65,7 +64,7 @@ glfw_sink_c::glfw_sink_c() this->d_worker = gr::thread::thread(_worker, this); } -glfw_sink_c::~glfw_sink_c() +glfw_sink_c_impl::~glfw_sink_c_impl() { this->d_active = false; this->d_worker.join(); @@ -74,7 +73,7 @@ glfw_sink_c::~glfw_sink_c() } int -glfw_sink_c::work( +glfw_sink_c_impl::work( int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) @@ -106,7 +105,7 @@ glfw_sink_c::work( } -void glfw_sink_c::worker() +void glfw_sink_c_impl::worker() { GLFWwindow *wnd; @@ -155,14 +154,14 @@ void glfw_sink_c::worker() glfwTerminate(); } -void glfw_sink_c::_worker(glfw_sink_c *obj) +void glfw_sink_c_impl::_worker(glfw_sink_c_impl *obj) { obj->worker(); } void -glfw_sink_c::glfw_render(void) +glfw_sink_c_impl::glfw_render(void) { /* Clear everything */ glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); @@ -183,7 +182,7 @@ glfw_sink_c::glfw_render(void) } void -glfw_sink_c::glfw_cb_reshape(int w, int h) +glfw_sink_c_impl::glfw_cb_reshape(int w, int h) { if (w < 0 || h < 0) glfwGetFramebufferSize(this->d_window, &w, &h); @@ -202,7 +201,7 @@ glfw_sink_c::glfw_cb_reshape(int w, int h) } void -glfw_sink_c::glfw_cb_key(int key, int scancode, int action, int mods) +glfw_sink_c_impl::glfw_cb_key(int key, int scancode, int action, int mods) { if (action != GLFW_PRESS) return; @@ -239,16 +238,16 @@ glfw_sink_c::glfw_cb_key(int key, int scancode, int action, int mods) } void -glfw_sink_c::_glfw_cb_reshape(GLFWwindow *wnd, int w, int h) +glfw_sink_c_impl::_glfw_cb_reshape(GLFWwindow *wnd, int w, int h) { - glfw_sink_c *sink = (glfw_sink_c *) glfwGetWindowUserPointer(wnd); + glfw_sink_c_impl *sink = (glfw_sink_c_impl *) glfwGetWindowUserPointer(wnd); sink->glfw_cb_reshape(w, h); } void -glfw_sink_c::_glfw_cb_key(GLFWwindow *wnd, int key, int scancode, int action, int mods) +glfw_sink_c_impl::_glfw_cb_key(GLFWwindow *wnd, int key, int scancode, int action, int mods) { - glfw_sink_c *sink = (glfw_sink_c *) glfwGetWindowUserPointer(wnd); + glfw_sink_c_impl *sink = (glfw_sink_c_impl *) glfwGetWindowUserPointer(wnd); sink->glfw_cb_key(key, scancode, action, mods); } diff --git a/lib/glfw_sink_c_impl.h b/lib/glfw_sink_c_impl.h new file mode 100644 index 0000000..36e0362 --- /dev/null +++ b/lib/glfw_sink_c_impl.h @@ -0,0 +1,79 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 Sylvain Munaut + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef INCLUDED_GR_FOSPHOR_GLFW_SINK_C_IMPL_H +#define INCLUDED_GR_FOSPHOR_GLFW_SINK_C_IMPL_H + +#include + +#include + +struct fosphor; +struct GLFWwindow; + +namespace gr { + namespace fosphor { + + class fifo; + + /*! + * \brief Main fosphor sink for GL spectrum display + * \ingroup fosphor + */ + class glfw_sink_c_impl : public glfw_sink_c + { + private: + void worker(); + static void _worker(glfw_sink_c_impl *obj); + + void glfw_render(void); + void glfw_cb_reshape(int w, int h); + void glfw_cb_key(int key, int scancode, int action, int mods); + + static void _glfw_cb_reshape(GLFWwindow *wnd, int w, int h); + static void _glfw_cb_key(GLFWwindow *wnd, int key, int scancode, int action, int mods); + + gr::thread::thread d_worker; + bool d_active; + + GLFWwindow *d_window; + + fifo *d_fifo; + struct fosphor *d_fosphor; + int d_width, d_height; + int d_db_ref, d_db_per_div_idx; + static const int k_db_per_div[]; + + public: + glfw_sink_c_impl(); + virtual ~glfw_sink_c_impl(); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + }; + + } // namespace fosphor +} // namespace gr + +#endif /* INCLUDED_GR_FOSPHOR_GLFW_SINK_C_IMPL_H */ +