11#ifndef RPCSERVER_THRIFT_H
12#define RPCSERVER_THRIFT_H
14#include "thrift/ControlPort.h"
15#include "thrift/gnuradio_types.h"
19#include <boost/format.hpp>
20#include <boost/thread/mutex.hpp>
27#define S__LINE__ S_(__LINE__)
46 void getKnobs(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
47 void getRe(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
48 void properties(GNURadio::KnobPropMap&,
const GNURadio::KnobIDList& knobs);
75 const std::string& port,
76 const std::string&
msg);
86 typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
87 ConfigureCallbackMap_t d_setcallbackmap;
89 typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
90 QueryCallbackMap_t d_getcallbackmap;
92 typedef std::map<std::string, handlerCallback_t> HandlerCallbackMap_t;
93 HandlerCallbackMap_t d_handlercallbackmap;
106 std::ostringstream
msg;
108 <<
" requires PRIVLVL <= " << _handlerCallback.
priv
109 <<
" to set, currently at: " <<
cur_priv;
115 template <
typename T,
typename TMap>
116 struct set_f :
public std::unary_function<T, void> {
117 set_f(TMap& _setcallbackmap,
const priv_lvl_t& _cur_priv)
118 : d_setcallbackmap(_setcallbackmap),
cur_priv(_cur_priv)
123 void operator()(
const T& p)
125 ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(p.first));
126 if (iter != d_setcallbackmap.end()) {
127 if (cur_priv <= iter->second.priv) {
128 (*iter->second.callback)
131 std::ostringstream
msg;
132 msg <<
"Key " << p.first
133 <<
" requires PRIVLVL <= " << iter->second.priv
134 <<
" to set, currently at: " <<
cur_priv;
138 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
142 TMap& d_setcallbackmap;
146 template <
typename T,
typename TMap>
147 struct get_f :
public std::unary_function<T, void> {
148 get_f(TMap& _getcallbackmap,
150 GNURadio::KnobMap& _outknobs)
151 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
155 void operator()(
const T& p)
157 QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
158 if (iter != d_getcallbackmap.end()) {
159 if (cur_priv <= iter->second.priv) {
163 std::ostringstream
msg;
164 msg <<
"Key " << iter->first
165 <<
" requires PRIVLVL: <= " << iter->second.priv
166 <<
" to get, currently at: " <<
cur_priv;
170 std::ostringstream smsgs;
171 smsgs <<
"Ctrlport Key called with unregistered key (" << p <<
")\n";
173 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
177 TMap& d_getcallbackmap;
179 GNURadio::KnobMap& outknobs;
182 template <
typename T,
typename TMap,
typename TKnobMap>
183 struct get_all_f :
public std::unary_function<T, void> {
184 get_all_f(TMap& _getcallbackmap,
const priv_lvl_t& _cur_priv, TKnobMap& _outknobs)
185 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
190 void operator()(
const T& p)
196 std::ostringstream
msg;
197 msg <<
"Key " << p.first <<
" requires PRIVLVL: <= " << p.second.priv
198 <<
" to get, currently at: " <<
cur_priv;
203 TMap& d_getcallbackmap;
208 template <
typename T,
typename TMap,
typename TKnobMap>
209 struct properties_all_f :
public std::unary_function<T, void> {
210 properties_all_f(QueryCallbackMap_t& _getcallbackmap,
212 GNURadio::KnobPropMap& _outknobs)
213 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
218 void operator()(
const T& p)
221 GNURadio::KnobProp prop;
223 prop.units = p.second.units;
224 prop.description = p.second.description;
227 prop.display =
static_cast<uint32_t
>(p.second.display);
228 outknobs[p.first] = prop;
230 std::ostringstream
msg;
231 msg <<
"Key " << p.first <<
" requires PRIVLVL: <= " << p.second.priv
232 <<
" to get, currently at: " <<
cur_priv;
237 TMap& d_getcallbackmap;
242 template <
class T,
typename TMap,
typename TKnobMap>
243 struct properties_f :
public std::unary_function<T, void> {
244 properties_f(TMap& _getcallbackmap,
247 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
252 void operator()(
const T& p)
254 typename TMap::const_iterator iter(d_getcallbackmap.find(p));
255 if (iter != d_getcallbackmap.end()) {
256 if (cur_priv <= iter->second.priv) {
257 GNURadio::KnobProp prop;
259 prop.units = iter->second.units;
260 prop.description = iter->second.description;
263 prop.display =
static_cast<uint32_t
>(iter->second.display);
266 std::ostringstream
msg;
267 msg <<
"Key " << iter->first
268 <<
" requires PRIVLVL: <= " << iter->second.priv
269 <<
" to get, currently at: " <<
cur_priv;
273 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
277 TMap& d_getcallbackmap;
Definition: rpccallbackregister_base.h:83
Tsptr callback
Definition: rpccallbackregister_base.h:105
static To_PMT instance
Definition: rpcpmtconverters_thrift.h:77
Definition: rpcserver_base.h:17
priv_lvl_t cur_priv
Definition: rpcserver_base.h:39
Definition: rpcserver_thrift.h:30
void unregisterQueryCallback(const std::string &id)
void registerConfigureCallback(const std::string &id, const configureCallback_t callback)
virtual ~rpcserver_thrift()
void getRe(GNURadio::KnobMap &, const GNURadio::KnobIDList &)
void setKnobs(const GNURadio::KnobMap &)
void properties(GNURadio::KnobPropMap &, const GNURadio::KnobIDList &knobs)
void getKnobs(GNURadio::KnobMap &, const GNURadio::KnobIDList &)
void registerQueryCallback(const std::string &id, const queryCallback_t callback)
void postMessage(const std::string &alias, const std::string &port, const std::string &msg)
Call this to post a message to the port for the block identified by alias.
void unregisterHandlerCallback(const std::string &id)
void registerHandlerCallback(const std::string &id, const handlerCallback_t callback)
void unregisterConfigureCallback(const std::string &id)
#define GR_LOG_ERROR(log, msg)
Definition: logger.h:250
GR_RUNTIME_API const pmt::pmt_t msg()
boost::mutex mutex
Definition: thread.h:37
std::shared_ptr< logger > logger_ptr
Definition: logger.h:207
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84
GNURadio::Knob from_pmt(const pmt::pmt_t &knob)
#define PMT_NIL
Definition: pmt.h:122
priv_lvl_t
Definition: rpccallbackregister_base.h:34
@ KNOBDOUBLE
Definition: rpccallbackregister_base.h:41
#define S__LINE__
Definition: rpcserver_thrift.h:27
std::string description
Definition: rpccallbackregister_base.h:76
priv_lvl_t priv
Definition: rpccallbackregister_base.h:75