23 #ifndef RPCSERVER_THRIFT_H 24 #define RPCSERVER_THRIFT_H 32 #include "thrift/ControlPort.h" 33 #include "thrift/gnuradio_types.h" 34 #include <boost/format.hpp> 35 #include <boost/thread/mutex.hpp> 39 #define S__LINE__ S_(__LINE__) 43 public GNURadio::ControlPortIf
61 void setKnobs(
const GNURadio::KnobMap&);
63 const GNURadio::KnobIDList&);
64 void getRe(GNURadio::KnobMap&,
65 const GNURadio::KnobIDList&);
67 const GNURadio::KnobIDList& knobs);
94 const std::string& port,
95 const std::string& msg);
102 typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
103 ConfigureCallbackMap_t d_setcallbackmap;
105 typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
106 QueryCallbackMap_t d_getcallbackmap;
108 typedef std::map<std::string, handlerCallback_t> HandlerCallbackMap_t;
109 HandlerCallbackMap_t d_handlercallbackmap;
120 _handlerCallback.
callback->post(port, msg);
123 std::cerr <<
"Message " << _handlerCallback.
description <<
" requires PRIVLVL <= " 124 << _handlerCallback.
priv <<
" to set, currently at: " 130 template<
typename T,
typename TMap>
struct set_f
131 :
public std::unary_function<T,void>
133 set_f(TMap &_setcallbackmap,
const priv_lvl_t &_cur_priv)
134 : d_setcallbackmap(_setcallbackmap),
cur_priv(_cur_priv)
139 void operator()(
const T& p)
141 ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(p.first));
142 if(iter != d_setcallbackmap.end()) {
143 if(cur_priv <= iter->second.priv) {
147 std::cerr <<
"Key " << p.first <<
" requires PRIVLVL <= " 148 << iter->second.priv <<
" to set, currently at: " 153 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
157 TMap& d_setcallbackmap;
161 template<
typename T,
typename TMap>
162 struct get_f :
public std::unary_function<T,void>
164 get_f(TMap &_getcallbackmap,
const priv_lvl_t &_cur_priv, GNURadio::KnobMap &_outknobs) :
165 d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
168 void operator()(
const T& p)
170 QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
171 if(iter != d_getcallbackmap.end()) {
172 if(cur_priv <= iter->second.priv) {
176 std::cerr <<
"Key " << iter->first <<
" requires PRIVLVL: <= " 177 << iter->second.priv <<
" to get, currently at: " 182 std::stringstream ss;
183 ss <<
"Ctrlport Key called with unregistered key (" << p <<
")\n";
184 std::cerr << ss.str();
185 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
189 TMap& d_getcallbackmap;
191 GNURadio::KnobMap& outknobs;
194 template<
typename T,
typename TMap,
typename TKnobMap>
195 struct get_all_f :
public std::unary_function<T,void>
197 get_all_f(TMap &_getcallbackmap,
const priv_lvl_t &_cur_priv, TKnobMap &_outknobs) :
198 d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
201 void operator()(
const T& p)
207 std::cerr <<
"Key " << p.first <<
" requires PRIVLVL <= " 208 << p.second.priv <<
" to get, currently at: " 213 TMap& d_getcallbackmap;
218 template<
typename T,
typename TMap,
typename TKnobMap>
219 struct properties_all_f :
public std::unary_function<T,void>
221 properties_all_f(QueryCallbackMap_t &_getcallbackmap,
223 GNURadio::KnobPropMap &_outknobs)
224 : d_getcallbackmap(_getcallbackmap),
229 void operator()(
const T& p)
232 GNURadio::KnobProp prop;
234 prop.units = p.second.units;
235 prop.description = p.second.description;
238 prop.display =
static_cast<uint32_t
>(p.second.display);
239 outknobs[p.first] = prop;
242 std::cerr <<
"Key " << p.first <<
" requires PRIVLVL <= " 243 << p.second.priv <<
" to get, currently at: " 248 TMap& d_getcallbackmap;
253 template<
class T,
typename TMap,
typename TKnobMap>
254 struct properties_f :
public std::unary_function<T,void>
256 properties_f(TMap &_getcallbackmap,
const priv_lvl_t &_cur_priv, TKnobMap &_outknobs) :
257 d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
260 void operator()(
const T& p)
262 typename TMap::const_iterator iter(d_getcallbackmap.find(p));
263 if(iter != d_getcallbackmap.end()) {
264 if(cur_priv <= iter->second.priv) {
265 GNURadio::KnobProp prop;
267 prop.units = iter->second.units;
268 prop.description = iter->second.description;
271 prop.display =
static_cast<uint32_t
>(iter->second.display);
275 std::cerr <<
"Key " << iter->first <<
" requires PRIVLVL: <= " 276 << iter->second.priv <<
" to get, currently at: " <<
cur_priv << std::endl;
280 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
284 TMap& d_getcallbackmap;
Definition: rpccallbackregister_base.h:80
void registerHandlerCallback(const std::string &id, const handlerCallback_t callback)
void unregisterHandlerCallback(const std::string &id)
void registerQueryCallback(const std::string &id, const queryCallback_t callback)
void properties(GNURadio::KnobPropMap &, const GNURadio::KnobIDList &knobs)
priv_lvl_t
Definition: rpccallbackregister_base.h:46
void registerConfigureCallback(const std::string &id, const configureCallback_t callback)
void getKnobs(GNURadio::KnobMap &, const GNURadio::KnobIDList &)
Definition: rpccallbackregister_base.h:54
callback_t< gr::messages::msg_accepter, gr::messages::msg_accepter_sptr > configureCallback_t
Definition: rpccallbackregister_base.h:100
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 getRe(GNURadio::KnobMap &, const GNURadio::KnobIDList &)
void unregisterConfigureCallback(const std::string &id)
#define PMT_NIL
Definition: pmt.h:103
Definition: rpcserver_base.h:28
#define S__LINE__
Definition: rpcserver_thrift.h:39
static To_PMT instance
Definition: rpcpmtconverters_thrift.h:59
callback_t< gr::messages::msg_producer, gr::messages::msg_producer_sptr > queryCallback_t
Definition: rpccallbackregister_base.h:101
priv_lvl_t priv
Definition: rpccallbackregister_base.h:73
void unregisterQueryCallback(const std::string &id)
boost::mutex mutex
Definition: thread.h:48
Definition: rpcserver_thrift.h:41
std::string description
Definition: rpccallbackregister_base.h:74
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
void setKnobs(const GNURadio::KnobMap &)
GNURadio::Knob from_pmt(const pmt::pmt_t &knob)
priv_lvl_t cur_priv
Definition: rpcserver_base.h:47
virtual ~rpcserver_thrift()
Tsptr callback
Definition: rpccallbackregister_base.h:97