13#include <boost/format.hpp>
22template <
class myType>
42template <
class myType>
47 std::string functionbase,
55 d_functionbase(functionbase),
73 myType rVal = d_deflt;
74 if (d_callback == NULL) {
76 <<
"WARNING: pycallback_object get() called without py callback set!"
81 PyGILState_STATE state = PyGILState_Ensure();
87 func = (PyObject*)d_callback;
89 result = PyEval_CallObject(func, NULL);
93 rVal = pyCast(result);
98 PyGILState_Release(state);
110 (boost::format(
"%s%d") % d_name % d_id).str(),
111 d_functionbase.c_str(),
125 PyObject* d_callback;
126 std::string d_functionbase, d_units, d_desc;
127 myType d_min, d_max, d_deflt;
135 myType pyCast(PyObject* obj)
137 std::cerr <<
"TYPE NOT IMPLEMENTED!" << std::endl;
144 std::vector<rpcbasic_sptr> d_rpc_vars;
155#if PY_MAJOR_VERSION >= 3
156 return std::string(PyUnicode_AsUTF8(obj));
158 return std::string(PyString_AsString(obj));
165 return PyFloat_AsDouble(obj);
171 return (
float)PyFloat_AsDouble(obj);
177 return PyInt_AsLong(obj);
183 int size = PyObject_Size(obj);
184 std::vector<float> rval(size);
185 for (
int i = 0; i < size; i++) {
186 rval[i] = (float)PyFloat_AsDouble(PyList_GetItem(obj, i));
194 int size = PyObject_Size(obj);
195 std::vector<gr_complex> rval(size);
196 for (
int i = 0; i < size; i++) {
197 rval[i] =
gr_complex((
float)PyComplex_RealAsDouble(PyList_GetItem(obj, i)),
198 (
float)PyComplex_ImagAsDouble(PyList_GetItem(obj, i)));
Definition: pycallback_object.h:24
static pmt::pmt_t make(myType _val)
Definition: pycallback_object.h:26
Definition: pycallback_object.h:44
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:46
void set_callback(PyObject *cb)
Definition: pycallback_object.h:103
void add_rpc_variable(rpcbasic_sptr s)
Definition: pycallback_object.h:69
void setup_rpc()
Definition: pycallback_object.h:105
myType get()
Definition: pycallback_object.h:71
Registers a 'get' function to get a parameter over ControlPort.
Definition: rpcregisterhelpers.h:1107
std::complex< float > gr_complex
Definition: gr_complex.h:15
float min(float a, float b)
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)
static pmt_t mp(const std::string &s)
Make pmt symbol.
Definition: pmt_sugar.h:24
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84
int pycallback_object_count
Definition: pycallback_object.h:19
pyport_t
Definition: pycallback_object.h:17
@ PYPORT_FLOAT
Definition: pycallback_object.h:17
@ PYPORT_STRING
Definition: pycallback_object.h:17
@ RPC_PRIVLVL_MIN
Definition: rpccallbackregister_base.h:34
uint32_t DisplayType
Definition: rpccallbackregister_base.h:17