GNU Radio 3.7.3 C++ API
rpcregisterhelpers.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 RPCREGISTERHELPERS_H
24 #define RPCREGISTERHELPERS_H
25 
26 #include <stdio.h>
27 #include <sstream>
28 #include <iostream>
30 #include <gnuradio/rpcmanager.h>
34 
35 // Base classes
36 template<typename T, typename Tto> class rpcextractor_base
37  : public virtual gr::messages::msg_accepter
38 {
39 public:
40  rpcextractor_base(T* source, void (T::*func)(Tto)) :
41  _source(source), _func(func) {;}
43 
44  void post(pmt::pmt_t which_port, pmt::pmt_t msg) {
45  throw std::runtime_error("rpcextractor_base: no post defined for this data type.\n");
46  }
47 
48 protected:
49  T* _source;
50  void (T::*_func)(Tto);
51 };
52 
53 template<typename T, typename Tto>
54 class rpcbasic_extractor : public virtual rpcextractor_base<T,Tto>
55 {
56 public:
57  rpcbasic_extractor(T* source, void (T::*func)(Tto)) :
58  rpcextractor_base<T,Tto>(source, func)
59  {;}
60 };
61 
62 template<typename T, typename Tfrom>
64 {
65 public:
66  rpcinserter_base(T* source, Tfrom (T::*func)()) : _source(source), _func(func) {;}
68 
69  pmt::pmt_t retrieve() { assert(0); return pmt::pmt_t(); }
70 
71 protected:
72  T* _source;
73  Tfrom (T::*_func)();
74 };
75 
76 template<typename T, typename Tfrom>
78  public virtual rpcinserter_base<T,Tfrom>
79 {
80 public:
81  rpcbasic_inserter(T* source, Tfrom (T::*func)()const)
82  : rpcinserter_base<T,Tfrom>(source, func)
83  {;}
84 
85  rpcbasic_inserter(T* source, Tfrom (T::*func)())
86  : rpcinserter_base<T,Tfrom>(source, func)
87  {;}
88 
90  {
93  }
94 };
95 
96 // Specialized Extractor Templates
97 template<typename T>
98 class rpcbasic_extractor<T,char> : public virtual rpcextractor_base<T,char>
99 {
100 public:
101  rpcbasic_extractor(T* source, void (T::*func)(char))
102  : rpcextractor_base<T,char>(source, func)
103  {;}
104 
105  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
106  {
108  (static_cast<char>(pmt::to_long(msg)));
109  }
110 };
111 
112 template<typename T>
113 class rpcbasic_extractor<T,short> : public virtual rpcextractor_base<T,short>
114 {
115 public:
116  rpcbasic_extractor(T* source, void (T::*func)(short))
117  : rpcextractor_base<T,short>(source, func)
118  {;}
119 
120  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
121  {
123  (static_cast<short>(pmt::to_long(msg)));
124  }
125 };
126 
127 template<typename T>
128 class rpcbasic_extractor<T,double> : public virtual rpcextractor_base<T,double>
129 {
130 public:
131  rpcbasic_extractor(T* source, void (T::*func)(double))
132  : rpcextractor_base<T,double>(source, func)
133  {;}
134 
135  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
136  {
138  (pmt::to_double(msg));
139  }
140 };
141 
142 template<typename T>
143 class rpcbasic_extractor<T,float> : public virtual rpcextractor_base<T,float>
144 {
145 public:
146  rpcbasic_extractor(T* source, void (T::*func)(float))
147  : rpcextractor_base<T,float>(source, func)
148  {;}
149 
150  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
151  {
153  (pmt::to_double(msg));
154  }
155 };
156 
157 template<typename T>
158 class rpcbasic_extractor<T,long> : public virtual rpcextractor_base<T,long>
159 {
160 public:
161  rpcbasic_extractor(T* source, void (T::*func)(long))
162  : rpcextractor_base<T,long>(source, func)
163  {;}
164 
165  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
166  {
168  (pmt::to_long(msg));
169  }
170 };
171 
172 template<typename T>
173 class rpcbasic_extractor<T,int> : public virtual rpcextractor_base<T,int>
174 {
175 public:
176  rpcbasic_extractor(T* source, void (T::*func)(int))
177  : rpcextractor_base<T,int>(source, func)
178  {;}
179 
180  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
181  {
183  (pmt::to_long(msg));
184  }
185 };
186 
187 template<typename T>
188 class rpcbasic_extractor<T,bool> : public virtual rpcextractor_base<T,bool>
189 {
190 public:
191  rpcbasic_extractor(T* source, void (T::*func)(bool))
192  : rpcextractor_base<T,bool>(source, func)
193  {;}
194 
195  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
196  {
198  (pmt::to_bool(msg));
199  }
200 };
201 
202 template<typename T>
203 class rpcbasic_extractor<T,std::complex<float> >
204  : public virtual rpcextractor_base<T,std::complex<float> >
205 {
206 public:
207  rpcbasic_extractor(T* source, void (T::*func)(std::complex<float>))
208  : rpcextractor_base<T,std::complex<float> >(source, func)
209  {;}
210 
211  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
212  {
213  std::complex<float> k = static_cast<std::complex<float> >(pmt::to_complex(msg));
216  }
217 };
218 
219 template<typename T>
220 class rpcbasic_extractor<T,std::complex<double> >
221  : public virtual rpcextractor_base<T,std::complex<double> >
222 {
223 public:
224  rpcbasic_extractor(T* source, void (T::*func)(std::complex<double>))
225  : rpcextractor_base<T,std::complex<double> >(source, func)
226  {;}
227 
228  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
229  {
232  }
233 };
234 
235 template<typename T>
236 class rpcbasic_extractor<T,std::string>
237  : public virtual rpcextractor_base<T,std::string>
238 {
239 public:
240  rpcbasic_extractor(T* source, void (T::*func)(std::string))
241  : rpcextractor_base<T,std::string>(source, func)
242  {;}
243 
244  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
245  {
248  }
249 };
250 
251 template<typename T>
252 class rpcbasic_inserter<T,uint64_t> : public virtual rpcinserter_base<T,uint64_t>
253 {
254 public:
255  rpcbasic_inserter(T* source, uint64_t (T::*func)() const)
256  : rpcinserter_base<T,uint64_t>(source, func)
257  {;}
258 
259  rpcbasic_inserter(T* source, uint64_t (T::*func)())
260  : rpcinserter_base<T,uint64_t>(source, func)
261  {;}
262 
264  {
267  }
268 };
269 
270 template<typename T>
271 class rpcbasic_inserter<T,std::vector< signed char > >
272  : public virtual rpcinserter_base<T,std::vector< signed char > >
273 {
274 public:
275  rpcbasic_inserter(T* source, std::vector< signed char > (T::*func)() const)
276  : rpcinserter_base<T,std::vector< signed char > >(source, func)
277  {;}
278 
279  rpcbasic_inserter(T* source, std::vector< signed char > (T::*func)())
280  : rpcinserter_base<T,std::vector< signed char > >(source, func)
281  {;}
282 
284  {
285  std::vector< signed char >
286  vec((rpcinserter_base<T,std::vector< signed char > >::
287  _source->*rpcinserter_base<T,std::vector< signed char > >::_func)());
288  return pmt::init_s8vector(vec.size(), &vec[0]);
289  }
290 };
291 
292 template<typename T>
293 class rpcbasic_inserter<T,std::vector< short > >
294  : public virtual rpcinserter_base<T,std::vector< short > >
295 {
296 public:
297  rpcbasic_inserter(T* source, std::vector< short > (T::*func)() const)
298  : rpcinserter_base<T,std::vector< short > >(source, func)
299  {;}
300 
301  rpcbasic_inserter(T* source, std::vector< short > (T::*func)())
302  : rpcinserter_base<T,std::vector< short > >(source, func)
303  {;}
304 
306  {
307  std::vector< short >
308  vec((rpcinserter_base<T,std::vector< short > >::
309  _source->*rpcinserter_base<T,std::vector< short > >::_func)());
310  return pmt::init_s16vector(vec.size(), &vec[0]);
311  }
312 };
313 
314 template<typename T>
315 class rpcbasic_inserter<T,std::vector< int > >
316  : public virtual rpcinserter_base<T,std::vector< int > >
317 {
318 public:
319  rpcbasic_inserter(T* source, std::vector<int > (T::*func)() const)
320  : rpcinserter_base<T,std::vector<int > >(source, func)
321  {;}
322 
323  rpcbasic_inserter(T* source, std::vector<int > (T::*func)())
324  : rpcinserter_base<T,std::vector<int > >(source, func)
325  {;}
326 
328  {
329  std::vector< int >
330  vec((rpcinserter_base<T,std::vector<int > >::
331  _source->*rpcinserter_base<T,std::vector< int > >::_func)());
332  return pmt::init_s32vector(vec.size(), &vec[0]);
333  }
334 };
335 
336 template<typename T>
337 class rpcbasic_inserter<T,std::vector< std::complex<float> > >
338  : public virtual rpcinserter_base<T,std::vector< std::complex<float> > >
339 {
340 public:
341  rpcbasic_inserter(T* source, std::vector<std::complex<float> > (T::*func)() const)
342  : rpcinserter_base<T,std::vector<std::complex<float> > >(source, func)
343  {;}
344 
345  rpcbasic_inserter(T* source, std::vector<std::complex<float> > (T::*func)())
346  : rpcinserter_base<T,std::vector<std::complex<float> > >(source, func)
347  {;}
348 
350  {
351  std::vector< std::complex<float> >
352  vec((rpcinserter_base<T,std::vector<std::complex<float> > >::
353  _source->*rpcinserter_base<T,std::vector< std::complex<float> > >::_func)());
354  return pmt::init_c32vector(vec.size(), &vec[0]);
355  }
356 };
357 
358 template<typename T>
359 class rpcbasic_inserter<T,std::vector< float> >
360  : public virtual rpcinserter_base<T,std::vector< float > >
361 {
362 public:
363  rpcbasic_inserter(T* source, std::vector<float> (T::*func)() const)
364  : rpcinserter_base<T,std::vector<float > >(source, func)
365  {;}
366 
367  rpcbasic_inserter(T* source, std::vector<float> (T::*func)())
368  : rpcinserter_base<T,std::vector<float> >(source, func)
369  {;}
370 
372  {
373  std::vector< float > vec((rpcinserter_base<T,std::vector<float> >::
374  _source->*rpcinserter_base<T,std::vector< float> >::_func)());
375  return pmt::init_f32vector(vec.size(), &vec[0]);
376  }
377 };
378 
379 template<typename T>
380 class rpcbasic_inserter<T,std::vector< uint8_t> >
381  : public virtual rpcinserter_base<T,std::vector< uint8_t > > {
382 public:
383  rpcbasic_inserter(T* source, std::vector<uint8_t> (T::*func)() const)
384  : rpcinserter_base<T,std::vector<uint8_t > >(source, func)
385  {;}
386 
387  rpcbasic_inserter(T* source, std::vector<uint8_t> (T::*func)())
388  : rpcinserter_base<T,std::vector<uint8_t> >(source, func)
389  {;}
390 
392  {
393  std::vector< uint8_t > vec((rpcinserter_base<T,std::vector<uint8_t> >::
394  _source->*rpcinserter_base<T,std::vector< uint8_t> >::_func)());
395  return pmt::init_u8vector(vec.size(), &vec[0]);
396  }
397 };
398 
399 template<typename T>
400 class rpcbasic_inserter<T,std::complex<float> >
401  : public virtual rpcinserter_base<T,std::complex<float > > {
402 public:
403  rpcbasic_inserter(T* source, std::complex<float> (T::*func)() const)
404  : rpcinserter_base<T,std::complex<float> >(source, func)
405  {;}
406 
407  rpcbasic_inserter(T* source, std::complex<float> (T::*func)())
408  : rpcinserter_base<T,std::complex<float> >(source, func)
409  {;}
410 
412  {
413  std::complex<float > k((rpcinserter_base<T,std::complex<float> >::
414  _source->*rpcinserter_base<T,std::complex<float> >::_func)());
415  return pmt::from_complex(k);
416  }
417 };
418 
419 template<typename T>
420 class rpcbasic_inserter<T,std::complex<double> >
421  : public virtual rpcinserter_base<T,std::complex<double > > {
422 public:
423  rpcbasic_inserter(T* source, std::complex<double> (T::*func)() const)
424  : rpcinserter_base<T,std::complex<double> >(source, func)
425  {;}
426 
427  rpcbasic_inserter(T* source, std::complex<double> (T::*func)())
428  : rpcinserter_base<T,std::complex<double> >(source, func)
429  {;}
430 
432  {
433  std::complex<double > k((rpcinserter_base<T,std::complex<double> >::
434  _source->*rpcinserter_base<T,std::complex<double> >::_func)());
435  return pmt::from_complex(k);
436  }
437 };
438 
439 template <typename T>
441 {
443 protected: static int count;
444 };
445 
446 // Base class to inherit from and create universal shared pointers.
448 {
449 public:
451  virtual ~rpcbasic_base() {};
452 };
453 
455 
456 template<typename T, typename Tto>
458 {
459  // Function used to add a 'set' RPC call using a basic_block's alias.
460  rpcbasic_register_set(const std::string& block_alias,
461  const char* functionbase,
462  void (T::*function)(Tto),
463  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
464  const char* units_ = "",
465  const char* desc_ = "",
466  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
467  DisplayType display_ = DISPNULL)
468  {
469  d_min = min;
470  d_max = max;
471  d_def = def;
472  d_units = units_;
473  d_desc = desc_;
474  d_minpriv = minpriv_;
475  d_display = display_;
476  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
477 #ifdef RPCSERVER_ENABLED
479  extractor(new rpcbasic_extractor<T,Tto>(d_object, function),
480  minpriv_, std::string(units_),
481  display_, std::string(desc_), min, max, def);
482  std::ostringstream oss(std::ostringstream::out);
483  oss << block_alias << "::" << functionbase;
484  d_id = oss.str();
485  //std::cerr << "REGISTERING SET: " << d_id << " " << desc_ << std::endl;
486  rpcmanager::get()->i()->registerConfigureCallback(d_id, extractor);
487 #endif
488  }
489 
490  // Function used to add a 'set' RPC call using a name and the object
491  rpcbasic_register_set(const std::string& name,
492  const char* functionbase,
493  T* obj,
494  void (T::*function)(Tto),
495  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
496  const char* units_ = "",
497  const char* desc_ = "",
498  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
499  DisplayType display_ = DISPNULL)
500  {
501  d_min = min;
502  d_max = max;
503  d_def = def;
504  d_units = units_;
505  d_desc = desc_;
506  d_minpriv = minpriv_;
507  d_display = display_;
508  d_object = obj;
509 #ifdef RPCSERVER_ENABLED
511  extractor(new rpcbasic_extractor<T,Tto>(d_object, function),
512  minpriv_, std::string(units_),
513  display_, std::string(desc_), min, max, def);
514  std::ostringstream oss(std::ostringstream::out);
515  oss << name << "::" << functionbase;
516  d_id = oss.str();
517  //std::cerr << "REGISTERING SET: " << d_id << " " << desc_ << std::endl;
518  rpcmanager::get()->i()->registerConfigureCallback(d_id, extractor);
519 #endif
520  }
521 
523  {
524 #ifdef RPCSERVER_ENABLED
526 #endif
527  }
528 
529 
530  pmt::pmt_t min() const { return d_min; }
531  pmt::pmt_t max() const { return d_max; }
532  pmt::pmt_t def() const { return d_def; }
533  std::string units() const { return d_units; }
534  std::string description() const { return d_desc; }
535  priv_lvl_t privilege_level() const { return d_minpriv; }
536  DisplayType default_display() const { return d_display; }
537 
538  void set_min(pmt::pmt_t p) { d_min = p; }
539  void set_max(pmt::pmt_t p) { d_max = p; }
540  void set_def(pmt::pmt_t p) { d_def = p; }
541  void units(std::string u) { d_units = u; }
542  void description(std::string d) { d_desc = d; }
543  void privilege_level(priv_lvl_t p) { d_minpriv = p; }
544  void default_display(DisplayType d) { d_display = d; }
545 
546 private:
547  std::string d_id;
548  pmt::pmt_t d_min, d_max, d_def;
549  std::string d_units, d_desc;
550  priv_lvl_t d_minpriv;
551  DisplayType d_display;
552  T *d_object;
553 };
554 
555 
556 template<typename T, typename Tfrom>
558 {
559 public:
560  // Function used to add a 'set' RPC call using a basic_block's alias.
561  // primary constructor to allow for T get() functions
562  rpcbasic_register_get(const std::string& block_alias,
563  const char* functionbase,
564  Tfrom (T::*function)(),
565  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
566  const char* units_ = "",
567  const char* desc_ = "",
568  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
569  DisplayType display_ = DISPNULL)
570  {
571  d_min = min;
572  d_max = max;
573  d_def = def;
574  d_units = units_;
575  d_desc = desc_;
576  d_minpriv = minpriv_;
577  d_display = display_;
578  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
579 #ifdef RPCSERVER_ENABLED
581  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, function),
582  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
583  std::ostringstream oss(std::ostringstream::out);
584  oss << block_alias << "::" << functionbase;
585  d_id = oss.str();
586  //std::cerr << "REGISTERING GET: " << d_id << " " << desc_ << std::endl;
587  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
588 #endif
589  }
590 
591 
592  // alternate constructor to allow for T get() const functions
593  rpcbasic_register_get(const std::string& block_alias,
594  const char* functionbase,
595  Tfrom (T::*function)() const,
596  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
597  const char* units_ = "",
598  const char* desc_ = "",
599  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
600  DisplayType display_ = DISPNULL)
601  {
602  d_min = min;
603  d_max = max;
604  d_def = def;
605  d_units = units_;
606  d_desc = desc_;
607  d_minpriv = minpriv_;
608  d_display = display_;
609  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
610 #ifdef RPCSERVER_ENABLED
612  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, (Tfrom (T::*)())function),
613  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
614  std::ostringstream oss(std::ostringstream::out);
615  oss << block_alias << "::" << functionbase;
616  d_id = oss.str();
617  //std::cerr << "REGISTERING GET CONST: " << d_id << " " << desc_ << " " << display_ << std::endl;
618  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
619 #endif
620  }
621 
622  // Function used to add a 'set' RPC call using a name and the object
623  // primary constructor to allow for T get() functions
624  rpcbasic_register_get(const std::string& name,
625  const char* functionbase,
626  T* obj,
627  Tfrom (T::*function)(),
628  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
629  const char* units_ = "",
630  const char* desc_ = "",
631  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
632  DisplayType display_ = DISPNULL)
633  {
634  d_min = min;
635  d_max = max;
636  d_def = def;
637  d_units = units_;
638  d_desc = desc_;
639  d_minpriv = minpriv_;
640  d_display = display_;
641  d_object = obj;
642 #ifdef RPCSERVER_ENABLED
644  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, function),
645  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
646  std::ostringstream oss(std::ostringstream::out);
647  oss << name << "::" << functionbase;
648  d_id = oss.str();
649  //std::cerr << "REGISTERING GET: " << d_id << " " << desc_ << std::endl;
650  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
651 #endif
652  }
653 
654 
655  // alternate constructor to allow for T get() const functions
656  rpcbasic_register_get(const std::string& name,
657  const char* functionbase,
658  T* obj,
659  Tfrom (T::*function)() const,
660  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
661  const char* units_ = "",
662  const char* desc_ = "",
663  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
664  DisplayType display_ = DISPNULL)
665  {
666  d_min = min;
667  d_max = max;
668  d_def = def;
669  d_units = units_;
670  d_desc = desc_;
671  d_minpriv = minpriv_;
672  d_display = display_;
673  d_object = obj;
674 #ifdef RPCSERVER_ENABLED
676  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, (Tfrom (T::*)())function),
677  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
678  std::ostringstream oss(std::ostringstream::out);
679  oss << name << "::" << functionbase;
680  d_id = oss.str();
681  //std::cerr << "REGISTERING GET CONST: " << d_id << " " << desc_ << " " << display_ << std::endl;
682  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
683 #endif
684  }
685 
687  {
688 #ifdef RPCSERVER_ENABLED
690 #endif
691  }
692 
693  pmt::pmt_t min() const { return d_min; }
694  pmt::pmt_t max() const { return d_max; }
695  pmt::pmt_t def() const { return d_def; }
696  std::string units() const { return d_units; }
697  std::string description() const { return d_desc; }
698  priv_lvl_t privilege_level() const { return d_minpriv; }
699  DisplayType default_display() const { return d_display; }
700 
701  void set_min(pmt::pmt_t p) { d_min = p; }
702  void set_max(pmt::pmt_t p) { d_max = p; }
703  void set_def(pmt::pmt_t p) { d_def = p; }
704  void units(std::string u) { d_units = u; }
705  void description(std::string d) { d_desc = d; }
706  void privilege_level(priv_lvl_t p) { d_minpriv = p; }
707  void default_display(DisplayType d) { d_display = d; }
708 
709 private:
710  std::string d_id;
711  pmt::pmt_t d_min, d_max, d_def;
712  std::string d_units, d_desc;
713  priv_lvl_t d_minpriv;
714  DisplayType d_display;
715  T *d_object;
716 };
717 
718 /*
719  * This class can wrap a pre-existing variable type for you
720  * it will define the getter and rpcregister call for you.
721  *
722  * It should be used for read-only getters.
723  *
724  */
725 template<typename Tfrom>
727 {
728 protected:
730  Tfrom *d_variable;
731  Tfrom get() { return *d_variable; }
732 public:
733  // empty constructor which should never be called but needs to exist for ues in varous STL data structures
734  void setptr(Tfrom* _variable){ rpcbasic_register_variable<Tfrom>::d_variable = _variable; }
736  d_rpc_reg("FAIL", "FAIL", this, &rpcbasic_register_variable::get,
737  pmt::PMT_NIL, pmt::PMT_NIL, pmt::PMT_NIL, DISPNULL,
738  "FAIL", "FAIL", RPC_PRIVLVL_MIN),
739  d_variable(NULL)
740  {
741  throw std::runtime_error("ERROR: rpcbasic_register_variable called with no args. If this happens, someone has tried to use rpcbasic_register_variable incorrectly.");
742  };
743 
744  rpcbasic_register_variable(const std::string& namebase,
745  const char* functionbase,
746  Tfrom *variable,
747  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
748  const char* units_ = "",
749  const char* desc_ = "",
750  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
751  DisplayType display_=DISPNULL) :
752  d_rpc_reg(namebase, functionbase, this, &rpcbasic_register_variable::get,
753  min, max, def, units_, desc_, minpriv_, display_),
754  d_variable(variable)
755  {
756  //std::cerr << "REGISTERING VAR: " << " " << desc_ << std::endl;
757  }
758 };
759 
760 template<typename Tfrom> class rpcbasic_register_variable_rw : public rpcbasic_register_variable<Tfrom> {
761  private:
763  public:
764  // empty constructor which should never be called but needs to exist for ues in varous STL data structures
766  d_rpc_regset("FAIL","FAIL",this,&rpcbasic_register_variable<Tfrom>::get,pmt::PMT_NIL,pmt::PMT_NIL,pmt::PMT_NIL,DISPNULL,"FAIL","FAIL",RPC_PRIVLVL_MIN)
767  {
768  throw std::runtime_error("ERROR: rpcbasic_register_variable_rw called with no args. if this happens someone used rpcbasic_register_variable_rw incorrectly.\n");
769  };
770  void set(Tfrom _variable){ *(rpcbasic_register_variable<Tfrom>::d_variable) = _variable; }
772  const std::string& namebase,
773  const char* functionbase,
774  Tfrom *variable,
775  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
776  const char* units_ = "",
777  const char* desc_ = "",
778  priv_lvl_t minpriv = RPC_PRIVLVL_MIN,
779  DisplayType display_=DISPNULL) :
780  rpcbasic_register_variable<Tfrom>(namebase,functionbase,variable,min,max,def,units_,desc_),
781  d_rpc_regset(namebase,functionbase,this,&rpcbasic_register_variable_rw::set,min,max,def,units_,desc_,minpriv,display_)
782  {
783  // no action
784  }
785 };
786 
787 
788 
789 
790 #endif
Definition: rpcregisterhelpers.h:447
virtual void registerConfigureCallback(const std::string &id, const configureCallback_t callback)=0
rpcbasic_register_get< rpcbasic_register_variable< Tfrom >, Tfrom > d_rpc_reg
Definition: rpcregisterhelpers.h:729
Definition: rpccallbackregister_base.h:80
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:349
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:263
Tfrom get()
Definition: rpcregisterhelpers.h:731
PMT_API pmt_t from_complex(double re, double im)
Return a complex number constructed of the given real and imaginary parts.
rpcbasic_inserter(T *source, std::complex< double >(T::*func)())
Definition: rpcregisterhelpers.h:427
rpcbasic_register_get(const std::string &name, const char *functionbase, T *obj, Tfrom(T::*function)() const, const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:656
rpcbasic_inserter(T *source, std::vector< signed char >(T::*func)())
Definition: rpcregisterhelpers.h:279
PMT_API pmt_t init_s32vector(size_t k, const int32_t *data)
rpcbasic_register_variable()
Definition: rpcregisterhelpers.h:735
std::string units() const
Definition: rpcregisterhelpers.h:533
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:371
pmt::pmt_t def() const
Definition: rpcregisterhelpers.h:532
void set(Tfrom _variable)
Definition: rpcregisterhelpers.h:770
PMT_API std::complex< double > to_complex(pmt_t z)
rpcbasic_inserter(T *source, std::vector< int >(T::*func)())
Definition: rpcregisterhelpers.h:323
T * _source
Definition: rpcregisterhelpers.h:72
rpcbasic_register_variable_rw()
Definition: rpcregisterhelpers.h:765
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:69
rpcbasic_extractor(T *source, void(T::*func)(double))
Definition: rpcregisterhelpers.h:131
float min(float a, float b)
rpcbasic_register_set(const std::string &block_alias, const char *functionbase, void(T::*function)(Tto), const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:460
rpcbasic_extractor(T *source, void(T::*func)(float))
Definition: rpcregisterhelpers.h:146
rpcbasic_inserter(T *source, std::vector< short >(T::*func)() const)
Definition: rpcregisterhelpers.h:297
PMT_API pmt_t init_u8vector(size_t k, const uint8_t *data)
Definition: rpcregisterhelpers.h:54
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:195
rpcbasic_inserter(T *source, std::complex< float >(T::*func)())
Definition: rpcregisterhelpers.h:407
Tfrom * d_variable
Definition: rpcregisterhelpers.h:730
Definition: rpcregisterhelpers.h:760
Definition: rpcregisterhelpers.h:440
rpcbasic_inserter(T *source, std::vector< short >(T::*func)())
Definition: rpcregisterhelpers.h:301
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:244
PMT_API pmt_t init_s8vector(size_t k, const int8_t *data)
Virtual base class that produces messages.
Definition: msg_producer.h:35
T * _source
Definition: rpcregisterhelpers.h:49
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:411
rpcbasic_inserter(T *source, std::vector< uint8_t >(T::*func)())
Definition: rpcregisterhelpers.h:387
void(T::* _func)(Tto)
Definition: rpcregisterhelpers.h:50
std::string description() const
Definition: rpcregisterhelpers.h:534
priv_lvl_t
Definition: rpccallbackregister_base.h:46
void default_display(DisplayType d)
Definition: rpcregisterhelpers.h:544
void privilege_level(priv_lvl_t p)
Definition: rpcregisterhelpers.h:706
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:120
unsigned char uint8_t
Definition: stdint.h:78
pmt::pmt_t max() const
Definition: rpcregisterhelpers.h:531
void units(std::string u)
Definition: rpcregisterhelpers.h:704
Definition: rpcregisterhelpers.h:63
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:135
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:44
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:105
PMT_API pmt_t intern(const std::string &s)
Alias for pmt_string_to_symbol.
rpcbasic_extractor(T *source, void(T::*func)(std::string))
Definition: rpcregisterhelpers.h:240
virtual void unregisterConfigureCallback(const std::string &id)=0
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:283
rpcbasic_extractor(T *source, void(T::*func)(Tto))
Definition: rpcregisterhelpers.h:57
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:391
rpcbasic_extractor(T *source, void(T::*func)(char))
Definition: rpcregisterhelpers.h:101
PMT_API const std::string symbol_to_string(const pmt_t &sym)
static int count
Definition: rpcregisterhelpers.h:443
void set_max(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:702
PMT_API bool to_bool(pmt_t val)
Return true if val is pmt::True, return false when val is pmt::PMT_F,.
shared_ptr documentation stub
Definition: shared_ptr_docstub.h:15
rpcbasic_inserter(T *source, uint64_t(T::*func)())
Definition: rpcregisterhelpers.h:259
Definition: rpccallbackregister_base.h:48
Tfrom(T::* _func)()
Definition: rpcregisterhelpers.h:73
rpcbasic_extractor(T *source, void(T::*func)(long))
Definition: rpcregisterhelpers.h:161
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:89
Definition: rpcregisterhelpers.h:557
virtual void registerQueryCallback(const std::string &id, const queryCallback_t callback)=0
void privilege_level(priv_lvl_t p)
Definition: rpcregisterhelpers.h:543
Definition: rpcregisterhelpers.h:77
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:327
PMT_API pmt_t from_uint64(uint64_t x)
Return the pmt value that represents the uint64 x.
rpcbasic_register_variable_rw(const std::string &namebase, const char *functionbase, Tfrom *variable, const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:771
rpcbasic_register_set(const std::string &name, const char *functionbase, T *obj, void(T::*function)(Tto), const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:491
virtual ~rpcbasic_base()
Definition: rpcregisterhelpers.h:451
void set_def(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:703
priv_lvl_t privilege_level() const
Definition: rpcregisterhelpers.h:698
rpcbasic_extractor(T *source, void(T::*func)(std::complex< double >))
Definition: rpcregisterhelpers.h:224
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:150
virtual void unregisterQueryCallback(const std::string &id)=0
rpcbasic_register_variable(const std::string &namebase, const char *functionbase, Tfrom *variable, const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:744
rpcinserter_base(T *source, Tfrom(T::*func)())
Definition: rpcregisterhelpers.h:66
rpcbasic_register_get(const std::string &name, const char *functionbase, T *obj, Tfrom(T::*function)(), const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:624
Definition: rpcregisterhelpers.h:36
rpcbasic_extractor(T *source, void(T::*func)(short))
Definition: rpcregisterhelpers.h:116
unsigned __int64 uint64_t
Definition: stdint.h:90
rpcbasic_register_get(const std::string &block_alias, const char *functionbase, Tfrom(T::*function)(), const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:562
Virtual base class that accepts messages.
Definition: messages/msg_accepter.h:35
rpcbasic_inserter(T *source, uint64_t(T::*func)() const)
Definition: rpcregisterhelpers.h:255
void set_max(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:539
PMT_API long to_long(pmt_t x)
Convert pmt to long if possible.
~rpcextractor_base()
Definition: rpcregisterhelpers.h:42
virtual rpcserver_base * i()=0
rpcextractor_base(T *source, void(T::*func)(Tto))
Definition: rpcregisterhelpers.h:40
PMT_API double to_double(pmt_t x)
Convert pmt to double if possible.
void setptr(Tfrom *_variable)
Definition: rpcregisterhelpers.h:734
static rpcserver_booter_base * get()
rpcbasic_extractor(T *source, void(T::*func)(std::complex< float >))
Definition: rpcregisterhelpers.h:207
pmt::pmt_t max() const
Definition: rpcregisterhelpers.h:694
rpcbasic_inserter(T *source, std::vector< float >(T::*func)())
Definition: rpcregisterhelpers.h:367
~rpcbasic_register_get()
Definition: rpcregisterhelpers.h:686
pmt::pmt_t min() const
Definition: rpcregisterhelpers.h:693
rpcbasic_inserter(T *source, std::vector< int >(T::*func)() const)
Definition: rpcregisterhelpers.h:319
Definition: rpcregisterhelpers.h:726
priv_lvl_t privilege_level() const
Definition: rpcregisterhelpers.h:535
const uint32_t DISPNULL
Definition: rpccallbackregister_base.h:32
rpcbasic_inserter(T *source, std::vector< float >(T::*func)() const)
Definition: rpcregisterhelpers.h:363
void set_def(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:540
PMT_API pmt_t init_f32vector(size_t k, const float *data)
VOLK_API void(kern.name) _manual($kern.arglist_full
Call into a specific implementation given by name.
DisplayType default_display() const
Definition: rpcregisterhelpers.h:536
pmt::pmt_t def() const
Definition: rpcregisterhelpers.h:695
rpcbasic_inserter(T *source, std::vector< uint8_t >(T::*func)() const)
Definition: rpcregisterhelpers.h:383
pmt::pmt_t min() const
Definition: rpcregisterhelpers.h:530
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:180
rpcinserter_base()
Definition: rpcregisterhelpers.h:67
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:431
PMT_API pmt_t init_c32vector(size_t k, const std::complex< float > *data)
std::string units() const
Definition: rpcregisterhelpers.h:696
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
GR_RUNTIME_API gr::block_registry global_block_registry
rpcbasic_inserter(T *source, std::complex< float >(T::*func)() const)
Definition: rpcregisterhelpers.h:403
rpcbasic_register_get(const std::string &block_alias, const char *functionbase, Tfrom(T::*function)() const, const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Definition: rpcregisterhelpers.h:593
rpcbasic_inserter(T *source, Tfrom(T::*func)())
Definition: rpcregisterhelpers.h:85
void set_min(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:538
rpcbasic_base()
Definition: rpcregisterhelpers.h:450
std::string description() const
Definition: rpcregisterhelpers.h:697
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:165
void units(std::string u)
Definition: rpcregisterhelpers.h:541
~rpcbasic_register_set()
Definition: rpcregisterhelpers.h:522
void default_display(DisplayType d)
Definition: rpcregisterhelpers.h:707
rpcbasic_inserter(T *source, std::complex< double >(T::*func)() const)
Definition: rpcregisterhelpers.h:423
void description(std::string d)
Definition: rpcregisterhelpers.h:542
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 set_min(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:701
rpc_register_base()
Definition: rpcregisterhelpers.h:442
rpcbasic_inserter(T *source, std::vector< std::complex< float > >(T::*func)() const)
Definition: rpcregisterhelpers.h:341
PMT_API pmt_t init_s16vector(size_t k, const int16_t *data)
rpcbasic_extractor(T *source, void(T::*func)(int))
Definition: rpcregisterhelpers.h:176
rpcbasic_inserter(T *source, Tfrom(T::*func)() const)
Definition: rpcregisterhelpers.h:81
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:211
basic_block_sptr block_lookup(pmt::pmt_t symbol)
rpcbasic_inserter(T *source, std::vector< signed char >(T::*func)() const)
Definition: rpcregisterhelpers.h:275
void description(std::string d)
Definition: rpcregisterhelpers.h:705
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:305
static pmt_t mp(const std::string &s)
Make pmt symbol.
Definition: pmt_sugar.h:36
rpcbasic_extractor(T *source, void(T::*func)(bool))
Definition: rpcregisterhelpers.h:191
unsigned char bool
Definition: stdbool.h:30
DisplayType default_display() const
Definition: rpcregisterhelpers.h:699
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:228
rpcbasic_inserter(T *source, std::vector< std::complex< float > >(T::*func)())
Definition: rpcregisterhelpers.h:345
PMT_API const pmt_t PMT_NIL
uint32_t DisplayType
Definition: rpccallbackregister_base.h:29
Definition: rpcregisterhelpers.h:457