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>
28 #define S__LINE__ S_(__LINE__)
47 void getKnobs(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
48 void getRe(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
49 void properties(GNURadio::KnobPropMap&,
const GNURadio::KnobIDList& knobs);
76 const std::string& port,
77 const std::string& msg);
87 typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
88 ConfigureCallbackMap_t d_setcallbackmap;
90 typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
91 QueryCallbackMap_t d_getcallbackmap;
93 typedef std::map<std::string, handlerCallback_t> HandlerCallbackMap_t;
94 HandlerCallbackMap_t d_handlercallbackmap;
105 _handlerCallback.
callback->post(port, msg);
107 std::ostringstream msg;
109 <<
" requires PRIVLVL <= " << _handlerCallback.
priv
110 <<
" to set, currently at: " <<
cur_priv;
116 template <
typename T,
typename TMap>
117 struct set_f :
public std::unary_function<T, void> {
118 set_f(TMap& _setcallbackmap,
const priv_lvl_t& _cur_priv)
119 : d_setcallbackmap(_setcallbackmap),
cur_priv(_cur_priv)
124 void operator()(
const T& p)
126 ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(p.first));
127 if (iter != d_setcallbackmap.end()) {
128 if (cur_priv <= iter->second.priv) {
129 (*iter->second.callback)
132 std::ostringstream msg;
133 msg <<
"Key " << p.first
134 <<
" requires PRIVLVL <= " << iter->second.priv
135 <<
" to set, currently at: " <<
cur_priv;
139 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
143 TMap& d_setcallbackmap;
147 template <
typename T,
typename TMap>
148 struct get_f :
public std::unary_function<T, void> {
149 get_f(TMap& _getcallbackmap,
151 GNURadio::KnobMap& _outknobs)
152 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
156 void operator()(
const T& p)
158 QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
159 if (iter != d_getcallbackmap.end()) {
160 if (cur_priv <= iter->second.priv) {
164 std::ostringstream msg;
165 msg <<
"Key " << iter->first
166 <<
" requires PRIVLVL: <= " << iter->second.priv
167 <<
" to get, currently at: " <<
cur_priv;
171 std::ostringstream smsgs;
172 smsgs <<
"Ctrlport Key called with unregistered key (" << p <<
")\n";
174 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
178 TMap& d_getcallbackmap;
180 GNURadio::KnobMap& outknobs;
183 template <
typename T,
typename TMap,
typename TKnobMap>
184 struct get_all_f :
public std::unary_function<T, void> {
185 get_all_f(TMap& _getcallbackmap,
const priv_lvl_t& _cur_priv, TKnobMap& _outknobs)
186 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
191 void operator()(
const T& p)
197 std::ostringstream msg;
198 msg <<
"Key " << p.first <<
" requires PRIVLVL: <= " << p.second.priv
199 <<
" to get, currently at: " <<
cur_priv;
204 TMap& d_getcallbackmap;
209 template <
typename T,
typename TMap,
typename TKnobMap>
210 struct properties_all_f :
public std::unary_function<T, void> {
211 properties_all_f(QueryCallbackMap_t& _getcallbackmap,
213 GNURadio::KnobPropMap& _outknobs)
214 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
219 void operator()(
const T& p)
222 GNURadio::KnobProp prop;
224 prop.units = p.second.units;
225 prop.description = p.second.description;
228 prop.display =
static_cast<uint32_t
>(p.second.display);
229 outknobs[p.first] = prop;
231 std::ostringstream msg;
232 msg <<
"Key " << p.first <<
" requires PRIVLVL: <= " << p.second.priv
233 <<
" to get, currently at: " <<
cur_priv;
238 TMap& d_getcallbackmap;
243 template <
class T,
typename TMap,
typename TKnobMap>
244 struct properties_f :
public std::unary_function<T, void> {
245 properties_f(TMap& _getcallbackmap,
248 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
253 void operator()(
const T& p)
255 typename TMap::const_iterator iter(d_getcallbackmap.find(p));
256 if (iter != d_getcallbackmap.end()) {
257 if (cur_priv <= iter->second.priv) {
258 GNURadio::KnobProp prop;
260 prop.units = iter->second.units;
261 prop.description = iter->second.description;
264 prop.display =
static_cast<uint32_t
>(iter->second.display);
267 std::ostringstream msg;
268 msg <<
"Key " << iter->first
269 <<
" requires PRIVLVL: <= " << iter->second.priv
270 <<
" to get, currently at: " <<
cur_priv;
274 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
278 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:31
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(logger, msg)
Definition: logger.h:251
boost::mutex mutex
Definition: thread.h:37
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition: logger.h:60
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:28
std::string description
Definition: rpccallbackregister_base.h:76
priv_lvl_t priv
Definition: rpccallbackregister_base.h:75