GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rpcserver_ice.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef RPCSERVER_ICE_H
24 #define RPCSERVER_ICE_H
25 
28 #include <string>
29 #include <sstream>
30 #include <map>
31 #include <gnuradio.h>
32 #include <Ice/Exception.h>
33 #include <boost/format.hpp>
34 
35 class rpcserver_ice : public virtual rpcserver_base, public GNURadio::ControlPort
36 {
37 public:
38  rpcserver_ice();
39  virtual ~rpcserver_ice();
40 
41  void registerConfigureCallback(const std::string &id, const configureCallback_t callback);
42  void unregisterConfigureCallback(const std::string &id);
43 
44  void registerQueryCallback(const std::string &id, const queryCallback_t callback);
45  void unregisterQueryCallback(const std::string &id);
46 
47  virtual void set(const GNURadio::KnobMap&, const Ice::Current&);
48 
49  GNURadio::KnobMap get(const GNURadio::KnobIDList&, const Ice::Current&);
50 
51  GNURadio::KnobMap getRe(const GNURadio::KnobIDList&, const Ice::Current&);
52 
53  GNURadio::KnobPropMap properties(const GNURadio::KnobIDList&, const Ice::Current&);
54 
55  virtual void shutdown(const Ice::Current&);
56 
57 private:
58  typedef std::map<std::string, configureCallback_t> ConfigureCallbackMap_t;
59  ConfigureCallbackMap_t d_setcallbackmap;
60 
61  typedef std::map<std::string, queryCallback_t> QueryCallbackMap_t;
62  QueryCallbackMap_t d_getcallbackmap;
63 
64  template<typename T, typename TMap> struct set_f
65  : public std::unary_function<T,void>
66  {
67  set_f(const Ice::Current& _c, TMap& _setcallbackmap, const priv_lvl_t& _cur_priv) :
68  c(_c), d_setcallbackmap(_setcallbackmap), cur_priv(_cur_priv)
69  {;}
70 
71  void operator()(const T& p)
72  {
73  ConfigureCallbackMap_t::const_iterator iter(d_setcallbackmap.find(p.first));
74  if(iter != d_setcallbackmap.end()) {
75  if(cur_priv <= iter->second.priv) {
76  (*iter->second.callback).post(pmt::PMT_NIL, rpcpmtconverter::to_pmt(p.second,c));
77  }
78  else {
79  std::cout << "Key " << p.first << " requires PRIVLVL <= "
80  << iter->second.priv << " to set, currently at: "
81  << cur_priv << std::endl;
82  }
83  }
84  else {
85  throw IceUtil::NullHandleException(__FILE__, __LINE__);
86  }
87  }
88 
89  const Ice::Current& c;
90  TMap& d_setcallbackmap;
91  const priv_lvl_t& cur_priv;
92  };
93 
94  template<typename T, typename TMap>
95  struct get_f : public std::unary_function<T,void>
96  {
97  get_f(const Ice::Current& _c, TMap& _getcallbackmap,
98  const priv_lvl_t& _cur_priv, GNURadio::KnobMap& _outknobs) :
99  c(_c), d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), outknobs(_outknobs)
100  {}
101 
102  void operator()(const T& p)
103  {
104  QueryCallbackMap_t::const_iterator iter(d_getcallbackmap.find(p));
105  if(iter != d_getcallbackmap.end()) {
106  if(cur_priv <= iter->second.priv) {
107  outknobs[p] = rpcpmtconverter::from_pmt((*iter->second.callback).retrieve(), c);
108  }
109  else {
110  std::cout << "Key " << iter->first << " requires PRIVLVL: <= "
111  << iter->second.priv << " to get, currently at: "
112  << cur_priv << std::endl;
113  }
114  }
115  else {
116  std::stringstream ss;
117  ss << "Ctrlport Key called with unregistered key (" << p << ")\n";
118  std::cout << ss.str();
119  throw IceUtil::IllegalArgumentException(__FILE__,__LINE__,ss.str().c_str());
120  }
121  }
122 
123  const Ice::Current& c;
124  TMap& d_getcallbackmap;
125  const priv_lvl_t& cur_priv;
126  GNURadio::KnobMap& outknobs;
127  };
128 
129  template<typename T, typename TMap, typename TKnobMap>
130  struct get_all_f : public std::unary_function<T,void>
131  {
132  get_all_f(const Ice::Current& _c, TMap& _getcallbackmap,
133  const priv_lvl_t& _cur_priv, TKnobMap& _outknobs) :
134  c(_c), d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), outknobs(_outknobs)
135  {;}
136 
137  void operator()(const T& p)
138  {
139  if(cur_priv <= p.second.priv) {
140  outknobs[p.first] = rpcpmtconverter::from_pmt(p.second.callback->retrieve(), c);
141  }
142  else {
143  std::cout << "Key " << p.first << " requires PRIVLVL <= "
144  << p.second.priv << " to get, currently at: "
145  << cur_priv << std::endl;
146  }
147  }
148 
149  const Ice::Current& c;
150  TMap& d_getcallbackmap;
151  const priv_lvl_t& cur_priv;
152  TKnobMap& outknobs;
153  };
154 
155  template<typename T, typename TMap, typename TKnobMap>
156  struct properties_all_f : public std::unary_function<T,void>
157  {
158  properties_all_f(const Ice::Current& _c, QueryCallbackMap_t& _getcallbackmap,
159  const priv_lvl_t& _cur_priv, GNURadio::KnobPropMap& _outknobs) :
160  c(_c), d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), outknobs(_outknobs)
161  {;}
162 
163  void operator()(const T& p)
164  {
165  if(cur_priv <= p.second.priv) {
166  GNURadio::KnobProp prop;//(new GNURadio::KnobProp());
167  prop.type = GNURadio::KNOBDOUBLE;
168  prop.units = p.second.units;
169  prop.description = p.second.description;
170  prop.min = rpcpmtconverter::from_pmt(p.second.min, c);
171  prop.max = rpcpmtconverter::from_pmt(p.second.max, c);
172  prop.display = static_cast<uint32_t>(p.second.display);
173  outknobs[p.first] = prop;
174  }
175  else {
176  std::cout << "Key " << p.first << " requires PRIVLVL <= "
177  << p.second.priv << " to get, currently at: "
178  << cur_priv << std::endl;
179  }
180  }
181 
182  const Ice::Current& c;
183  TMap& d_getcallbackmap;
184  const priv_lvl_t& cur_priv;
185  TKnobMap& outknobs;
186  };
187 
188  template<class T, typename TMap, typename TKnobMap>
189  struct properties_f : public std::unary_function<T,void>
190  {
191  properties_f(const Ice::Current& _c, TMap& _getcallbackmap,
192  const priv_lvl_t& _cur_priv, TKnobMap& _outknobs) :
193  c(_c), d_getcallbackmap(_getcallbackmap), cur_priv(_cur_priv), outknobs(_outknobs)
194  {;}
195 
196  void operator()(const T& p)
197  {
198  typename TMap::const_iterator iter(d_getcallbackmap.find(p));
199  if(iter != d_getcallbackmap.end()) {
200  if(cur_priv <= iter->second.priv) {
201  GNURadio::KnobProp prop;
202  prop.type = GNURadio::KNOBDOUBLE;
203  prop.units = iter->second.units;
204  prop.description = iter->second.description;
205  prop.min = rpcpmtconverter::from_pmt(iter->second.min, c);
206  prop.max = rpcpmtconverter::from_pmt(iter->second.max, c);
207  prop.display = static_cast<uint32_t>(iter->second.display);
208  //outknobs[iter->first] = prop;
209  outknobs[p] = prop;
210  }
211  else {
212  std::cout << "Key " << iter->first << " requires PRIVLVL: <= " <<
213  iter->second.priv << " to get, currently at: " << cur_priv << std::endl;
214  }
215  }
216  else {
217  throw IceUtil::NullHandleException(__FILE__, __LINE__);
218  }
219  }
220 
221  const Ice::Current& c;
222  TMap& d_getcallbackmap;
223  const priv_lvl_t& cur_priv;
224  TKnobMap& outknobs;
225  };
226 };
227 
228 #endif /* RPCSERVER_ICE_H */
Definition: rpccallbackregister_base.h:80
virtual void set(const GNURadio::KnobMap &, const Ice::Current &)
void unregisterQueryCallback(const std::string &id)
virtual void shutdown(const Ice::Current &)
void registerQueryCallback(const std::string &id, const queryCallback_t callback)
priv_lvl_t
Definition: rpccallbackregister_base.h:46
void registerConfigureCallback(const std::string &id, const configureCallback_t callback)
Definition: rpccallbackregister_base.h:54
callback_t< gr::messages::msg_accepter, gr::messages::msg_accepter_sptr > configureCallback_t
Definition: rpccallbackregister_base.h:100
GNURadio::KnobMap getRe(const GNURadio::KnobIDList &, const Ice::Current &)
unsigned int uint32_t
Definition: stdint.h:80
void unregisterConfigureCallback(const std::string &id)
Definition: rpcserver_ice.h:35
#define PMT_NIL
Definition: pmt.h:252
Definition: rpcserver_base.h:28
GNURadio::KnobPtr from_pmt(const pmt::pmt_t &knob, const Ice::Current &c)
pmt::pmt_t to_pmt(const GNURadio::KnobPtr &knob, const Ice::Current &c)
GNURadio::KnobPropMap properties(const GNURadio::KnobIDList &, const Ice::Current &)
priv_lvl_t cur_priv
Definition: rpcserver_base.h:42
virtual ~rpcserver_ice()