11#ifndef RPCSERVER_THRIFT_H
12#define RPCSERVER_THRIFT_H
14#include "thrift/ControlPort.h"
15#include "thrift/gnuradio_types.h"
26#define S__LINE__ S_(__LINE__)
45 void getKnobs(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
46 void getRe(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
47 void properties(GNURadio::KnobPropMap&,
const GNURadio::KnobIDList& knobs);
74 const std::string& port,
75 const std::string&
msg);
85 typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
86 ConfigureCallbackMap_t d_setcallbackmap;
88 typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
89 QueryCallbackMap_t d_getcallbackmap;
91 typedef std::map<std::string, handlerCallback_t> HandlerCallbackMap_t;
92 HandlerCallbackMap_t d_handlercallbackmap;
105 std::ostringstream
msg;
107 <<
" requires PRIVLVL <= " << _handlerCallback.
priv
108 <<
" to set, currently at: " <<
cur_priv;
114 template <
typename T,
typename TMap>
115 struct set_f :
public std::function<void(T)> {
116 set_f(TMap& _setcallbackmap,
const priv_lvl_t& _cur_priv)
117 : d_setcallbackmap(_setcallbackmap),
cur_priv(_cur_priv)
122 void operator()(
const T& p)
124 ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(p.first));
125 if (iter != d_setcallbackmap.end()) {
126 if (cur_priv <= iter->second.priv) {
127 (*iter->second.callback)
130 std::ostringstream
msg;
131 msg <<
"Key " << p.first
132 <<
" requires PRIVLVL <= " << iter->second.priv
133 <<
" to set, currently at: " <<
cur_priv;
137 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
141 TMap& d_setcallbackmap;
145 template <
typename T,
typename TMap>
146 struct get_f :
public std::function<void(T)> {
147 get_f(TMap& _getcallbackmap,
149 GNURadio::KnobMap& _outknobs)
150 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
154 void operator()(
const T& p)
156 QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
157 if (iter != d_getcallbackmap.end()) {
158 if (cur_priv <= iter->second.priv) {
162 std::ostringstream
msg;
163 msg <<
"Key " << iter->first
164 <<
" requires PRIVLVL: <= " << iter->second.priv
165 <<
" to get, currently at: " <<
cur_priv;
169 std::ostringstream smsgs;
170 smsgs <<
"Ctrlport Key called with unregistered key (" << p <<
")\n";
172 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
176 TMap& d_getcallbackmap;
178 GNURadio::KnobMap& outknobs;
181 template <
typename T,
typename TMap,
typename TKnobMap>
182 struct get_all_f :
public std::function<void(T)> {
183 get_all_f(TMap& _getcallbackmap,
const priv_lvl_t& _cur_priv, TKnobMap& _outknobs)
184 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
189 void operator()(
const T& p)
195 std::ostringstream
msg;
196 msg <<
"Key " << p.first <<
" requires PRIVLVL: <= " << p.second.priv
197 <<
" to get, currently at: " <<
cur_priv;
202 TMap& d_getcallbackmap;
207 template <
typename T,
typename TMap,
typename TKnobMap>
208 struct properties_all_f :
public std::function<void(T)> {
209 properties_all_f(QueryCallbackMap_t& _getcallbackmap,
211 GNURadio::KnobPropMap& _outknobs)
212 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
217 void operator()(
const T& p)
220 GNURadio::KnobProp prop;
222 prop.units = p.second.units;
223 prop.description = p.second.description;
226 prop.display =
static_cast<uint32_t
>(p.second.display);
227 outknobs[p.first] = prop;
229 std::ostringstream
msg;
230 msg <<
"Key " << p.first <<
" requires PRIVLVL: <= " << p.second.priv
231 <<
" to get, currently at: " <<
cur_priv;
236 TMap& d_getcallbackmap;
241 template <
class T,
typename TMap,
typename TKnobMap>
242 struct properties_f :
public std::function<void(T)> {
243 properties_f(TMap& _getcallbackmap,
246 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
251 void operator()(
const T& p)
253 typename TMap::const_iterator iter(d_getcallbackmap.find(p));
254 if (iter != d_getcallbackmap.end()) {
255 if (cur_priv <= iter->second.priv) {
256 GNURadio::KnobProp prop;
258 prop.units = iter->second.units;
259 prop.description = iter->second.description;
262 prop.display =
static_cast<uint32_t
>(iter->second.display);
265 std::ostringstream
msg;
266 msg <<
"Key " << iter->first
267 <<
" requires PRIVLVL: <= " << iter->second.priv
268 <<
" to get, currently at: " <<
cur_priv;
272 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
276 TMap& d_getcallbackmap;
Definition: rpccallbackregister_base.h:83
Tsptr callback
Definition: rpccallbackregister_base.h:105
static To_PMT instance
Definition: rpcpmtconverters_thrift.h:79
Definition: rpcserver_base.h:17
priv_lvl_t cur_priv
Definition: rpcserver_base.h:39
Definition: rpcserver_thrift.h:29
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:268
GR_RUNTIME_API const pmt::pmt_t msg()
boost::mutex mutex
Definition: thread.h:37
std::shared_ptr< logger > logger_ptr
Definition: logger.h:225
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:83
GNURadio::Knob from_pmt(const pmt::pmt_t &knob)
#define PMT_NIL
Definition: pmt.h:121
priv_lvl_t
Definition: rpccallbackregister_base.h:34
@ KNOBDOUBLE
Definition: rpccallbackregister_base.h:41
#define S__LINE__
Definition: rpcserver_thrift.h:26
std::string description
Definition: rpccallbackregister_base.h:76
priv_lvl_t priv
Definition: rpccallbackregister_base.h:75