25 #include <boost/format.hpp> 33 template <
class myType>
53 template <
class myType>
58 std::string functionbase,
66 d_functionbase(functionbase),
84 myType rVal = d_deflt;
85 if (d_callback == NULL) {
86 printf(
"WARNING: pycallback_object get() called without py callback set!\n");
90 PyGILState_STATE state = PyGILState_Ensure();
96 func = (PyObject*)d_callback;
98 result = PyEval_CallObject(func, NULL);
102 rVal = pyCast(result);
107 PyGILState_Release(state);
119 (boost::format(
"%s%d") % d_name % d_id).str(),
120 d_functionbase.c_str(),
134 PyObject* d_callback;
135 std::string d_functionbase, d_units, d_desc;
136 myType d_min, d_max, d_deflt;
144 myType pyCast(PyObject* obj)
146 printf(
"TYPE NOT IMPLEMENTED!\n");
153 std::vector<rpcbasic_sptr> d_rpc_vars;
164 return std::string(PyString_AsString(obj));
170 return PyFloat_AsDouble(obj);
176 return (
float)PyFloat_AsDouble(obj);
182 return PyInt_AsLong(obj);
188 int size = PyObject_Size(obj);
189 std::vector<float> rval(size);
190 for (
int i = 0; i < size; i++) {
191 rval[i] = (float)PyFloat_AsDouble(PyList_GetItem(obj, i));
199 int size = PyObject_Size(obj);
200 std::vector<gr_complex> rval(size);
201 for (
int i = 0; i < size; i++) {
202 rval[i] =
gr_complex((
float)PyComplex_RealAsDouble(PyList_GetItem(obj, i)),
203 (
float)PyComplex_ImagAsDouble(PyList_GetItem(obj, i)));
Definition: pycallback_object.h:28
boost::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:96
pycallback_object(std::string name, std::string functionbase, std::string units, std::string desc, myType min, myType max, myType deflt, DisplayType dtype)
Definition: pycallback_object.h:57
float min(float a, float b)
int pycallback_object_count
Definition: pycallback_object.h:30
void setup_rpc()
Definition: pycallback_object.h:114
static pmt::pmt_t make(myType _val)
Definition: pycallback_object.h:37
pyport_t
Definition: pycallback_object.h:28
Definition: rpccallbackregister_base.h:46
Definition: pycallback_object.h:54
Registers a 'get' function to get a parameter over ControlPort.
Definition: rpcregisterhelpers.h:1117
std::complex< float > gr_complex
Definition: gr_complex.h:27
void set_callback(PyObject *cb)
Definition: pycallback_object.h:112
PMT_API pmt_t init_f32vector(size_t k, const float *data)
PMT_API pmt_t init_c32vector(size_t k, const std::complex< float > *data)
Definition: pycallback_object.h:28
void add_rpc_variable(rpcbasic_sptr s)
Definition: pycallback_object.h:80
Definition: pycallback_object.h:34
static pmt_t mp(const std::string &s)
Make pmt symbol.
Definition: pmt_sugar.h:35
myType get()
Definition: pycallback_object.h:82
uint32_t DisplayType
Definition: rpccallbackregister_base.h:29