[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 15/50: controlport: convert rpcpmtconverter
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 15/50: controlport: convert rpcpmtconverter::to_pmt() if statement to a function object map |
Date: |
Wed, 15 Apr 2015 21:07:53 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit b1183b0ab68b139994fc4190b82307908331fa75
Author: Nate Goergen <address@hidden>
Date: Sun Mar 1 00:45:16 2015 -0600
controlport: convert rpcpmtconverter::to_pmt() if statement to a function
object map
---
.../include/gnuradio/rpcpmtconverters_thrift.h | 40 ++++-
.../controlport/thrift/rpcpmtconverters_thrift.cc | 179 +++++++++++++--------
2 files changed, 150 insertions(+), 69 deletions(-)
diff --git a/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h
b/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h
index 1bc819c..25c8b5f 100644
--- a/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h
+++ b/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h
@@ -23,16 +23,50 @@
#define RPCPMTCONVERTERS_THRIFT_H
#include <pmt/pmt.h>
+#include <boost/noncopyable.hpp>
+#include <boost/ptr_container/ptr_map.hpp>
#include "gnuradio_types.h"
-namespace GNURadio {
- typedef boost::shared_ptr<Knob> KnobPtr;
-}
namespace rpcpmtconverter
{
pmt::pmt_t to_pmt(const GNURadio::Knob& knob);
GNURadio::Knob from_pmt(const pmt::pmt_t& knob);
+
+ struct to_pmt_f {
+ to_pmt_f() {;}
+
+ virtual pmt::pmt_t operator()(const GNURadio::Knob& knob);
+ };
+
+ struct to_pmt_byte_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_short_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_int_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_long_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_double_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_string_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_bool_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_complex_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_f32vect_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_f64vect_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_s64vect_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_s32vect_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_s16vect_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_s8vect_f : public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+ struct to_pmt_c32vect_f: public to_pmt_f { pmt::pmt_t operator()(const
GNURadio::Knob& knob); };
+
+ class To_PMT : private boost::noncopyable {
+
+ public:
+ static To_PMT instance;
+
+ pmt::pmt_t operator()(const GNURadio::Knob& knob);
+
+ private:
+ To_PMT();
+
+ boost::ptr_map<GNURadio::BaseTypes::type, to_pmt_f> to_pmt_map;
+ };
}
#endif /* RPCPMTCONVERTERS_THRIFT_H */
diff --git a/gnuradio-runtime/lib/controlport/thrift/rpcpmtconverters_thrift.cc
b/gnuradio-runtime/lib/controlport/thrift/rpcpmtconverters_thrift.cc
index 9541f18..967f140 100644
--- a/gnuradio-runtime/lib/controlport/thrift/rpcpmtconverters_thrift.cc
+++ b/gnuradio-runtime/lib/controlport/thrift/rpcpmtconverters_thrift.cc
@@ -19,6 +19,7 @@
* Boston, MA 02110-1301, USA.
*/
+#include <boost/assign/ptr_map_inserter.hpp>
#include <gnuradio/rpcpmtconverters_thrift.h>
#include "gnuradio_types.h"
#include <gnuradio/gr_complex.h>
@@ -140,73 +141,119 @@ rpcpmtconverter::from_pmt(const pmt::pmt_t& knob)
return GNURadio::Knob();
}
+pmt::pmt_t rpcpmtconverter::to_pmt_byte_f::operator()(const GNURadio::Knob&
knob) {
+ return pmt::mp(knob.value.a_byte);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_short_f::operator()(const GNURadio::Knob&
knob) {
+ return pmt::mp(knob.value.a_short);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_int_f::operator()(const GNURadio::Knob&
knob) {
+ return pmt::mp(knob.value.a_int);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_long_f::operator()(const GNURadio::Knob&
knob) {
+ return pmt::mp(knob.value.a_long);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_double_f::operator()(const GNURadio::Knob&
knob) {
+ return pmt::mp(knob.value.a_double);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_string_f::operator()(const GNURadio::Knob&
knob) {
+ return pmt::string_to_symbol(knob.value.a_string);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_bool_f::operator()(const GNURadio::Knob&
knob) {
+ if (knob.value.a_bool)
+ return pmt::PMT_T;
+ else
+ return pmt::PMT_F;
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_complex_f::operator()(const GNURadio::Knob&
knob) {
+ gr_complexd cpx(knob.value.a_complex.re, knob.value.a_complex.im);
+ return pmt::from_complex(cpx);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_f32vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::vector<double> v_double = knob.value.a_f32vector;
+ std::vector<float> v(v_double.begin(), v_double.end());
+ return pmt::init_f32vector(v.size(), v);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_f64vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::vector<double> v = knob.value.a_f64vector;
+ return pmt::init_f64vector(v.size(), v);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_s64vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::vector<int64_t> v = knob.value.a_s64vector;
+ return pmt::init_s64vector(v.size(), v);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_s32vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::vector<int32_t> v = knob.value.a_s32vector;
+ return pmt::init_s32vector(v.size(), v);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_s16vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::vector<int16_t> v = knob.value.a_s16vector;
+ return pmt::init_s16vector(v.size(), v);
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_s8vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::basic_string<char> v = knob.value.a_s8vector;
+ return pmt::init_s8vector(v.size(), reinterpret_cast<const
int8_t*>(v.data()));
+}
+
+pmt::pmt_t rpcpmtconverter::to_pmt_c32vect_f::operator()(const GNURadio::Knob&
knob) {
+ std::vector<GNURadio::complex> v0 = knob.value.a_c32vector;
+ std::vector<GNURadio::complex>::iterator vitr;
+ std::vector<gr_complex> v;
+ for(vitr = v0.begin(); vitr != v0.end(); vitr++) {
+ v.push_back(gr_complex(vitr->re, vitr->im));
+ }
+ return pmt::init_c32vector(v.size(), v);
+}
+
+rpcpmtconverter::To_PMT rpcpmtconverter::To_PMT::instance;
+
+rpcpmtconverter::To_PMT::To_PMT()
+{
+
boost::assign::ptr_map_insert<to_pmt_bool_f>(to_pmt_map)(GNURadio::BaseTypes::BOOL);
+
boost::assign::ptr_map_insert<to_pmt_byte_f>(to_pmt_map)(GNURadio::BaseTypes::BYTE);
+
boost::assign::ptr_map_insert<to_pmt_short_f>(to_pmt_map)(GNURadio::BaseTypes::SHORT);
+
boost::assign::ptr_map_insert<to_pmt_int_f>(to_pmt_map)(GNURadio::BaseTypes::INT);
+
boost::assign::ptr_map_insert<to_pmt_long_f>(to_pmt_map)(GNURadio::BaseTypes::LONG);
+
boost::assign::ptr_map_insert<to_pmt_double_f>(to_pmt_map)(GNURadio::BaseTypes::DOUBLE);
+
boost::assign::ptr_map_insert<to_pmt_string_f>(to_pmt_map)(GNURadio::BaseTypes::STRING);
+
boost::assign::ptr_map_insert<to_pmt_complex_f>(to_pmt_map)(GNURadio::BaseTypes::COMPLEX);
+
boost::assign::ptr_map_insert<to_pmt_f32vect_f>(to_pmt_map)(GNURadio::BaseTypes::F32VECTOR);
+
boost::assign::ptr_map_insert<to_pmt_f64vect_f>(to_pmt_map)(GNURadio::BaseTypes::F64VECTOR);
+
boost::assign::ptr_map_insert<to_pmt_s64vect_f>(to_pmt_map)(GNURadio::BaseTypes::S64VECTOR);
+
boost::assign::ptr_map_insert<to_pmt_s32vect_f>(to_pmt_map)(GNURadio::BaseTypes::S32VECTOR);
+
boost::assign::ptr_map_insert<to_pmt_s16vect_f>(to_pmt_map)(GNURadio::BaseTypes::S16VECTOR);
+
boost::assign::ptr_map_insert<to_pmt_s8vect_f>(to_pmt_map)(GNURadio::BaseTypes::S8VECTOR);
+
boost::assign::ptr_map_insert<to_pmt_c32vect_f>(to_pmt_map)(GNURadio::BaseTypes::C32VECTOR);
+}
+
pmt::pmt_t
-rpcpmtconverter::to_pmt(const GNURadio::Knob& knob)
+rpcpmtconverter::to_pmt_f::operator()(const GNURadio::Knob& knob)
{
- if(knob.type == GNURadio::BaseTypes::BYTE) {
- return pmt::mp(knob.value.a_byte);
- }
- else if(knob.type == GNURadio::BaseTypes::SHORT) {
- return pmt::mp(knob.value.a_short);
- }
- else if(knob.type == GNURadio::BaseTypes::INT) {
- return pmt::mp(knob.value.a_int);
- }
- else if(knob.type == GNURadio::BaseTypes::LONG) {
- return pmt::mp(knob.value.a_long);
- }
- else if(knob.type == GNURadio::BaseTypes::DOUBLE) {
- return pmt::mp(knob.value.a_double);
- }
- else if(knob.type == GNURadio::BaseTypes::STRING) {
- return pmt::string_to_symbol(knob.value.a_string);
- }
- else if(knob.type == GNURadio::BaseTypes::BOOL) {
- if (knob.value.a_bool)
- return pmt::PMT_T;
- else
- return pmt::PMT_F;
- }
- else if(knob.type == GNURadio::BaseTypes::COMPLEX) {
- gr_complexd cpx(knob.value.a_complex.re, knob.value.a_complex.im);
- return pmt::from_complex(cpx);
- }
- else if(knob.type == GNURadio::BaseTypes::F32VECTOR) {
- std::vector<double> v_double = knob.value.a_f32vector;
- std::vector<float> v(v_double.begin(), v_double.end());
- return pmt::init_f32vector(v.size(), v);
- }
- else if(knob.type == GNURadio::BaseTypes::F64VECTOR) {
- std::vector<double> v = knob.value.a_f64vector;
- return pmt::init_f64vector(v.size(), v);
- }
- else if(knob.type == GNURadio::BaseTypes::S64VECTOR) {
- std::vector<int64_t> v = knob.value.a_s64vector;
- return pmt::init_s64vector(v.size(), v);
- }
- else if(knob.type == GNURadio::BaseTypes::S32VECTOR) {
- std::vector<int32_t> v = knob.value.a_s32vector;
- return pmt::init_s32vector(v.size(), v);
- }
- else if(knob.type == GNURadio::BaseTypes::S16VECTOR) {
- std::vector<int16_t> v = knob.value.a_s16vector;
- return pmt::init_s16vector(v.size(), v);
- }
- else if(knob.type == GNURadio::BaseTypes::S8VECTOR) {
- std::basic_string<char> v = knob.value.a_s8vector;
- return pmt::init_s8vector(v.size(), reinterpret_cast<const
int8_t*>(v.data()));
- }
- else if(knob.type == GNURadio::BaseTypes::C32VECTOR) {
- std::vector<GNURadio::complex> v0 = knob.value.a_c32vector;
- std::vector<GNURadio::complex>::iterator vitr;
- std::vector<gr_complex> v;
- for(vitr = v0.begin(); vitr != v0.end(); vitr++) {
- v.push_back(gr_complex(vitr->re, vitr->im));
- }
- return pmt::init_c32vector(v.size(), v);
- }
- else {
- std::cerr << "Error: Don't know how to handle Knob Type: " << knob.type <<
std::endl; assert(0);
- }
+ std::cerr << "Error: Don't know how to handle Knob Type: " << knob.type <<
std::endl; assert(0);
return pmt::pmt_t();
}
+
+pmt::pmt_t
+rpcpmtconverter::To_PMT::operator()(const GNURadio::Knob& knob)
+{
+ return to_pmt_map[knob.type](knob);
+}
+
+pmt::pmt_t
+rpcpmtconverter::to_pmt(const GNURadio::Knob& knob)
+{
+ return rpcpmtconverter::To_PMT::instance(knob);
+}
- [Commit-gnuradio] [gnuradio] branch master updated (676d5cb -> b092142), git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 03/50: controlport: working controlport server using thrift., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 06/50: controlport: quick fix, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 02/50: ctrlport: thrift: "py" instead of "python" -- guessing a version thing, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 04/50: controlport: restructuring to add subdirs for different cp backends., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 18/50: controlport: improving transport layer throughput., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 07/50: controlport: Addes a FindThrift cmake module to find the Thrift headers, libraries, and Python files., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 17/50: controlport: convert to To_PMT registration objects, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 20/50: runtime: more generic version of prefs class., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 22/50: cmake: force QA tests to turn ControlPort off by default., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 15/50: controlport: convert rpcpmtconverter::to_pmt() if statement to a function object map,
git <=
- [Commit-gnuradio] [gnuradio] 01/50: Initial thrift definition for gnuradio, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 14/50: controlport: Thrift's binary type, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 09/50: controlport: cleanup and switching over to new Python common interface., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 23/50: controlport: cleaning up and using logger to display endpoint., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 34/50: controlport: replacement of nanosleep() with boost::sleep() in startup thread. Fix of merge error in booter_thrift., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 28/50: controlport: more cleaning up., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 31/50: controlport: moving the logger call that publishes Thrift's endpoint to i_impl()., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 24/50: controlport: adding performance and controlport monitor GRC blocks., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 29/50: controlport: changing the default port number on the Thrift interface to zero., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 21/50: controlport: Adds ability to configure Thrift through a config file, git, 2015/04/16