- /*
- * Fix order numbers for the optional channels.
- *
- * Example:
- * Required channels: r1, r2, r3. Optional: o1, o2, o3, o4.
- * 'order' fields in the d->channels list = 0, 1, 2.
- * 'order' fields in the d->opt_channels list = 3, 4, 5, 6.
- */
- for (l = d->opt_channels; l; l = l->next) {
- pdch = l->data;
- pdch->order += g_slist_length(d->channels);
- }
-
- /* Convert annotation class attribute to GSList of char **. */
- d->annotations = NULL;
- if (PyObject_HasAttrString(d->py_dec, "annotations")) {
- py_annlist = PyObject_GetAttrString(d->py_dec, "annotations");
- if (!PyTuple_Check(py_annlist)) {
- srd_err("Protocol decoder %s annotations should "
- "be a tuple.", module_name);
- goto err_out;
- }
- for (i = 0; i < PyTuple_Size(py_annlist); i++) {
- py_ann = PyTuple_GetItem(py_annlist, i);
- if (!PyTuple_Check(py_ann) || PyTuple_Size(py_ann) != 2) {
- srd_err("Protocol decoder %s annotation %d should "
- "be a tuple with two elements.", module_name, i + 1);
- goto err_out;
- }
-
- if (py_strseq_to_char(py_ann, &ann) != SRD_OK) {
- goto err_out;
- }
- d->annotations = g_slist_append(d->annotations, ann);
- }
- }
-
- /* Convert annotation_rows to GSList of 'struct srd_decoder_annotation_row'. */
- d->annotation_rows = NULL;
- if (PyObject_HasAttrString(d->py_dec, "annotation_rows")) {
- py_ann_rows = PyObject_GetAttrString(d->py_dec, "annotation_rows");
- if (!PyTuple_Check(py_ann_rows)) {
- srd_err("Protocol decoder %s annotation row list "
- "must be a tuple.", module_name);
- goto err_out;
- }
- for (i = 0; i < PyTuple_Size(py_ann_rows); i++) {
- py_ann_row = PyTuple_GetItem(py_ann_rows, i);
- if (!PyTuple_Check(py_ann_row)) {
- srd_err("Protocol decoder %s annotation rows "
- "must be tuples.", module_name);
- goto err_out;
- }
- if (PyTuple_Size(py_ann_row) != 3
- || !PyUnicode_Check(PyTuple_GetItem(py_ann_row, 0))
- || !PyUnicode_Check(PyTuple_GetItem(py_ann_row, 1))
- || !PyTuple_Check(PyTuple_GetItem(py_ann_row, 2))) {
- srd_err("Protocol decoder %s annotation rows "
- "must contain tuples containing two "
- "strings and a tuple.", module_name);
- goto err_out;
- }
-
- if (py_str_as_str(PyTuple_GetItem(py_ann_row, 0), &ann_row_id) != SRD_OK)
- goto err_out;
-
- if (py_str_as_str(PyTuple_GetItem(py_ann_row, 1), &ann_row_desc) != SRD_OK)
- goto err_out;
-
- py_ann_classes = PyTuple_GetItem(py_ann_row, 2);
- ann_classes = NULL;
- for (j = 0; j < PyTuple_Size(py_ann_classes); j++) {
- py_long = PyTuple_GetItem(py_ann_classes, j);
- if (!PyLong_Check(py_long)) {
- srd_err("Protocol decoder %s annotation row class "
- "list must only contain numbers.", module_name);
- goto err_out;
- }
- ann_classes = g_slist_append(ann_classes,
- GINT_TO_POINTER(PyLong_AsLong(py_long)));
- }
-
- ann_row = g_malloc0(sizeof(struct srd_decoder_annotation_row));
- ann_row->id = ann_row_id;
- ann_row->desc = ann_row_desc;
- ann_row->ann_classes = ann_classes;
- d->annotation_rows = g_slist_append(d->annotation_rows, ann_row);
- }
- }