commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/50: Initial thrift definition for gnurad


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/50: Initial thrift definition for gnuradio
Date: Wed, 15 Apr 2015 21:07:50 +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 ef802329bd4ac846f7fb5b35432ebceb91480ce7
Author: Doug Geiger <address@hidden>
Date:   Fri Sep 19 16:28:33 2014 -0400

    Initial thrift definition for gnuradio
    
    It compiles!
    C++ binding work.
    Cmake integration is still TBD.
---
 .../include/gnuradio/rpcpmtconverters_thrift.h     |  38 ++++
 .../include/gnuradio/rpcserver_thrift.h            | 222 +++++++++++++++++++++
 gnuradio-runtime/lib/controlport/CMakeLists.txt    |   8 +-
 gnuradio-runtime/lib/controlport/gnuradio.thrift   |  97 +++++++++
 .../lib/controlport/rpcpmtconverters_thrift.cc     | 109 ++++++++++
 .../lib/controlport/rpcserver_thrift.cc            | 191 ++++++++++++++++++
 6 files changed, 664 insertions(+), 1 deletion(-)

diff --git a/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h 
b/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h
new file mode 100644
index 0000000..1bc819c
--- /dev/null
+++ b/gnuradio-runtime/include/gnuradio/rpcpmtconverters_thrift.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2014 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef RPCPMTCONVERTERS_THRIFT_H
+#define RPCPMTCONVERTERS_THRIFT_H
+
+#include <pmt/pmt.h>
+#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);
+}
+
+#endif /* RPCPMTCONVERTERS_THRIFT_H */
diff --git a/gnuradio-runtime/include/gnuradio/rpcserver_thrift.h 
b/gnuradio-runtime/include/gnuradio/rpcserver_thrift.h
new file mode 100644
index 0000000..8bb7776
--- /dev/null
+++ b/gnuradio-runtime/include/gnuradio/rpcserver_thrift.h
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2014 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef RPCSERVER_THRIFT_H
+#define RPCSERVER_THRIFT_H
+
+#include <gnuradio/rpcserver_base.h>
+#include <gnuradio/rpcpmtconverters_thrift.h>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <map>
+#include "ControlPort.h"
+#include "gnuradio_types.h"
+#include <boost/format.hpp>
+
+#define S(x) #x
+#define S_(x) S(x)
+#define S__LINE__ S_(__LINE__)
+
+class rpcserver_thrift : public virtual rpcserver_base, public 
GNURadio::ControlPortIf
+{
+public:
+  rpcserver_thrift();
+  virtual ~rpcserver_thrift();
+
+  void registerConfigureCallback(const std::string &id, const 
configureCallback_t callback);
+  void unregisterConfigureCallback(const std::string &id);
+
+  void registerQueryCallback(const std::string &id, const queryCallback_t 
callback);
+  void unregisterQueryCallback(const std::string &id);
+
+  virtual void set(const GNURadio::KnobMap&);
+
+  GNURadio::KnobMap get(const GNURadio::KnobIDList&);
+
+  GNURadio::KnobMap getRe(const GNURadio::KnobIDList&);
+
+  GNURadio::KnobPropMap properties(const GNURadio::KnobIDList&);
+
+  virtual void shutdown();
+
+private:
+  typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
+  ConfigureCallbackMap_t d_setcallbackmap;
+
+  typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
+  QueryCallbackMap_t d_getcallbackmap;
+
+  template<typename T, typename TMap> struct set_f
+          : public std::unary_function<T,void> {
+    set_f(TMap &_setcallbackmap, const priv_lvl_t &_cur_priv) :
+            d_setcallbackmap(_setcallbackmap), cur_priv(_cur_priv) {
+      ;
+    }
+
+    void operator()(const T& p)
+    {
+      ConfigureCallbackMap_t::const_iterator 
iter(d_setcallbackmap.find(p.first));
+      if(iter != d_setcallbackmap.end()) {
+        if(cur_priv <= iter->second.priv) {
+          (*iter->second.callback).post(pmt::PMT_NIL, 
rpcpmtconverter::to_pmt(p.second));
+        }
+        else {
+          std::cout << "Key " << p.first << " requires PRIVLVL <= "
+                  << iter->second.priv << " to set, currently at: "
+                  << cur_priv << std::endl;
+        }
+      }
+      else {
+        throw apache::thrift::TApplicationException(__FILE__ " " S__LINE__);
+      }
+    }
+
+    TMap& d_setcallbackmap;
+    const priv_lvl_t& cur_priv;
+  };
+
+  template<typename T, typename TMap>
+  struct get_f : public std::unary_function<T,void>
+  {
+    get_f(TMap &_getcallbackmap, const priv_lvl_t &_cur_priv, 
GNURadio::KnobMap &_outknobs) :
+            d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), 
outknobs(_outknobs)
+    {}
+
+    void operator()(const T& p)
+    {
+      QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
+      if(iter != d_getcallbackmap.end()) {
+        if(cur_priv <= iter->second.priv) {
+          outknobs[p] = 
rpcpmtconverter::from_pmt((*iter->second.callback).retrieve());
+        }
+        else {
+          std::cout << "Key " << iter->first << " requires PRIVLVL: <= "
+                  << iter->second.priv << " to get, currently at: "
+                  << cur_priv << std::endl;
+        }
+      }
+      else {
+        std::stringstream ss;
+        ss << "Ctrlport Key called with unregistered key (" << p << ")\n";
+        std::cout << ss.str();
+        throw apache::thrift::TApplicationException(__FILE__ " " S__LINE__);
+      }
+    }
+
+    TMap& d_getcallbackmap;
+    const priv_lvl_t& cur_priv;
+    GNURadio::KnobMap& outknobs;
+  };
+
+  template<typename T, typename TMap, typename TKnobMap>
+  struct get_all_f : public std::unary_function<T,void>
+  {
+    get_all_f(TMap &_getcallbackmap, const priv_lvl_t &_cur_priv, TKnobMap 
&_outknobs) :
+            d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), 
outknobs(_outknobs)
+    {;}
+
+    void operator()(const T& p)
+    {
+      if(cur_priv <= p.second.priv) {
+        outknobs[p.first] = 
rpcpmtconverter::from_pmt(p.second.callback->retrieve());
+      }
+      else {
+        std::cout << "Key " << p.first << " requires PRIVLVL <= "
+                << p.second.priv << " to get, currently at: "
+                << cur_priv << std::endl;
+      }
+    }
+
+    TMap& d_getcallbackmap;
+    const priv_lvl_t& cur_priv;
+    TKnobMap& outknobs;
+  };
+
+  template<typename T, typename TMap, typename TKnobMap>
+  struct properties_all_f : public std::unary_function<T,void>
+  {
+    properties_all_f(QueryCallbackMap_t &_getcallbackmap, const priv_lvl_t 
&_cur_priv, GNURadio::KnobPropMap &_outknobs)
+            :
+            d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), 
outknobs(_outknobs)
+    {;}
+
+    void operator()(const T& p)
+    {
+      if(cur_priv <= p.second.priv) {
+        GNURadio::KnobProp prop;
+        prop.type  = GNURadio::KnobType::KNOBDOUBLE;
+        prop.units = p.second.units;
+        prop.description = p.second.description;
+        prop.min   = rpcpmtconverter::from_pmt(p.second.min);
+        prop.max   = rpcpmtconverter::from_pmt(p.second.max);
+        prop.display = static_cast<uint32_t>(p.second.display);
+        outknobs[p.first] = prop;
+      }
+      else {
+        std::cout << "Key " << p.first << " requires PRIVLVL <= "
+                << p.second.priv << " to get, currently at: "
+                << cur_priv << std::endl;
+      }
+    }
+
+    TMap& d_getcallbackmap;
+    const priv_lvl_t& cur_priv;
+    TKnobMap& outknobs;
+  };
+
+  template<class T, typename TMap, typename TKnobMap>
+  struct properties_f : public std::unary_function<T,void>
+  {
+    properties_f(TMap &_getcallbackmap, const priv_lvl_t &_cur_priv, TKnobMap 
&_outknobs) :
+            d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), 
outknobs(_outknobs)
+    {;}
+
+    void operator()(const T& p)
+    {
+      typename TMap::const_iterator iter(d_getcallbackmap.find(p));
+      if(iter != d_getcallbackmap.end()) {
+        if(cur_priv <= iter->second.priv) {
+          GNURadio::KnobProp prop;
+          prop.type  = GNURadio::KnobType::KNOBDOUBLE;
+          prop.units = iter->second.units;
+          prop.description = iter->second.description;
+          prop.min   = rpcpmtconverter::from_pmt(iter->second.min);
+          prop.max   = rpcpmtconverter::from_pmt(iter->second.max);
+          prop.display = static_cast<uint32_t>(iter->second.display);
+          outknobs[p] = prop;
+        }
+        else {
+          std::cout << "Key " << iter->first << " requires PRIVLVL: <= " <<
+                  iter->second.priv << " to get, currently at: " << cur_priv 
<< std::endl;
+        }
+      }
+      else {
+        throw apache::thrift::TApplicationException(__FILE__ " " S__LINE__);
+      }
+    }
+
+    TMap& d_getcallbackmap;
+    const priv_lvl_t& cur_priv;
+    TKnobMap& outknobs;
+  };
+};
+
+#endif /* RPCSERVER_THRIFT_H */
\ No newline at end of file
diff --git a/gnuradio-runtime/lib/controlport/CMakeLists.txt 
b/gnuradio-runtime/lib/controlport/CMakeLists.txt
index 262c5ad..8777009 100644
--- a/gnuradio-runtime/lib/controlport/CMakeLists.txt
+++ b/gnuradio-runtime/lib/controlport/CMakeLists.txt
@@ -20,13 +20,19 @@
 if(ENABLE_GR_CTRLPORT)
 
 # Add definition so we can compile in ControlPort to the blocks.
-ADD_DEFINITIONS(-DGR_CTRLPORT)
+add_definitions(-DGR_CTRLPORT)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 list(APPEND gnuradio_ctrlport_sources
   ${CMAKE_CURRENT_SOURCE_DIR}/rpcmanager.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/rpcserver_aggregator.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/rpcserver_booter_aggregator.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/rpcserver_selector.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/rpcserver_thrift.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/rpcpmtconverters_thrift.cc
+  ${CMAKE_CURRENT_SOURCE_DIR}/gnuradio_types.cpp
+  ${CMAKE_CURRENT_SOURCE_DIR}/gnuradio_constants.cpp
 )
 
 ########################################################################
diff --git a/gnuradio-runtime/lib/controlport/gnuradio.thrift 
b/gnuradio-runtime/lib/controlport/gnuradio.thrift
new file mode 100644
index 0000000..ac928eb
--- /dev/null
+++ b/gnuradio-runtime/lib/controlport/gnuradio.thrift
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2014 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+namespace cpp GNURadio
+namespace python GNURadio
+
+struct complex {
+  1: double re;
+  2: double im;
+}
+
+enum BaseTypes { BOOL, BYTE, SHORT, LONG, DOUBLE, STRING, COMPLEX }
+
+union KnobBase {
+  1: bool a_bool;
+  2: byte a_byte;
+  3: i32 a_short;
+  4: i64 a_long;
+  5: double a_double;
+  6: string a_string;
+  7: complex a_complex;
+}
+
+struct Knob {
+  1: BaseTypes type;
+  2: KnobBase value;
+}
+
+typedef list<bool>   VectorB
+typedef list<byte>   VectorC
+typedef list<i32>    VectorI
+typedef list<double> VectorF
+typedef list<double> VectorD
+typedef list<string> VectorS
+typedef list<i64>   VectorL
+typedef list<i32>  VectorT
+
+enum KnobType { KNOBBOOL, KNOBCHAR, KNOBINT, KNOBDOUBLE, KNOBSTRING,
+                KNOBLONG, KNOBVECBOOL, KNOBVECCHAR, KNOBVECINT,
+                KNOBVECDOUBLE, KNOBVECSTRING, KNOBVECLONG, KNOBSHORT}
+
+const i32 DISPNULL = 0x0000
+const i32 DISPTIME = 0x0001
+const i32 DISPXY   = 0x0002
+const i32 DISPPSD  = 0x0004
+const i32 DISPSPEC = 0x0008
+const i32 DISPRAST = 0x0010
+const i32 DISPOPTCPLX    = 0x0100
+const i32 DISPOPTLOG     = 0x0200
+const i32 DISPOPTSTEM    = 0x0400
+const i32 DISPOPTSTRIP   = 0x0800
+const i32 DISPOPTSCATTER = 0x1000
+
+struct KnobProp {
+  1: KnobType    type,
+  2: string      units,
+  3: string      description,
+  4: i32         display,
+  5: Knob        min,
+  6: Knob        max,
+  7: Knob        defaultvalue
+}
+
+typedef list<string> KnobIDList
+typedef map<string, Knob> KnobMap
+typedef map<string, KnobProp> KnobPropMap
+typedef map<string, string> WaveformArgMap
+
+service StreamReceiver {
+        void push(1:VectorC data);
+}
+
+service ControlPort {
+        void setKnobs(1:KnobMap knobs);
+        KnobMap getKnobs(1:KnobIDList knobs);
+        KnobMap getRe(1:KnobIDList knobs);
+        KnobPropMap properties(1:KnobIDList knobs);
+        void shutdown();
+}
diff --git a/gnuradio-runtime/lib/controlport/rpcpmtconverters_thrift.cc 
b/gnuradio-runtime/lib/controlport/rpcpmtconverters_thrift.cc
new file mode 100644
index 0000000..bb2da62
--- /dev/null
+++ b/gnuradio-runtime/lib/controlport/rpcpmtconverters_thrift.cc
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2014 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gnuradio/rpcpmtconverters_thrift.h>
+#include "gnuradio_types.h"
+#include <iostream>
+
+GNURadio::Knob
+rpcpmtconverter::from_pmt(const pmt::pmt_t& knob)
+{
+  if(pmt::is_real(knob)) {
+
+    GNURadio::Knob result;
+    result.type = GNURadio::BaseTypes::DOUBLE;
+    result.value.__set_a_double(pmt::to_double(knob));
+    return result;
+  }
+  else if(pmt::is_symbol(knob)) {
+    std::string value = pmt::symbol_to_string(knob);
+    GNURadio::Knob result;
+    result.type = GNURadio::BaseTypes::STRING;
+    result.value.__set_a_string(value);
+    return result;
+  }
+  else if(pmt::is_integer(knob)) {
+    GNURadio::Knob result;
+    result.type = GNURadio::BaseTypes::LONG;
+    result.value.__set_a_long(pmt::to_long(knob));
+    return result;
+  }
+  else if(pmt::is_bool(knob)) {
+    GNURadio::Knob result;
+    result.type = GNURadio::BaseTypes::BOOL;
+    result.value.__set_a_bool(pmt::to_bool(knob));
+    return result;
+  }
+  else if(pmt::is_uint64(knob)) {
+    GNURadio::Knob result;
+    result.type = GNURadio::BaseTypes::LONG;
+    result.value.__set_a_long(pmt::to_uint64(knob));
+    return result;
+  }
+  else if(pmt::is_complex(knob)) {
+    GNURadio::Knob result;
+    result.type = GNURadio::BaseTypes::COMPLEX;
+    std::complex<double> tmp = pmt::to_complex(knob);
+    GNURadio::complex cpx;
+    cpx.re = tmp.real();
+    cpx.im = tmp.imag();
+    result.value.__set_a_complex(cpx);
+    return result;
+  } //TODO Vectors
+  else {
+    std::cerr << "Error: Don't know how to handle Knob Type (from): " << 
std::endl; assert(0);}
+  return GNURadio::Knob();
+}
+
+pmt::pmt_t
+rpcpmtconverter::to_pmt(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::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) {
+    std::complex<double> cpx(knob.value.a_complex.re, knob.value.a_complex.im);
+    return pmt::from_complex(cpx);
+  }
+  else {
+    std::cerr << "Error: Don't know how to handle Knob Type: " << knob.type << 
std::endl; assert(0);
+  }
+  return pmt::pmt_t();
+}
diff --git a/gnuradio-runtime/lib/controlport/rpcserver_thrift.cc 
b/gnuradio-runtime/lib/controlport/rpcserver_thrift.cc
new file mode 100644
index 0000000..6546dfe
--- /dev/null
+++ b/gnuradio-runtime/lib/controlport/rpcserver_thrift.cc
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2014 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#include <gnuradio/rpcserver_thrift.h>
+#include <iostream>
+#include <sstream>
+#include <stdexcept>
+#include <pmt/pmt.h>
+#include <thrift/protocol/TBinaryProtocol.h>
+#include <thrift/transport/TSocket.h>
+#include <thrift/transport/TTransportUtils.h>
+#include <boost/xpressive/xpressive.hpp>
+#include "ControlPort.h"
+
+#define DEBUG 0
+
+using namespace rpcpmtconverter;
+
+rpcserver_thrift::rpcserver_thrift()
+{}
+
+rpcserver_thrift::~rpcserver_thrift()
+{}
+
+void
+rpcserver_thrift::registerConfigureCallback(const std::string &id, const 
configureCallback_t callback)
+{
+  {
+    ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(id));
+    if(iter != d_setcallbackmap.end()) {
+      std::stringstream s;
+      s << "rpcserver_thrift:: rpcserver_thrift ERROR registering set, already 
registered: "
+              << id << std::endl;
+      throw std::runtime_error(s.str().c_str());
+    }
+  }
+
+  if(DEBUG) {
+    std::cout << "rpcserver_thrift registering set: " << id << std::endl;
+  }
+  d_setcallbackmap.insert(ConfigureCallbackMap_t::value_type(id, callback));
+}
+
+void
+rpcserver_thrift::unregisterConfigureCallback(const std::string &id)
+{
+  ConfigureCallbackMap_t::iterator iter(d_setcallbackmap.find(id));
+  if(iter == d_setcallbackmap.end()) {
+    std::stringstream s;
+    s << "rpcserver_thrift:: rpcserver_thrift ERROR unregistering set, not 
registered: "
+            << id << std::endl;
+    throw std::runtime_error(s.str().c_str());
+  }
+
+  if(DEBUG)
+    std::cout << "rpcserver_thrift unregistering set: " << id << std::endl;
+
+  d_setcallbackmap.erase(iter);
+}
+
+void
+rpcserver_thrift::registerQueryCallback(const std::string &id,
+        const queryCallback_t callback)
+{
+  {
+    QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(id));
+    if(iter != d_getcallbackmap.end()) {
+      std::stringstream s;
+      s << "rpcserver_thrift:: rpcserver_thrift ERROR registering get, already 
registered: "
+              << id << std::endl;
+      throw std::runtime_error(s.str().c_str());
+    }
+  }
+
+  if(DEBUG) {
+    std::cout << "rpcserver_thrift registering get: " << id << std::endl;
+  }
+  d_getcallbackmap.insert(QueryCallbackMap_t::value_type(id, callback));
+}
+
+void
+rpcserver_thrift::unregisterQueryCallback(const std::string &id)
+{
+  QueryCallbackMap_t::iterator iter(d_getcallbackmap.find(id));
+  if(iter == d_getcallbackmap.end()) {
+    std::stringstream s;
+    s << "rpcserver_thrift:: rpcserver_thrift ERROR unregistering get,  
registered: "
+            << id << std::endl;
+    throw std::runtime_error(s.str().c_str());
+  }
+
+  if(DEBUG) {
+    std::cout << "rpcserver_thrift unregistering get: " << id << std::endl;
+  }
+
+  d_getcallbackmap.erase(iter);
+}
+
+void
+rpcserver_thrift::set(const GNURadio::KnobMap& knobs)
+{
+  std::for_each(knobs.begin(), knobs.end(),
+          set_f<GNURadio::KnobMap::value_type,ConfigureCallbackMap_t>
+                  (d_setcallbackmap, cur_priv));
+}
+
+GNURadio::KnobMap
+rpcserver_thrift::getRe(const GNURadio::KnobIDList& knobs)
+{
+  GNURadio::KnobMap outknobs;
+
+  if(knobs.size() == 0) {
+    std::for_each(d_getcallbackmap.begin(), d_getcallbackmap.end(),
+            get_all_f<QueryCallbackMap_t::value_type, QueryCallbackMap_t, 
GNURadio::KnobMap>
+                    (d_getcallbackmap, cur_priv, outknobs));
+  }
+  else {
+    QueryCallbackMap_t::iterator it;
+    for(it = d_getcallbackmap.begin(); it != d_getcallbackmap.end(); it++){
+      for(size_t j=0; j<knobs.size(); j++){
+        const boost::xpressive::sregex 
re(boost::xpressive::sregex::compile(knobs[j]));
+        if(boost::xpressive::regex_match(it->first, re)){
+          get_f<GNURadio::KnobIDList::value_type, QueryCallbackMap_t>
+                  (d_getcallbackmap, cur_priv, outknobs)(it->first);
+          break;
+        }
+      }
+    }
+  }
+  return outknobs;
+}
+
+GNURadio::KnobMap
+rpcserver_thrift::get(const GNURadio::KnobIDList& knobs)
+{
+  GNURadio::KnobMap outknobs;
+
+  if(knobs.size() == 0) {
+    std::for_each(d_getcallbackmap.begin(), d_getcallbackmap.end(),
+            get_all_f<QueryCallbackMap_t::value_type, QueryCallbackMap_t, 
GNURadio::KnobMap>
+                    (d_getcallbackmap, cur_priv, outknobs));
+  }
+  else {
+    std::for_each(knobs.begin(), knobs.end(),
+            get_f<GNURadio::KnobIDList::value_type, QueryCallbackMap_t>
+                    (d_getcallbackmap, cur_priv, outknobs));
+  }
+  return outknobs;
+}
+
+GNURadio::KnobPropMap
+rpcserver_thrift::properties(const GNURadio::KnobIDList& knobs)
+{
+  GNURadio::KnobPropMap outknobs;
+
+  if(knobs.size() == 0) {
+    std::for_each(d_getcallbackmap.begin(), d_getcallbackmap.end(),
+            properties_all_f<QueryCallbackMap_t::value_type,
+                    QueryCallbackMap_t, 
GNURadio::KnobPropMap>(d_getcallbackmap, cur_priv, outknobs));
+  }
+  else {
+    std::for_each(knobs.begin(), knobs.end(),
+            properties_f<GNURadio::KnobIDList::value_type,
+                    QueryCallbackMap_t, 
GNURadio::KnobPropMap>(d_getcallbackmap, cur_priv, outknobs));
+  }
+  return outknobs;
+}
+
+void
+rpcserver_thrift::shutdown() {
+  if (DEBUG) {
+    std::cout << "Shutting down..." << std::endl;
+  }
+}
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]