gr-baz Package
baz_native_callback.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2004,2013 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 /*
00024  * gr-baz by Balint Seeber (http://spench.net/contact)
00025  * Information, documentation & samples: http://wiki.spench.net/wiki/gr-baz
00026  */
00027 
00028 #ifndef INCLUDED_BAZ_NATIVE_CALLBACK_X_H
00029 #define INCLUDED_BAZ_NATIVE_CALLBACK_X_H
00030 
00031 #include <gr_sync_block.h>
00032 
00033 class BAZ_API baz_native_callback_x;
00034 
00035 /*
00036  * We use boost::shared_ptr's instead of raw pointers for all access
00037  * to gr_blocks (and many other data structures).  The shared_ptr gets
00038  * us transparent reference counting, which greatly simplifies storage
00039  * management issues.  This is especially helpful in our hybrid
00040  * C++ / Python system.
00041  *
00042  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
00043  *
00044  * As a convention, the _sptr suffix indicates a boost::shared_ptr
00045  */
00046 typedef boost::shared_ptr<baz_native_callback_x> baz_native_callback_x_sptr;
00047 
00048 class BAZ_API baz_native_callback_target
00049 {
00050 public:
00051   virtual void callback(float f, unsigned long samples_processed)=0; // FIXME: Item size
00052 };
00053 
00054 //typedef boost::shared_ptr<baz_native_callback_target> baz_native_callback_target_sptr;
00055 #define baz_native_callback_target_sptr gr_basic_block_sptr
00056 
00057 /*!
00058  * \brief Return a shared_ptr to a new instance of baz_native_callback_x.
00059  *
00060  * To avoid accidental use of raw pointers, baz_native_callback_x's
00061  * constructor is private.  howto_make_square2_ff is the public
00062  * interface for creating new instances.
00063  */
00064 BAZ_API baz_native_callback_x_sptr baz_make_native_callback_x (int size, baz_native_callback_target_sptr target, bool threshold_enable=false, float threshold_level=0.0);
00065 
00066 /*!
00067  * \brief square2 a stream of floats.
00068  * \ingroup block
00069  *
00070  * This uses the preferred technique: subclassing gr_sync_block.
00071  */
00072 class BAZ_API baz_native_callback_x : public gr_sync_block
00073 {
00074 private:
00075   // The friend declaration allows howto_make_square2_ff to
00076   // access the private constructor.
00077 
00078   friend baz_native_callback_x_sptr baz_make_native_callback_x (int size, baz_native_callback_target_sptr target, bool threshold_enable, float threshold_level);
00079 
00080   baz_native_callback_x (int size, baz_native_callback_target_sptr target, bool threshold_enable, float threshold_level);       // private constructor
00081 
00082   int d_size;
00083   baz_native_callback_target_sptr d_target;
00084   bool d_threshold_enable;
00085   float d_threshold_level;
00086 
00087   bool d_triggered;
00088   unsigned long d_samples_processed;
00089 
00090  public:
00091   ~baz_native_callback_x ();    // public destructor
00092 
00093   void set_size(int size);
00094   void set_target(baz_native_callback_target_sptr target);
00095   void set_threshold_enable(bool enable);
00096   void set_threshold_level(float threshold_level);
00097 
00098   inline int size() const
00099   { return d_size; }
00100   // Target
00101   inline bool threshold_enable() const
00102   { return d_threshold_enable; }
00103   inline float threshold_level() const
00104   { return d_threshold_level; }
00105 
00106   int work (int noutput_items,
00107             gr_vector_const_void_star &input_items,
00108             gr_vector_void_star &output_items);
00109 };
00110 
00111 #endif /* INCLUDED_BAZ_NATIVE_CALLBACK_X_H */