+struct srd_decoder_instance *srd_instance_new(const char *id)
+{
+ struct srd_decoder *dec = srd_get_decoder_by_id(id);
+ if (!dec)
+ return NULL;
+ struct srd_decoder_instance *di = g_malloc(sizeof(*di));
+ PyObject *py_args, *py_value;
+
+ /* Create a Python tuple of size 1. */
+ if (!(py_args = PyTuple_New(0))) { /* NEWREF */
+ if (PyErr_Occurred())
+ PyErr_Print(); /* Returns void. */
+
+ return NULL; /* TODO: More specific error? */
+ }
+
+ py_value = Py_BuildValue("{sssisd}",
+ "driver", "demo",
+ "unitsize", _unitsize, //FIXME: Pass in a unitsize that matches the selected LA
+ "starttime", 129318231823.0 //TODO: Fill with something reasonable.
+ );
+
+ /* Create an instance of the Decoder class */
+ di->py_instance = PyObject_Call(dec->py_decobj, py_args, py_value);
+ if (!di->py_instance) {
+ if (PyErr_Occurred())
+ PyErr_Print(); /* Returns void. */
+ Py_XDECREF(py_args);
+ Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
+ return NULL; /* TODO: More specific error? */
+ }
+
+ Py_XDECREF(py_args);
+ Py_XDECREF(py_value);
+
+ return di;
+}
+
+int srd_instance_set_probe(struct srd_decoder_instance *di,
+ const char *probename, int num)
+{
+ PyObject *probedict, *probenum;
+ probedict = PyObject_GetAttrString(di->py_instance, "probes"); /* NEWREF */
+ if (!probedict) {
+ if (PyErr_Occurred())
+ PyErr_Print(); /* Returns void. */
+
+ return SRD_ERR_PYTHON; /* TODO: More specific error? */
+ }
+
+ probenum = PyInt_FromLong(num);
+ PyMapping_SetItemString(probedict, (char*)probename, probenum);
+
+ Py_XDECREF(probenum);
+ Py_XDECREF(probedict);
+ return SRD_OK;
+}
+