GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
rpcregisterhelpers.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012,2014 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>
33 
34 // Fixes circular dependency issue before including block_registry.h
35 class rpcbasic_base;
36 typedef boost::shared_ptr<rpcbasic_base> rpcbasic_sptr;
37 
39 
40 
41 /*********************************************************************
42  * RPC Extractor Base Classes
43  ********************************************************************/
44 
45 /*!
46  *\brief Base class for registering a ControlPort Extractor. Acts as
47  * a message acceptor.
48  */
49 template<typename T, typename Tto>
51  : public virtual gr::messages::msg_accepter
52 {
53 public:
54  rpcextractor_base(T* source, void (T::*func)(Tto)) :
55  _source(source), _func(func) {;}
57 
58  void post(pmt::pmt_t which_port, pmt::pmt_t msg) {
59  throw std::runtime_error("rpcextractor_base: no post defined for this data type.\n");
60  }
61 
62 protected:
63  T* _source;
64  void (T::*_func)(Tto);
65 };
66 
67 template<typename T>
68 class rpcextractor_base<T,void>
69  : public virtual gr::messages::msg_accepter
70 {
71 public:
72  rpcextractor_base(T* source, void (T::*func)()) :
73  _source(source), _func(func) {;}
75 
76  void post(pmt::pmt_t which_port, pmt::pmt_t msg) {
77  throw std::runtime_error("rpcextractor_base: no post defined for this data type.\n");
78  }
79 
80 protected:
81  T* _source;
82  void (T::*_func)();
83 };
84 
85 /*!
86  * \brief Templated parent class for registering a ControlPort Extractor.
87  */
88 template<typename T, typename Tto>
89 class rpcbasic_extractor : public virtual rpcextractor_base<T,Tto>
90 {
91 public:
92  rpcbasic_extractor(T* source, void (T::*func)(Tto)) :
93  rpcextractor_base<T,Tto>(source, func)
94  {;}
95 };
96 
97 
98 /*********************************************************************
99  * RPC Inserter Base Classes
100  ********************************************************************/
101 
102 /*!
103  * \brief Base class for registering a ControlPort Inserter. Produces a
104  * message.
105  */
106 template<typename T, typename Tfrom>
108 {
109 public:
110  rpcinserter_base(T* source, Tfrom (T::*func)()) : _source(source), _func(func) {;}
112 
113  pmt::pmt_t retrieve() { assert(0); return pmt::pmt_t(); }
114 
115 protected:
117  Tfrom (T::*_func)();
118 };
119 
120 
121 /*!
122  * \brief Templated parent class for registering a ControlPort
123  * Inserter.
124  */
125 template<typename T, typename Tfrom>
127  public virtual rpcinserter_base<T,Tfrom>
128 {
129 public:
130  rpcbasic_inserter(T* source, Tfrom (T::*func)()const)
131  : rpcinserter_base<T,Tfrom>(source, func)
132  {;}
133 
134  rpcbasic_inserter(T* source, Tfrom (T::*func)())
135  : rpcinserter_base<T,Tfrom>(source, func)
136  {;}
137 
139  {
142  }
143 };
144 
145 
146 
147 /*********************************************************************
148  * RPC Handler Base Classes
149  ********************************************************************/
150 
151 /*!
152  *\brief Base class for registering a ControlPort Handler. Acts as
153  * a message acceptor.
154  */
155 template<typename T>
157  : public virtual gr::messages::msg_accepter
158 {
159 public:
160  rpchandler_base(T* source, const char* handler) :
161  _source(source), _handler(handler) {;}
163 
164  void post(pmt::pmt_t which_port, pmt::pmt_t msg) {
165  _source->post(which_port, msg);
166  }
167 
168 protected:
170  const char* _handler;
171 };
172 
173 
174 /*!
175  * \brief Templated parent class for registering a ControlPort Extractor.
176  */
177 template<typename T>
178 class rpcbasic_handler : public virtual rpchandler_base<T>
179 {
180 public:
181  rpcbasic_handler(T* source, const char* handler) :
182  rpchandler_base<T>(source, handler)
183  {;}
184 };
185 
186 
187 
188 
189 /*********************************************************************
190  * RPC Specialized Extractors
191  ********************************************************************/
192 
193 /*!
194  * \brief Specialized extractor class to make calls to functions that
195  * do not take data (enable, reset, start, etc.).
196  */
197 template<typename T>
198 class rpcbasic_extractor<T,void> : public virtual rpcextractor_base<T,void>
199 {
200 public:
201  rpcbasic_extractor(T* source, void (T::*func)())
202  : rpcextractor_base<T,void>(source, func)
203  {;}
204 
205  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
206  {
208  }
209 };
210 
211 /*!
212  * \brief Specialized extractor class for char data.
213  */
214 template<typename T>
215 class rpcbasic_extractor<T,char> : public virtual rpcextractor_base<T,char>
216 {
217 public:
218  rpcbasic_extractor(T* source, void (T::*func)(char))
219  : rpcextractor_base<T,char>(source, func)
220  {;}
221 
222  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
223  {
225  (static_cast<char>(pmt::to_long(msg)));
226  }
227 };
228 
229 /*!
230  * \brief Specialized extractor class for short data.
231  */
232 template<typename T>
233 class rpcbasic_extractor<T,short> : public virtual rpcextractor_base<T,short>
234 {
235 public:
236  rpcbasic_extractor(T* source, void (T::*func)(short))
237  : rpcextractor_base<T,short>(source, func)
238  {;}
239 
240  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
241  {
243  (static_cast<short>(pmt::to_long(msg)));
244  }
245 };
246 
247 /*!
248  * \brief Specialized extractor class for double data.
249  */
250 template<typename T>
251 class rpcbasic_extractor<T,double> : public virtual rpcextractor_base<T,double>
252 {
253 public:
254  rpcbasic_extractor(T* source, void (T::*func)(double))
255  : rpcextractor_base<T,double>(source, func)
256  {;}
257 
258  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
259  {
261  (pmt::to_double(msg));
262  }
263 };
264 
265 /*!
266  * \brief Specialized extractor class for float data.
267  */
268 template<typename T>
269 class rpcbasic_extractor<T,float> : public virtual rpcextractor_base<T,float>
270 {
271 public:
272  rpcbasic_extractor(T* source, void (T::*func)(float))
273  : rpcextractor_base<T,float>(source, func)
274  {;}
275 
276  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
277  {
279  (pmt::to_double(msg));
280  }
281 };
282 
283 /*!
284  * \brief Specialized extractor class for long data.
285  */
286 template<typename T>
287 class rpcbasic_extractor<T,long> : public virtual rpcextractor_base<T,long>
288 {
289 public:
290  rpcbasic_extractor(T* source, void (T::*func)(long))
291  : rpcextractor_base<T,long>(source, func)
292  {;}
293 
294  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
295  {
297  (pmt::to_long(msg));
298  }
299 };
300 
301 /*!
302  * \brief Specialized extractor class for int data.
303  */
304 template<typename T>
305 class rpcbasic_extractor<T,int> : public virtual rpcextractor_base<T,int>
306 {
307 public:
308  rpcbasic_extractor(T* source, void (T::*func)(int))
309  : rpcextractor_base<T,int>(source, func)
310  {;}
311 
312  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
313  {
315  (pmt::to_long(msg));
316  }
317 };
318 
319 /*!
320  * \brief Specialized extractor class for bool data.
321  */
322 template<typename T>
323 class rpcbasic_extractor<T,bool> : public virtual rpcextractor_base<T,bool>
324 {
325 public:
326  rpcbasic_extractor(T* source, void (T::*func)(bool))
327  : rpcextractor_base<T,bool>(source, func)
328  {;}
329 
330  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
331  {
333  (pmt::to_bool(msg));
334  }
335 };
336 
337 /*!
338  * \brief Specialized extractor class for complex (float) data.
339  */
340 template<typename T>
341 class rpcbasic_extractor<T,std::complex<float> >
342  : public virtual rpcextractor_base<T,std::complex<float> >
343 {
344 public:
345  rpcbasic_extractor(T* source, void (T::*func)(std::complex<float>))
346  : rpcextractor_base<T,std::complex<float> >(source, func)
347  {;}
348 
349  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
350  {
351  std::complex<float> k = static_cast<std::complex<float> >(pmt::to_complex(msg));
354  }
355 };
356 
357 /*!
358  * \brief Specialized extractor class for complex (double) data.
359  */
360 template<typename T>
361 class rpcbasic_extractor<T,std::complex<double> >
362  : public virtual rpcextractor_base<T,std::complex<double> >
363 {
364 public:
365  rpcbasic_extractor(T* source, void (T::*func)(std::complex<double>))
366  : rpcextractor_base<T,std::complex<double> >(source, func)
367  {;}
368 
369  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
370  {
373  }
374 };
375 
376 /*!
377  * \brief Specialized extractor class for string data.
378  */
379 template<typename T>
380 class rpcbasic_extractor<T,std::string>
381  : public virtual rpcextractor_base<T,std::string>
382 {
383 public:
384  rpcbasic_extractor(T* source, void (T::*func)(std::string))
385  : rpcextractor_base<T,std::string>(source, func)
386  {;}
387 
388  void post(pmt::pmt_t which_port, pmt::pmt_t msg)
389  {
392  }
393 };
394 
395 
396 /*********************************************************************
397  * RPC Specialized Inserters
398  ********************************************************************/
399 
400 /*!
401  * \brief Specialized inserter class for uint64_t data.
402  */
403 template<typename T>
404 class rpcbasic_inserter<T,uint64_t> : public virtual rpcinserter_base<T,uint64_t>
405 {
406 public:
407  rpcbasic_inserter(T* source, uint64_t (T::*func)() const)
408  : rpcinserter_base<T,uint64_t>(source, func)
409  {;}
410 
411  rpcbasic_inserter(T* source, uint64_t (T::*func)())
412  : rpcinserter_base<T,uint64_t>(source, func)
413  {;}
414 
416  {
419  }
420 };
421 
422 /*!
423  * \brief Specialized inserter class for vectors of signed char data.
424  */
425 template<typename T>
426 class rpcbasic_inserter<T,std::vector< signed char > >
427  : public virtual rpcinserter_base<T,std::vector< signed char > >
428 {
429 public:
430  rpcbasic_inserter(T* source, std::vector< signed char > (T::*func)() const)
431  : rpcinserter_base<T,std::vector< signed char > >(source, func)
432  {;}
433 
434  rpcbasic_inserter(T* source, std::vector< signed char > (T::*func)())
435  : rpcinserter_base<T,std::vector< signed char > >(source, func)
436  {;}
437 
439  {
440  std::vector< signed char >
441  vec((rpcinserter_base<T,std::vector< signed char > >::
442  _source->*rpcinserter_base<T,std::vector< signed char > >::_func)());
443  return pmt::init_s8vector(vec.size(), &vec[0]);
444  }
445 };
446 
447 /*!
448  * \brief Specialized inserter class for vectors of short data.
449  */
450 template<typename T>
451 class rpcbasic_inserter<T,std::vector< short > >
452  : public virtual rpcinserter_base<T,std::vector< short > >
453 {
454 public:
455  rpcbasic_inserter(T* source, std::vector< short > (T::*func)() const)
456  : rpcinserter_base<T,std::vector< short > >(source, func)
457  {;}
458 
459  rpcbasic_inserter(T* source, std::vector< short > (T::*func)())
460  : rpcinserter_base<T,std::vector< short > >(source, func)
461  {;}
462 
464  {
465  std::vector< short >
466  vec((rpcinserter_base<T,std::vector< short > >::
467  _source->*rpcinserter_base<T,std::vector< short > >::_func)());
468  return pmt::init_s16vector(vec.size(), &vec[0]);
469  }
470 };
471 
472 /*!
473  * \brief Specialized inserter class for vectors of int data.
474  */
475 template<typename T>
476 class rpcbasic_inserter<T,std::vector< int > >
477  : public virtual rpcinserter_base<T,std::vector< int > >
478 {
479 public:
480  rpcbasic_inserter(T* source, std::vector<int > (T::*func)() const)
481  : rpcinserter_base<T,std::vector<int > >(source, func)
482  {;}
483 
484  rpcbasic_inserter(T* source, std::vector<int > (T::*func)())
485  : rpcinserter_base<T,std::vector<int > >(source, func)
486  {;}
487 
489  {
490  std::vector< int >
491  vec((rpcinserter_base<T,std::vector<int > >::
492  _source->*rpcinserter_base<T,std::vector< int > >::_func)());
493  return pmt::init_s32vector(vec.size(), &vec[0]);
494  }
495 };
496 
497 /*!
498  * \brief Specialized inserter class for vectors of complex (float) data.
499  */
500 template<typename T>
501 class rpcbasic_inserter<T,std::vector< std::complex<float> > >
502  : public virtual rpcinserter_base<T,std::vector< std::complex<float> > >
503 {
504 public:
505  rpcbasic_inserter(T* source, std::vector<std::complex<float> > (T::*func)() const)
506  : rpcinserter_base<T,std::vector<std::complex<float> > >(source, func)
507  {;}
508 
509  rpcbasic_inserter(T* source, std::vector<std::complex<float> > (T::*func)())
510  : rpcinserter_base<T,std::vector<std::complex<float> > >(source, func)
511  {;}
512 
514  {
515  std::vector< std::complex<float> >
516  vec((rpcinserter_base<T,std::vector<std::complex<float> > >::
517  _source->*rpcinserter_base<T,std::vector< std::complex<float> > >::_func)());
518  return pmt::init_c32vector(vec.size(), &vec[0]);
519  }
520 };
521 
522 /*!
523  * \brief Specialized inserter class for vectors of float data.
524  */
525 template<typename T>
526 class rpcbasic_inserter<T,std::vector< float> >
527  : public virtual rpcinserter_base<T,std::vector< float > >
528 {
529 public:
530  rpcbasic_inserter(T* source, std::vector<float> (T::*func)() const)
531  : rpcinserter_base<T,std::vector<float > >(source, func)
532  {;}
533 
534  rpcbasic_inserter(T* source, std::vector<float> (T::*func)())
535  : rpcinserter_base<T,std::vector<float> >(source, func)
536  {;}
537 
539  {
540  std::vector< float > vec((rpcinserter_base<T,std::vector<float> >::
541  _source->*rpcinserter_base<T,std::vector< float> >::_func)());
542  return pmt::init_f32vector(vec.size(), &vec[0]);
543  }
544 };
545 
546 /*!
547  * \brief Specialized inserter class for vectors of uint8_t data.
548  */
549 template<typename T>
550 class rpcbasic_inserter<T,std::vector< uint8_t> >
551  : public virtual rpcinserter_base<T,std::vector< uint8_t > > {
552 public:
553  rpcbasic_inserter(T* source, std::vector<uint8_t> (T::*func)() const)
554  : rpcinserter_base<T,std::vector<uint8_t > >(source, func)
555  {;}
556 
557  rpcbasic_inserter(T* source, std::vector<uint8_t> (T::*func)())
558  : rpcinserter_base<T,std::vector<uint8_t> >(source, func)
559  {;}
560 
562  {
563  std::vector< uint8_t > vec((rpcinserter_base<T,std::vector<uint8_t> >::
564  _source->*rpcinserter_base<T,std::vector< uint8_t> >::_func)());
565  return pmt::init_u8vector(vec.size(), &vec[0]);
566  }
567 };
568 
569 /*!
570  * \brief Specialized inserter class for complex (float) data.
571  */
572 template<typename T>
573 class rpcbasic_inserter<T,std::complex<float> >
574  : public virtual rpcinserter_base<T,std::complex<float > > {
575 public:
576  rpcbasic_inserter(T* source, std::complex<float> (T::*func)() const)
577  : rpcinserter_base<T,std::complex<float> >(source, func)
578  {;}
579 
580  rpcbasic_inserter(T* source, std::complex<float> (T::*func)())
581  : rpcinserter_base<T,std::complex<float> >(source, func)
582  {;}
583 
585  {
586  std::complex<float > k((rpcinserter_base<T,std::complex<float> >::
587  _source->*rpcinserter_base<T,std::complex<float> >::_func)());
588  return pmt::from_complex(k);
589  }
590 };
591 
592 /*!
593  * \brief Specialized inserter class for complex (double) data.
594  */
595 template<typename T>
596 class rpcbasic_inserter<T,std::complex<double> >
597  : public virtual rpcinserter_base<T,std::complex<double > > {
598 public:
599  rpcbasic_inserter(T* source, std::complex<double> (T::*func)() const)
600  : rpcinserter_base<T,std::complex<double> >(source, func)
601  {;}
602 
603  rpcbasic_inserter(T* source, std::complex<double> (T::*func)())
604  : rpcinserter_base<T,std::complex<double> >(source, func)
605  {;}
606 
608  {
609  std::complex<double > k((rpcinserter_base<T,std::complex<double> >::
610  _source->*rpcinserter_base<T,std::complex<double> >::_func)());
611  return pmt::from_complex(k);
612  }
613 };
614 
615 /*!
616  * \brief Base class for registering a ControlPort function.
617  */
618 template <typename T>
620 {
622 protected: static int count;
623 };
624 
625 /*!
626  * Base class to inherit from and create universal shared pointers.
627  */
629 {
630 public:
632  virtual ~rpcbasic_base() {};
633 };
634 
635 
636 
637 /*********************************************************************
638  * RPC Register Set Classes
639  ********************************************************************/
640 
641 /*!
642  * \brief Registers a 'set' function to set a parameter over
643  * ControlPort.
644  *
645  * \details
646  *
647  * This class allows us to remotely set a value or parameter of the
648  * block over ControlPort. The set occurs by calling a setter accessor
649  * function of the class, usually set_[variable](), which is passed in
650  * as \p function.
651  *
652  * We can set the (expected) minimum (\p min), maximum (\p max), and
653  * default (\p def) of the variables being set. These values are not
654  * enforced, however, but can be useful for setting up graphs and
655  * other ways of bounding the data.
656  *
657  * This class also allows us to provide information to the user about
658  * the variable being set, such as an appropriate unit (\p units_) as
659  * well as a description (\p desc_) about what the variable does.
660  *
661  * The privilege (\p minpriv_) level is the minimum privilege level a
662  * remote must identify with to be able to call this function.
663  *
664  * We also provide display hints (\p display_), which can be used by
665  * the ControlPort client application to know how to best display or
666  * even print the data. This is a mask of options for variables set in
667  * rpccallbackregister_base.h. The mask is defined by one of the
668  * "DisplayType Plotting Types" and or'd with any of the "DisplayType
669  * Options" features. See "Display Options" in \ref page_ctrlport for
670  * details.
671  */
672 template<typename T, typename Tto>
674 {
675  /*!
676  * \brief Adds the ability to set the variable over ControlPort.
677  *
678  * \details
679  *
680  * This constructor is specifically for gr::block's to use to add
681  * settable variables to ControlPort. Generally meant to be used
682  * in gr::block::setup_rpc.
683  *
684  * Uses the block's alias to create the ControlPort interface. This
685  * alias is cross-referenced by the global_block_registry (static
686  * variable of type gr::block_registry) to get the pointer to the
687  * block.
688  *
689  * \param block_alias Block's alias; use alias() to get it from the block.
690  * \param functionbase The name of the function that we'll access over ControlPort
691  * \param function A function pointer to the real function accessed when called
692  * something like: &[block class]\::set_[variable]()
693  * \param min Expected minimum value the parameter can hold
694  * \param max Expected maximum value the parameter can hold
695  * \param def Expected default value the parameter can hold
696  * \param units_ A string to describe what units to represent the variable with
697  * \param desc_ A string to describing the variable.
698  * \param minpriv_ The required minimum privilege level
699  * \param display_ The display mask
700  */
701  rpcbasic_register_set(const std::string& block_alias,
702  const char* functionbase,
703  void (T::*function)(Tto),
704  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
705  const char* units_ = "",
706  const char* desc_ = "",
707  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
708  DisplayType display_ = DISPNULL)
709  {
710  d_min = min;
711  d_max = max;
712  d_def = def;
713  d_units = units_;
714  d_desc = desc_;
715  d_minpriv = minpriv_;
716  d_display = display_;
717  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
718 #ifdef GR_RPCSERVER_ENABLED
720  extractor(new rpcbasic_extractor<T,Tto>(d_object, function),
721  minpriv_, std::string(units_),
722  display_, std::string(desc_), min, max, def);
723  std::ostringstream oss(std::ostringstream::out);
724  oss << block_alias << "::" << functionbase;
725  d_id = oss.str();
726  //std::cerr << "REGISTERING SET: " << d_id << " " << desc_ << std::endl;
727  rpcmanager::get()->i()->registerConfigureCallback(d_id, extractor);
728 #endif
729  }
730 
731  /*!
732  * \brief Adds the ability to set the variable over ControlPort.
733  *
734  * \details
735  *
736  * Allows us to add non gr::block related objects to
737  * ControlPort. Instead of using the block's alias, we give it a \p
738  * name and the actual pointer to the object as \p obj. We just need
739  * to make sure that the pointer to this object is always valid.
740  *
741  * \param name Name of the object being set up for ControlPort access
742  * \param functionbase The name of the function that we'll access over ControlPort
743  * \param obj A pointer to the object itself
744  * \param function A function pointer to the real function accessed when called
745  * something like: &[block class]\::set_[variable]()
746  * \param min Expected minimum value the parameter can hold
747  * \param max Expected maximum value the parameter can hold
748  * \param def Expected default value the parameter can hold
749  * \param units_ A string to describe what units to represent the variable with
750  * \param desc_ A string to describing the variable.
751  * \param minpriv_ The required minimum privilege level
752  * \param display_ The display mask
753  */
754  rpcbasic_register_set(const std::string& name,
755  const char* functionbase,
756  T* obj,
757  void (T::*function)(Tto),
758  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
759  const char* units_ = "",
760  const char* desc_ = "",
761  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
762  DisplayType display_ = DISPNULL)
763  {
764  d_min = min;
765  d_max = max;
766  d_def = def;
767  d_units = units_;
768  d_desc = desc_;
769  d_minpriv = minpriv_;
770  d_display = display_;
771  d_object = obj;
772 #ifdef GR_RPCSERVER_ENABLED
774  extractor(new rpcbasic_extractor<T,Tto>(d_object, function),
775  minpriv_, std::string(units_),
776  display_, std::string(desc_), min, max, def);
777  std::ostringstream oss(std::ostringstream::out);
778  oss << name << "::" << functionbase;
779  d_id = oss.str();
780  //std::cerr << "REGISTERING SET: " << d_id << " " << desc_ << std::endl;
781  rpcmanager::get()->i()->registerConfigureCallback(d_id, extractor);
782 #endif
783  }
784 
786  {
787 #ifdef GR_RPCSERVER_ENABLED
789 #endif
790  }
791 
792 
793  pmt::pmt_t min() const { return d_min; }
794  pmt::pmt_t max() const { return d_max; }
795  pmt::pmt_t def() const { return d_def; }
796  std::string units() const { return d_units; }
797  std::string description() const { return d_desc; }
798  priv_lvl_t privilege_level() const { return d_minpriv; }
799  DisplayType default_display() const { return d_display; }
800 
801  void set_min(pmt::pmt_t p) { d_min = p; }
802  void set_max(pmt::pmt_t p) { d_max = p; }
803  void set_def(pmt::pmt_t p) { d_def = p; }
804  void units(std::string u) { d_units = u; }
805  void description(std::string d) { d_desc = d; }
806  void privilege_level(priv_lvl_t p) { d_minpriv = p; }
807  void default_display(DisplayType d) { d_display = d; }
808 
809 private:
810  std::string d_id;
811  pmt::pmt_t d_min, d_max, d_def;
812  std::string d_units, d_desc;
813  priv_lvl_t d_minpriv;
814  DisplayType d_display;
815  T *d_object;
816 };
817 
818 
819 /*********************************************************************
820  * RPC Register Trigger Classes
821  ********************************************************************/
822 
823 /*!
824  * \brief Registers a 'trigger' function to trigger an action over
825  * ControlPort.
826  *
827  * \details
828  *
829  * This class allows us to set up triggered events or function calls
830  * over ControlPort. When used from a ControlPort client, the \p
831  * function established here will be activated. Generally, this is
832  * meant to enable some kind of trigger or action that a block or
833  * object will perform, such as a reset, start, stop, etc.
834  *
835  * Simpler than the rpcbasic_register_set class, the constructor here
836  * only takes a few parameters, mostly because there is not actual
837  * variable associated with these function calls. It takes in the
838  * information to set up the pointer to the object that has the \p
839  * function, a ControlPort name (\p functionbase) for the triggered
840  * action, a description (\p desc_), and a privilege level (\p
841  * minpriv_).
842  */
843 template<typename T>
845 {
846  /*!
847  * \brief Adds the ability to trigger a function over ControlPort.
848  *
849  * \details
850  *
851  * This constructor is specifically for gr::block's to use to add
852  * trigger functions to ControlPort. Generally meant to be used
853  * in gr::block::setup_rpc.
854  *
855  * Uses the block's alias to create the ControlPort interface. This
856  * alias is cross-referenced by the global_block_registry (static
857  * variable of type gr::block_registry) to get the pointer to the
858  * block.
859  *
860  * \param block_alias Block's alias; use alias() to get it from the block.
861  * \param functionbase The name of the function that we'll access over ControlPort
862  * \param function A function pointer to the real function accessed when called
863  * something like: &[block class]\::set_[variable]
864  * \param desc_ A string to describing the variable.
865  * \param minpriv_ The required minimum privilege level
866  */
867  rpcbasic_register_trigger(const std::string& block_alias,
868  const char* functionbase,
869  void (T::*function)(),
870  const char* desc_ = "",
871  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN)
872  {
873  d_desc = desc_;
874  d_minpriv = minpriv_;
875  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
876 #ifdef GR_RPCSERVER_ENABLED
878  extractor(new rpcbasic_extractor<T,void>(d_object, function),
879  minpriv_, std::string(desc_));
880  std::ostringstream oss(std::ostringstream::out);
881  oss << block_alias << "::" << functionbase;
882  d_id = oss.str();
883  //std::cerr << "REGISTERING TRIGGER: " << d_id << " " << desc_ << std::endl;
884  rpcmanager::get()->i()->registerConfigureCallback(d_id, extractor);
885 #endif
886  }
887 
888  /*!
889  * \brief Adds the ability to trigger a function over ControlPort.
890  *
891  * \details
892  *
893  * Allows us to add non gr::block related objects to
894  * ControlPort. Instead of using the block's alias, we give it a \p
895  * name and the actual pointer to the object as \p obj. We just need
896  * to make sure that the pointer to this object is always valid.
897  *
898  * \param name Name of the object being set up for ControlPort access
899  * \param functionbase The name of the function that we'll access over ControlPort
900  * \param obj A pointer to the object itself
901  * \param function A function pointer to the real function accessed when called
902  * something like: &[block class]\::set_[variable]
903  * \param desc_ A string to describing the variable.
904  * \param minpriv_ The required minimum privilege level
905  */
906  rpcbasic_register_trigger(const std::string& name,
907  const char* functionbase,
908  T* obj,
909  void (T::*function)(),
910  const char* desc_ = "",
911  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN)
912  {
913  d_desc = desc_;
914  d_minpriv = minpriv_;
915  d_object = obj;
916 #ifdef GR_RPCSERVER_ENABLED
918  extractor(new rpcbasic_extractor<T,void>(d_object, function),
919  minpriv_, std::string(desc_));
920  std::ostringstream oss(std::ostringstream::out);
921  oss << name << "::" << functionbase;
922  d_id = oss.str();
923  //std::cerr << "REGISTERING TRIGGER: " << d_id << " " << desc_ << std::endl;
924  rpcmanager::get()->i()->registerConfigureCallback(d_id, extractor);
925 #endif
926  }
927 
929  {
930 #ifdef GR_RPCSERVER_ENABLED
932 #endif
933  }
934 
935 
936  std::string description() const { return d_desc; }
937  priv_lvl_t privilege_level() const { return d_minpriv; }
938 
939  void description(std::string d) { d_desc = d; }
940  void privilege_level(priv_lvl_t p) { d_minpriv = p; }
941 
942 private:
943  std::string d_id;
944  std::string d_desc;
945  priv_lvl_t d_minpriv;
946  T *d_object;
947 };
948 
949 
950 
951 /*********************************************************************
952  * RPC Register Get Classes
953  ********************************************************************/
954 
955 /*!
956  * \brief Registers a 'get' function to get a parameter over
957  * ControlPort.
958  *
959  * \details
960  *
961  * This class allows us to remotely get a value or parameter of the
962  * block over ControlPort. The get occurs by calling a getter accessor
963  * function of the class, usually [variable](), which is passed in
964  * as \p function.
965  *
966  * We can set the (expected) minimum (\p min), maximum (\p max), and
967  * default (\p def) of the variables we will get. These values are not
968  * enforced, however, but can be useful for setting up graphs and
969  * other ways of bounding the data.
970  *
971  * This class also allows us to provide information to the user about
972  * the variable, such as an appropriate unit (\p units_) as well as a
973  * description (\p desc_) about what the variable does.
974  *
975  * The privilege (\p minpriv_) level is the minimum privilege level a
976  * remote must identify with to be able to call this function.
977  *
978  * We also provide display hints (\p display_), which can be used by
979  * the ControlPort client application to know how to best display or
980  * even print the data. This is a mask of options for variables set in
981  * rpccallbackregister_base.h. The mask is defined by one of the
982  * "DisplayType Plotting Types" and or'd with any of the "DisplayType
983  * Options" features. See "Display Options" in \ref page_ctrlport for
984  * details.
985  */
986 template<typename T, typename Tfrom>
988 {
989 public:
990 
991  /*!
992  * \brief Adds the ability to get the variable over ControlPort.
993  *
994  * \details
995  *
996  * This constructor is specifically for gr::block's to use to add
997  * gettable variables to ControlPort. Generally meant to be used
998  * in gr::block::setup_rpc.
999  *
1000  * Uses the block's alias to create the ControlPort interface. This
1001  * alias is cross-referenced by the global_block_registry (static
1002  * variable of type gr::block_registry) to get the pointer to the
1003  * block.
1004  *
1005  * \param block_alias Block's alias; use alias() to get it from the block.
1006  * \param functionbase The name of the function that we'll access over ControlPort
1007  * \param function A function pointer to the real function accessed when called
1008  * something like: &[block class]\::[variable]()
1009  * \param min Expected minimum value the parameter can hold
1010  * \param max Expected maximum value the parameter can hold
1011  * \param def Expected default value the parameter can hold
1012  * \param units_ A string to describe what units to represent the variable with
1013  * \param desc_ A string to describing the variable.
1014  * \param minpriv_ The required minimum privilege level
1015  * \param display_ The display mask
1016  */
1017  rpcbasic_register_get(const std::string& block_alias,
1018  const char* functionbase,
1019  Tfrom (T::*function)(),
1020  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
1021  const char* units_ = "",
1022  const char* desc_ = "",
1023  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
1024  DisplayType display_ = DISPNULL)
1025  {
1026  d_min = min;
1027  d_max = max;
1028  d_def = def;
1029  d_units = units_;
1030  d_desc = desc_;
1031  d_minpriv = minpriv_;
1032  d_display = display_;
1033  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
1034 #ifdef GR_RPCSERVER_ENABLED
1036  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, function),
1037  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
1038  std::ostringstream oss(std::ostringstream::out);
1039  oss << block_alias << "::" << functionbase;
1040  d_id = oss.str();
1041  //std::cerr << "REGISTERING GET: " << d_id << " " << desc_ << std::endl;
1042  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
1043 #endif
1044  }
1045 
1046 
1047  /*!
1048  * \brief Same as rpcbasic_register_get::rpcbasic_register_get that allows using
1049  * '[variable]() const' getter functions.
1050  */
1051  rpcbasic_register_get(const std::string& block_alias,
1052  const char* functionbase,
1053  Tfrom (T::*function)() const,
1054  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
1055  const char* units_ = "",
1056  const char* desc_ = "",
1057  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
1058  DisplayType display_ = DISPNULL)
1059  {
1060  d_min = min;
1061  d_max = max;
1062  d_def = def;
1063  d_units = units_;
1064  d_desc = desc_;
1065  d_minpriv = minpriv_;
1066  d_display = display_;
1067  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
1068 #ifdef GR_RPCSERVER_ENABLED
1070  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, (Tfrom (T::*)())function),
1071  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
1072  std::ostringstream oss(std::ostringstream::out);
1073  oss << block_alias << "::" << functionbase;
1074  d_id = oss.str();
1075  //std::cerr << "REGISTERING GET CONST: " << d_id << " " << desc_ << " " << display_ << std::endl;
1076  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
1077 #endif
1078  }
1079 
1080 
1081  /*!
1082  * \brief Adds the ability to get the variable over ControlPort.
1083  *
1084  * \details
1085  *
1086  * Allows us to add non gr::block related objects to
1087  * ControlPort. Instead of using the block's alias, we give it a \p
1088  * name and the actual pointer to the object as \p obj. We just need
1089  * to make sure that the pointer to this object is always valid.
1090  *
1091  * \param name Name of the object being set up for ControlPort access
1092  * \param functionbase The name of the function that we'll access over ControlPort
1093  * \param obj A pointer to the object itself
1094  * \param function A function pointer to the real function accessed when called
1095  * something like: &[block class]\::set_[variable]()
1096  * \param min Expected minimum value the parameter can hold
1097  * \param max Expected maximum value the parameter can hold
1098  * \param def Expected default value the parameter can hold
1099  * \param units_ A string to describe what units to represent the variable with
1100  * \param desc_ A string to describing the variable.
1101  * \param minpriv_ The required minimum privilege level
1102  * \param display_ The display mask
1103  */
1104  rpcbasic_register_get(const std::string& name,
1105  const char* functionbase,
1106  T* obj,
1107  Tfrom (T::*function)(),
1108  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
1109  const char* units_ = "",
1110  const char* desc_ = "",
1111  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
1112  DisplayType display_ = DISPNULL)
1113  {
1114  d_min = min;
1115  d_max = max;
1116  d_def = def;
1117  d_units = units_;
1118  d_desc = desc_;
1119  d_minpriv = minpriv_;
1120  d_display = display_;
1121  d_object = obj;
1122 #ifdef GR_RPCSERVER_ENABLED
1124  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, function),
1125  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
1126  std::ostringstream oss(std::ostringstream::out);
1127  oss << name << "::" << functionbase;
1128  d_id = oss.str();
1129  //std::cerr << "REGISTERING GET: " << d_id << " " << desc_ << std::endl;
1130  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
1131 #endif
1132  }
1133 
1134 
1135  /*!
1136  * \brief Same as above that allows using '[variable]() const'
1137  * getter functions.
1138  */
1139  rpcbasic_register_get(const std::string& name,
1140  const char* functionbase,
1141  T* obj,
1142  Tfrom (T::*function)() const,
1143  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
1144  const char* units_ = "",
1145  const char* desc_ = "",
1146  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
1147  DisplayType display_ = DISPNULL)
1148  {
1149  d_min = min;
1150  d_max = max;
1151  d_def = def;
1152  d_units = units_;
1153  d_desc = desc_;
1154  d_minpriv = minpriv_;
1155  d_display = display_;
1156  d_object = obj;
1157 #ifdef GR_RPCSERVER_ENABLED
1159  inserter(new rpcbasic_inserter<T,Tfrom>(d_object, (Tfrom (T::*)())function),
1160  minpriv_, std::string(units_), display_, std::string(desc_), min, max, def);
1161  std::ostringstream oss(std::ostringstream::out);
1162  oss << name << "::" << functionbase;
1163  d_id = oss.str();
1164  //std::cerr << "REGISTERING GET CONST: " << d_id << " " << desc_ << " " << display_ << std::endl;
1165  rpcmanager::get()->i()->registerQueryCallback(d_id, inserter);
1166 #endif
1167  }
1168 
1170  {
1171 #ifdef GR_RPCSERVER_ENABLED
1173 #endif
1174  }
1175 
1176  pmt::pmt_t min() const { return d_min; }
1177  pmt::pmt_t max() const { return d_max; }
1178  pmt::pmt_t def() const { return d_def; }
1179  std::string units() const { return d_units; }
1180  std::string description() const { return d_desc; }
1181  priv_lvl_t privilege_level() const { return d_minpriv; }
1182  DisplayType default_display() const { return d_display; }
1183 
1184  void set_min(pmt::pmt_t p) { d_min = p; }
1185  void set_max(pmt::pmt_t p) { d_max = p; }
1186  void set_def(pmt::pmt_t p) { d_def = p; }
1187  void units(std::string u) { d_units = u; }
1188  void description(std::string d) { d_desc = d; }
1189  void privilege_level(priv_lvl_t p) { d_minpriv = p; }
1190  void default_display(DisplayType d) { d_display = d; }
1191 
1192 private:
1193  std::string d_id;
1194  pmt::pmt_t d_min, d_max, d_def;
1195  std::string d_units, d_desc;
1196  priv_lvl_t d_minpriv;
1197  DisplayType d_display;
1198  T *d_object;
1199 };
1200 
1201 
1202 
1203 /*********************************************************************
1204  * RPC Register Variable Classes
1205  ********************************************************************/
1206 
1207 /*!
1208  * \brief Registers a read-only function to get a parameter over ControlPort.
1209  *
1210  * \details
1211  *
1212  * This class allows us to remotely get a value or parameter of the
1213  * block over ControlPort. Unlike the rpcbasic_register_get class,
1214  * this version is passed the variable directly and establishes a
1215  * getter for us, so there is no need to have a getter function
1216  * already in the object.
1217  *
1218  * This version is for read-only get access.
1219  *
1220  * We can set the (expected) minimum (\p min), maximum (\p max), and
1221  * default (\p def) of the variables we will get. These values are not
1222  * enforced, however, but can be useful for setting up graphs and
1223  * other ways of bounding the data.
1224  *
1225  * This class also allows us to provide information to the user about
1226  * the variable, such as an appropriate unit (\p units_) as well as a
1227  * description (\p desc_) about what the variable does.
1228  *
1229  * The privilege (\p minpriv_) level is the minimum privilege level a
1230  * remote must identify with to be able to call this function.
1231  *
1232  * We also provide display hints (\p display_), which can be used by
1233  * the ControlPort client application to know how to best display or
1234  * even print the data. This is a mask of options for variables set in
1235  * rpccallbackregister_base.h. The mask is defined by one of the
1236  * "DisplayType Plotting Types" and or'd with any of the "DisplayType
1237  * Options" features. See "Display Options" in \ref page_ctrlport for
1238  * details.
1239  */
1240 template<typename Tfrom>
1242  : public rpcbasic_base
1243 {
1244 protected:
1246  Tfrom *d_variable;
1247  Tfrom get() { return *d_variable; }
1248 
1249 public:
1250 
1251  void setptr(Tfrom* _variable)
1252  {
1254  }
1255 
1256  /*! Empty constructor which should never be called but needs to
1257  * exist for ues in varous STL data structures
1258  */
1260  d_rpc_reg("FAIL", "FAIL", this, &rpcbasic_register_variable::get,
1262  "FAIL", "FAIL", RPC_PRIVLVL_MIN),
1263  d_variable(NULL)
1264  {
1265  throw std::runtime_error("ERROR: rpcbasic_register_variable called with no args. If this happens, someone has tried to use rpcbasic_register_variable incorrectly.");
1266  };
1267 
1268  /*!
1269  * \brief Adds the ability to get the variable over ControlPort.
1270  *
1271  * \details
1272  *
1273  * Creates a new getter accessor function to read \p variable.
1274  *
1275  * \param namebase Name of the object being set up for ControlPort access
1276  * \param functionbase The name of the function that we'll access over ControlPort
1277  * \param variable A pointer to the variable, possibly as a member of a class
1278  * \param min Expected minimum value the parameter can hold
1279  * \param max Expected maximum value the parameter can hold
1280  * \param def Expected default value the parameter can hold
1281  * \param units_ A string to describe what units to represent the variable with
1282  * \param desc_ A string to describing the variable.
1283  * \param minpriv_ The required minimum privilege level
1284  * \param display_ The display mask
1285  */
1286  rpcbasic_register_variable(const std::string& namebase,
1287  const char* functionbase,
1288  Tfrom *variable,
1289  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
1290  const char* units_ = "",
1291  const char* desc_ = "",
1292  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
1293  DisplayType display_ = DISPNULL) :
1294  d_rpc_reg(namebase, functionbase, this, &rpcbasic_register_variable::get,
1295  min, max, def, units_, desc_, minpriv_, display_),
1296  d_variable(variable)
1297  {
1298  //std::cerr << "REGISTERING VAR: " << " " << desc_ << std::endl;
1299  }
1300 };
1301 
1302 
1303 /*!
1304  * \brief Registers a read/write function to get and set a parameter
1305  * over ControlPort.
1306  *
1307  * \details
1308  *
1309  * This class allows us to remotely get and/or set a value or
1310  * parameter of the block over ControlPort. Unlike the
1311  * rpcbasic_register_get class, this version is passed the variable
1312  * directly and establishes a getter for us, so there is no need to
1313  * have a getter function already in the object.
1314  *
1315  * This version establishes both get and set functions and so provides
1316  * read/write access to the variable.
1317  *
1318  * We can set the (expected) minimum (\p min), maximum (\p max), and
1319  * default (\p def) of the variables we will get. These values are not
1320  * enforced, however, but can be useful for setting up graphs and
1321  * other ways of bounding the data.
1322  *
1323  * This class also allows us to provide information to the user about
1324  * the variable, such as an appropriate unit (\p units_) as well as a
1325  * description (\p desc_) about what the variable does.
1326  *
1327  * The privilege (\p minpriv_) level is the minimum privilege level a
1328  * remote must identify with to be able to call this function.
1329  *
1330  * We also provide display hints (\p display_), which can be used by
1331  * the ControlPort client application to know how to best display or
1332  * even print the data. This is a mask of options for variables set in
1333  * rpccallbackregister_base.h. The mask is defined by one of the
1334  * "DisplayType Plotting Types" and or'd with any of the "DisplayType
1335  * Options" features. See "Display Options" in \ref page_ctrlport for
1336  * details.
1337  */
1338 template<typename Tfrom>
1340  : public rpcbasic_register_variable<Tfrom>
1341 {
1342 private:
1344 
1345 public:
1346  /*! Empty constructor which should never be called but needs to
1347  * exist for ues in varous STL data structures.
1348  */
1350  d_rpc_regset("FAIL", "FAIL", this,
1353  DISPNULL, "FAIL", "FAIL", RPC_PRIVLVL_MIN)
1354  {
1355  throw std::runtime_error("ERROR: rpcbasic_register_variable_rw called with no args. if this happens someone used rpcbasic_register_variable_rw incorrectly.\n");
1356  };
1357 
1358  void set(Tfrom _variable)
1359  {
1361  }
1362 
1363  /*!
1364  * \brief Adds the ability to set and get the variable over ControlPort.
1365  *
1366  * \details
1367  *
1368  * Creates new getter and setter accessor functions to read and write \p variable.
1369  *
1370  * \param namebase Name of the object being set up for ControlPort access
1371  * \param functionbase The name of the function that we'll access over ControlPort
1372  * \param variable A pointer to the variable, possibly as a member of a class
1373  * \param min Expected minimum value the parameter can hold
1374  * \param max Expected maximum value the parameter can hold
1375  * \param def Expected default value the parameter can hold
1376  * \param units_ A string to describe what units to represent the variable with
1377  * \param desc_ A string to describing the variable.
1378  * \param minpriv The required minimum privilege level
1379  * \param display_ The display mask
1380  */
1382  const std::string& namebase,
1383  const char* functionbase,
1384  Tfrom *variable,
1385  const pmt::pmt_t &min, const pmt::pmt_t &max, const pmt::pmt_t &def,
1386  const char* units_ = "",
1387  const char* desc_ = "",
1388  priv_lvl_t minpriv = RPC_PRIVLVL_MIN,
1389  DisplayType display_=DISPNULL)
1390  : rpcbasic_register_variable<Tfrom>(namebase, functionbase, variable,
1391  min, max, def, units_, desc_),
1392  d_rpc_regset(namebase, functionbase, this,
1394  min, max, def, units_, desc_, minpriv, display_)
1395  {
1396  // no action
1397  }
1398 };
1399 
1400 
1401 /*!
1402  * \brief Registers a message handler function to post a message to a
1403  * block's handler.
1404  */
1405 template<typename T>
1407 {
1408 public:
1409 
1410  /*!
1411  * \brief Adds the ability to pass a message over ControlPort.
1412  *
1413  * \details
1414  * This makes any message handler function avialable over
1415  * ControlPort. Since message handlers always take in a single PMT
1416  * message input, this interface provides a very generic way of
1417  * setting values in a block in a flowgraph.
1418  *
1419  * \param block_alias Alias of the block
1420  * \param handler The name of the message port in the block
1421  * \param units_ A string to describe what units to represent the variable with
1422  * \param desc_ A string to describing the variable.
1423  * \param minpriv_ The required minimum privilege level
1424  * \param display_ The display mask
1425  */
1426  rpcbasic_register_handler(const std::string& block_alias,
1427  const char* handler,
1428  const char* units_ = "",
1429  const char* desc_ = "",
1430  priv_lvl_t minpriv_ = RPC_PRIVLVL_MIN,
1431  DisplayType display_ = DISPNULL)
1432  {
1433  d_units = units_;
1434  d_desc = desc_;
1435  d_minpriv = minpriv_;
1436  d_display = display_;
1437  d_object = dynamic_cast<T*>(global_block_registry.block_lookup(pmt::intern(block_alias)).get());
1438 #ifdef GR_RPCSERVER_ENABLED
1440  inserter(new rpcbasic_handler<T>(d_object, handler),
1441  minpriv_, std::string(units_), display_, std::string(desc_),
1442  0, 0, 0);
1443  std::ostringstream oss(std::ostringstream::out);
1444  oss << block_alias << "::" << handler;
1445  d_id = oss.str();
1446  //std::cerr << "REGISTERING GET: " << d_id << " " << desc_ << std::endl;
1447  rpcmanager::get()->i()->registerHandlerCallback(d_id, inserter);
1448 #endif
1449  }
1450 
1452  {
1453 #ifdef GR_RPCSERVER_ENABLED
1455 #endif
1456  }
1457 
1458  std::string units() const { return d_units; }
1459  std::string description() const { return d_desc; }
1460  priv_lvl_t privilege_level() const { return d_minpriv; }
1461  DisplayType default_display() const { return d_display; }
1462 
1463  void units(std::string u) { d_units = u; }
1464  void description(std::string d) { d_desc = d; }
1465  void privilege_level(priv_lvl_t p) { d_minpriv = p; }
1466  void default_display(DisplayType d) { d_display = d; }
1467 
1468 private:
1469  std::string d_id;
1470  std::string d_units, d_desc;
1471  priv_lvl_t d_minpriv;
1472  DisplayType d_display;
1473  T *d_object;
1474 };
1475 
1476 
1477 
1478 #endif
Definition: rpcregisterhelpers.h:628
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:1245
Definition: rpccallbackregister_base.h:80
~rpcbasic_register_trigger()
Definition: rpcregisterhelpers.h:928
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:513
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:415
Tfrom get()
Definition: rpcregisterhelpers.h:1247
PMT_API pmt_t from_complex(double re, double im)
Return a complex number constructed of the given real and imaginary parts.
~rpchandler_base()
Definition: rpcregisterhelpers.h:162
rpcbasic_inserter(T *source, std::complex< double >(T::*func)())
Definition: rpcregisterhelpers.h:603
T * _source
Definition: rpcregisterhelpers.h:169
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)
Same as above that allows using '[variable]() const' getter functions.
Definition: rpcregisterhelpers.h:1139
rpcbasic_inserter(T *source, std::vector< signed char >(T::*func)())
Definition: rpcregisterhelpers.h:434
PMT_API pmt_t init_s32vector(size_t k, const int32_t *data)
Templated parent class for registering a ControlPort Extractor.
Definition: rpcregisterhelpers.h:178
rpcbasic_register_variable()
Definition: rpcregisterhelpers.h:1259
std::string units() const
Definition: rpcregisterhelpers.h:796
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:538
pmt::pmt_t def() const
Definition: rpcregisterhelpers.h:795
void privilege_level(priv_lvl_t p)
Definition: rpcregisterhelpers.h:1465
void set(Tfrom _variable)
Definition: rpcregisterhelpers.h:1358
PMT_API std::complex< double > to_complex(pmt_t z)
rpcbasic_inserter(T *source, std::vector< int >(T::*func)())
Definition: rpcregisterhelpers.h:484
T * _source
Definition: rpcregisterhelpers.h:116
rpcbasic_register_variable_rw()
Definition: rpcregisterhelpers.h:1349
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:113
std::string units() const
Definition: rpcregisterhelpers.h:1458
rpcbasic_extractor(T *source, void(T::*func)(double))
Definition: rpcregisterhelpers.h:254
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)
Adds the ability to set the variable over ControlPort.
Definition: rpcregisterhelpers.h:701
rpcbasic_extractor(T *source, void(T::*func)(float))
Definition: rpcregisterhelpers.h:272
rpcbasic_inserter(T *source, std::vector< short >(T::*func)() const)
Definition: rpcregisterhelpers.h:455
PMT_API pmt_t init_u8vector(size_t k, const uint8_t *data)
Templated parent class for registering a ControlPort Extractor.
Definition: rpcregisterhelpers.h:89
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:330
rpcbasic_inserter(T *source, std::complex< float >(T::*func)())
Definition: rpcregisterhelpers.h:580
rpcbasic_extractor(T *source, void(T::*func)())
Definition: rpcregisterhelpers.h:201
Tfrom * d_variable
Definition: rpcregisterhelpers.h:1246
void units(std::string u)
Definition: rpcregisterhelpers.h:1463
DisplayType default_display() const
Definition: rpcregisterhelpers.h:1461
Registers a read/write function to get and set a parameter over ControlPort.
Definition: rpcregisterhelpers.h:1339
Base class for registering a ControlPort Handler. Acts as a message acceptor.
Definition: rpcregisterhelpers.h:156
rpcbasic_handler(T *source, const char *handler)
Definition: rpcregisterhelpers.h:181
Base class for registering a ControlPort function.
Definition: rpcregisterhelpers.h:619
rpcbasic_inserter(T *source, std::vector< short >(T::*func)())
Definition: rpcregisterhelpers.h:459
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:388
std::string description() const
Definition: rpcregisterhelpers.h:1459
PMT_API pmt_t init_s8vector(size_t k, const int8_t *data)
void description(std::string d)
Definition: rpcregisterhelpers.h:939
STL namespace.
Virtual base class that produces messages.
Definition: msg_producer.h:35
T * _source
Definition: rpcregisterhelpers.h:63
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:584
rpcbasic_inserter(T *source, std::vector< uint8_t >(T::*func)())
Definition: rpcregisterhelpers.h:557
void(T::* _func)(Tto)
Definition: rpcregisterhelpers.h:64
std::string description() const
Definition: rpcregisterhelpers.h:797
priv_lvl_t
Definition: rpccallbackregister_base.h:46
void default_display(DisplayType d)
Definition: rpcregisterhelpers.h:807
Registers a message handler function to post a message to a block's handler.
Definition: rpcregisterhelpers.h:1406
void description(std::string d)
Definition: rpcregisterhelpers.h:1464
void privilege_level(priv_lvl_t p)
Definition: rpcregisterhelpers.h:1189
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:240
pmt::pmt_t max() const
Definition: rpcregisterhelpers.h:794
void units(std::string u)
Definition: rpcregisterhelpers.h:1187
Base class for registering a ControlPort Inserter. Produces a message.
Definition: rpcregisterhelpers.h:107
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:258
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:58
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:222
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:384
virtual void unregisterConfigureCallback(const std::string &id)=0
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:438
rpcbasic_extractor(T *source, void(T::*func)(Tto))
Definition: rpcregisterhelpers.h:92
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:561
rpcbasic_extractor(T *source, void(T::*func)(char))
Definition: rpcregisterhelpers.h:218
PMT_API const std::string symbol_to_string(const pmt_t &sym)
static int count
Definition: rpcregisterhelpers.h:622
void set_max(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:1185
PMT_API bool to_bool(pmt_t val)
Return true if val is pmt::True, return false when val is pmt::PMT_F,.
rpcbasic_inserter(T *source, uint64_t(T::*func)())
Definition: rpcregisterhelpers.h:411
Definition: rpccallbackregister_base.h:48
Tfrom(T::* _func)()
Definition: rpcregisterhelpers.h:117
rpcbasic_extractor(T *source, void(T::*func)(long))
Definition: rpcregisterhelpers.h:290
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:138
Registers a 'get' function to get a parameter over ControlPort.
Definition: rpcregisterhelpers.h:987
virtual void registerQueryCallback(const std::string &id, const queryCallback_t callback)=0
void privilege_level(priv_lvl_t p)
Definition: rpcregisterhelpers.h:806
Templated parent class for registering a ControlPort Inserter.
Definition: rpcregisterhelpers.h:126
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:488
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)
Adds the ability to set and get the variable over ControlPort.
Definition: rpcregisterhelpers.h:1381
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)
Adds the ability to set the variable over ControlPort.
Definition: rpcregisterhelpers.h:754
virtual ~rpcbasic_base()
Definition: rpcregisterhelpers.h:632
rpcbasic_register_handler(const std::string &block_alias, const char *handler, const char *units_="", const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN, DisplayType display_=DISPNULL)
Adds the ability to pass a message over ControlPort.
Definition: rpcregisterhelpers.h:1426
void set_def(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:1186
~rpcextractor_base()
Definition: rpcregisterhelpers.h:74
priv_lvl_t privilege_level() const
Definition: rpcregisterhelpers.h:1181
rpchandler_base(T *source, const char *handler)
Definition: rpcregisterhelpers.h:160
rpcbasic_extractor(T *source, void(T::*func)(std::complex< double >))
Definition: rpcregisterhelpers.h:365
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:276
std::string description() const
Definition: rpcregisterhelpers.h:936
priv_lvl_t privilege_level() const
Definition: rpcregisterhelpers.h:1460
virtual void unregisterQueryCallback(const std::string &id)=0
priv_lvl_t privilege_level() const
Definition: rpcregisterhelpers.h:937
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)
Adds the ability to get the variable over ControlPort.
Definition: rpcregisterhelpers.h:1286
rpcinserter_base(T *source, Tfrom(T::*func)())
Definition: rpcregisterhelpers.h:110
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)
Adds the ability to get the variable over ControlPort.
Definition: rpcregisterhelpers.h:1104
Base class for registering a ControlPort Extractor. Acts as a message acceptor.
Definition: rpcregisterhelpers.h:50
T * _source
Definition: rpcregisterhelpers.h:81
rpcbasic_extractor(T *source, void(T::*func)(short))
Definition: rpcregisterhelpers.h:236
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)
Adds the ability to get the variable over ControlPort.
Definition: rpcregisterhelpers.h:1017
Virtual base class that accepts messages.
Definition: messages/msg_accepter.h:35
rpcbasic_inserter(T *source, uint64_t(T::*func)() const)
Definition: rpcregisterhelpers.h:407
void default_display(DisplayType d)
Definition: rpcregisterhelpers.h:1466
void set_max(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:802
PMT_API long to_long(pmt_t x)
Convert pmt to long if possible.
~rpcextractor_base()
Definition: rpcregisterhelpers.h:56
virtual rpcserver_base * i()=0
rpcextractor_base(T *source, void(T::*func)(Tto))
Definition: rpcregisterhelpers.h:54
PMT_API double to_double(pmt_t x)
Convert pmt to double if possible.
void setptr(Tfrom *_variable)
Definition: rpcregisterhelpers.h:1251
virtual void unregisterHandlerCallback(const std::string &id)=0
static rpcserver_booter_base * get()
rpcbasic_extractor(T *source, void(T::*func)(std::complex< float >))
Definition: rpcregisterhelpers.h:345
pmt::pmt_t max() const
Definition: rpcregisterhelpers.h:1177
#define PMT_NIL
Definition: pmt.h:103
rpcbasic_inserter(T *source, std::vector< float >(T::*func)())
Definition: rpcregisterhelpers.h:534
~rpcbasic_register_get()
Definition: rpcregisterhelpers.h:1169
pmt::pmt_t min() const
Definition: rpcregisterhelpers.h:1176
rpcbasic_inserter(T *source, std::vector< int >(T::*func)() const)
Definition: rpcregisterhelpers.h:480
Registers a 'trigger' function to trigger an action over ControlPort.
Definition: rpcregisterhelpers.h:844
Registers a read-only function to get a parameter over ControlPort.
Definition: rpcregisterhelpers.h:1241
priv_lvl_t privilege_level() const
Definition: rpcregisterhelpers.h:798
const uint32_t DISPNULL
DisplayType Plotting types.
Definition: rpccallbackregister_base.h:32
rpcbasic_inserter(T *source, std::vector< float >(T::*func)() const)
Definition: rpcregisterhelpers.h:530
rpcextractor_base(T *source, void(T::*func)())
Definition: rpcregisterhelpers.h:72
void set_def(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:803
PMT_API pmt_t init_f32vector(size_t k, const float *data)
DisplayType default_display() const
Definition: rpcregisterhelpers.h:799
pmt::pmt_t def() const
Definition: rpcregisterhelpers.h:1178
rpcbasic_inserter(T *source, std::vector< uint8_t >(T::*func)() const)
Definition: rpcregisterhelpers.h:553
pmt::pmt_t min() const
Definition: rpcregisterhelpers.h:793
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:312
const char * _handler
Definition: rpcregisterhelpers.h:170
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:76
Specialized extractor class to make calls to functions that do not take data (enable, reset, start, etc.).
Definition: rpcregisterhelpers.h:198
virtual void registerHandlerCallback(const std::string &id, const handlerCallback_t callback)=0
rpcinserter_base()
Definition: rpcregisterhelpers.h:111
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:607
PMT_API pmt_t init_c32vector(size_t k, const std::complex< float > *data)
std::string units() const
Definition: rpcregisterhelpers.h:1179
GR_RUNTIME_API gr::block_registry global_block_registry
rpcbasic_inserter(T *source, std::complex< float >(T::*func)() const)
Definition: rpcregisterhelpers.h:576
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)
Same as rpcbasic_register_get::rpcbasic_register_get that allows using '[variable]() const' getter fu...
Definition: rpcregisterhelpers.h:1051
rpcbasic_inserter(T *source, Tfrom(T::*func)())
Definition: rpcregisterhelpers.h:134
void set_min(pmt::pmt_t p)
Definition: rpcregisterhelpers.h:801
rpcbasic_base()
Definition: rpcregisterhelpers.h:631
std::string description() const
Definition: rpcregisterhelpers.h:1180
rpcbasic_register_trigger(const std::string &name, const char *functionbase, T *obj, void(T::*function)(), const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN)
Adds the ability to trigger a function over ControlPort.
Definition: rpcregisterhelpers.h:906
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:294
void units(std::string u)
Definition: rpcregisterhelpers.h:804
~rpcbasic_register_set()
Definition: rpcregisterhelpers.h:785
void default_display(DisplayType d)
Definition: rpcregisterhelpers.h:1190
rpcbasic_inserter(T *source, std::complex< double >(T::*func)() const)
Definition: rpcregisterhelpers.h:599
void description(std::string d)
Definition: rpcregisterhelpers.h:805
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:1184
rpcbasic_register_trigger(const std::string &block_alias, const char *functionbase, void(T::*function)(), const char *desc_="", priv_lvl_t minpriv_=RPC_PRIVLVL_MIN)
Adds the ability to trigger a function over ControlPort.
Definition: rpcregisterhelpers.h:867
rpc_register_base()
Definition: rpcregisterhelpers.h:621
rpcbasic_inserter(T *source, std::vector< std::complex< float > >(T::*func)() const)
Definition: rpcregisterhelpers.h:505
~rpcbasic_register_handler()
Definition: rpcregisterhelpers.h:1451
PMT_API pmt_t init_s16vector(size_t k, const int16_t *data)
rpcbasic_extractor(T *source, void(T::*func)(int))
Definition: rpcregisterhelpers.h:308
rpcbasic_inserter(T *source, Tfrom(T::*func)() const)
Definition: rpcregisterhelpers.h:130
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:349
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:164
basic_block_sptr block_lookup(pmt::pmt_t symbol)
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:205
rpcbasic_inserter(T *source, std::vector< signed char >(T::*func)() const)
Definition: rpcregisterhelpers.h:430
void description(std::string d)
Definition: rpcregisterhelpers.h:1188
pmt::pmt_t retrieve()
send msg to msg_producer
Definition: rpcregisterhelpers.h:463
static pmt_t mp(const std::string &s)
Make pmt symbol.
Definition: pmt_sugar.h:36
Definition: pmt.h:51
rpcbasic_extractor(T *source, void(T::*func)(bool))
Definition: rpcregisterhelpers.h:326
void privilege_level(priv_lvl_t p)
Definition: rpcregisterhelpers.h:940
DisplayType default_display() const
Definition: rpcregisterhelpers.h:1182
void post(pmt::pmt_t which_port, pmt::pmt_t msg)
send msg to msg_accepter on port which_port
Definition: rpcregisterhelpers.h:369
rpcbasic_inserter(T *source, std::vector< std::complex< float > >(T::*func)())
Definition: rpcregisterhelpers.h:509
uint32_t DisplayType
Definition: rpccallbackregister_base.h:29
Registers a 'set' function to set a parameter over ControlPort.
Definition: rpcregisterhelpers.h:673