23 #ifndef RPCSERVER_THRIFT_H 24 #define RPCSERVER_THRIFT_H 26 #include "thrift/ControlPort.h" 27 #include "thrift/gnuradio_types.h" 30 #include <boost/format.hpp> 31 #include <boost/thread/mutex.hpp> 39 #define S__LINE__ S_(__LINE__) 57 void setKnobs(
const GNURadio::KnobMap&);
58 void getKnobs(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
59 void getRe(GNURadio::KnobMap&,
const GNURadio::KnobIDList&);
60 void properties(GNURadio::KnobPropMap&,
const GNURadio::KnobIDList& knobs);
87 const std::string& port,
88 const std::string& msg);
95 typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
96 ConfigureCallbackMap_t d_setcallbackmap;
98 typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
99 QueryCallbackMap_t d_getcallbackmap;
101 typedef std::map<std::string, handlerCallback_t> HandlerCallbackMap_t;
102 HandlerCallbackMap_t d_handlercallbackmap;
113 _handlerCallback.
callback->post(port, msg);
115 std::cerr <<
"Message " << _handlerCallback.
description 116 <<
" requires PRIVLVL <= " << _handlerCallback.
priv 117 <<
" to set, currently at: " <<
cur_priv << std::endl;
122 template <
typename T,
typename TMap>
123 struct set_f :
public std::unary_function<T, void> {
124 set_f(TMap& _setcallbackmap,
const priv_lvl_t& _cur_priv)
125 : d_setcallbackmap(_setcallbackmap),
cur_priv(_cur_priv)
130 void operator()(
const T& p)
132 ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(p.first));
133 if (iter != d_setcallbackmap.end()) {
134 if (cur_priv <= iter->second.priv) {
135 (*iter->second.callback)
138 std::cerr <<
"Key " << p.first
139 <<
" requires PRIVLVL <= " << iter->second.priv
140 <<
" to set, currently at: " <<
cur_priv << std::endl;
143 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
147 TMap& d_setcallbackmap;
151 template <
typename T,
typename TMap>
152 struct get_f :
public std::unary_function<T, void> {
153 get_f(TMap& _getcallbackmap,
155 GNURadio::KnobMap& _outknobs)
156 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
160 void operator()(
const T& p)
162 QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
163 if (iter != d_getcallbackmap.end()) {
164 if (cur_priv <= iter->second.priv) {
168 std::cerr <<
"Key " << iter->first
169 <<
" requires PRIVLVL: <= " << iter->second.priv
170 <<
" to get, currently at: " <<
cur_priv << std::endl;
173 std::stringstream ss;
174 ss <<
"Ctrlport Key called with unregistered key (" << p <<
")\n";
175 std::cerr << ss.str();
176 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
180 TMap& d_getcallbackmap;
182 GNURadio::KnobMap& outknobs;
185 template <
typename T,
typename TMap,
typename TKnobMap>
186 struct get_all_f :
public std::unary_function<T, void> {
187 get_all_f(TMap& _getcallbackmap,
const priv_lvl_t& _cur_priv, TKnobMap& _outknobs)
188 : d_getcallbackmap(_getcallbackmap),
cur_priv(_cur_priv), outknobs(_outknobs)
193 void operator()(
const T& p)
199 std::cerr <<
"Key " << p.first <<
" requires PRIVLVL <= " << p.second.priv
200 <<
" to get, currently at: " <<
cur_priv << std::endl;
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::cerr <<
"Key " << p.first <<
" requires PRIVLVL <= " << p.second.priv
232 <<
" to get, currently at: " <<
cur_priv << std::endl;
236 TMap& d_getcallbackmap;
241 template <
class T,
typename TMap,
typename TKnobMap>
242 struct properties_f :
public std::unary_function<T, void> {
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::cerr <<
"Key " << iter->first
266 <<
" requires PRIVLVL: <= " << iter->second.priv
267 <<
" to get, currently at: " <<
cur_priv << std::endl;
270 throw apache::thrift::TApplicationException(__FILE__
" " S__LINE__);
274 TMap& d_getcallbackmap;
Definition: rpccallbackregister_base.h:94
void registerHandlerCallback(const std::string &id, const handlerCallback_t callback)
void unregisterHandlerCallback(const std::string &id)
boost::shared_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:96
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:53
callback_t< gr::messages::msg_accepter, gr::messages::msg_accepter_sptr > configureCallback_t
Definition: rpccallbackregister_base.h:121
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:134
Definition: rpcserver_base.h:28
#define S__LINE__
Definition: rpcserver_thrift.h:39
static To_PMT instance
Definition: rpcpmtconverters_thrift.h:89
callback_t< gr::messages::msg_producer, gr::messages::msg_producer_sptr > queryCallback_t
Definition: rpccallbackregister_base.h:123
priv_lvl_t priv
Definition: rpccallbackregister_base.h:87
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:88
void setKnobs(const GNURadio::KnobMap &)
GNURadio::Knob from_pmt(const pmt::pmt_t &knob)
priv_lvl_t cur_priv
Definition: rpcserver_base.h:51
virtual ~rpcserver_thrift()
Tsptr callback
Definition: rpccallbackregister_base.h:117