| 337 | * @since 0.3.0 |
| 338 | */ |
| 339 | SRD_API struct srd_decoder_inst *srd_inst_new(struct srd_session *sess, |
| 340 | const char *decoder_id, GHashTable *options) |
| 341 | { |
| 342 | int i; |
| 343 | struct srd_decoder *dec; |
| 344 | struct srd_decoder_inst *di; |
| 345 | char *inst_id; |
| 346 | PyGILState_STATE gstate; |
| 347 | |
| 348 | i = 1; |
| 349 | |
| 350 | if (!sess) |
| 351 | return NULL; |
| 352 | |
| 353 | if (!(dec = srd_decoder_get_by_id(decoder_id))) { |
| 354 | srd_err("Protocol decoder %s not found.", decoder_id); |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | di = malloc(sizeof(struct srd_decoder_inst)); |
| 359 | if (di == NULL){ |
| 360 | srd_err("%s,ERROR:failed to alloc memory.", __func__); |
| 361 | return NULL; |
| 362 | } |
| 363 | memset(di, 0, sizeof(struct srd_decoder_inst)); |
| 364 | |
| 365 | di->decoder = dec; |
| 366 | di->sess = sess; |
| 367 | |
| 368 | if (options) { |
| 369 | inst_id = g_hash_table_lookup(options, "id"); |
| 370 | if (inst_id) |
| 371 | di->inst_id = g_strdup(inst_id); |
| 372 | g_hash_table_remove(options, "id"); |
| 373 | } |
| 374 | |
| 375 | /* Create a unique instance ID (as none was provided). */ |
| 376 | if (!di->inst_id) { |
| 377 | di->inst_id = g_strdup_printf("%s-%d", decoder_id, i++); |
| 378 | while (srd_inst_find_by_id(sess, di->inst_id)) { |
| 379 | g_free(di->inst_id); |
| 380 | di->inst_id = g_strdup_printf("%s-%d", decoder_id, i++); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | gstate = PyGILState_Ensure(); |
| 385 | |
| 386 | /* |
| 387 | * Prepare a default channel map, where samples come in the |
| 388 | * order in which the decoder class defined them. |
| 389 | */ |
| 390 | di->py_pinvalues = NULL; |
| 391 | di->dec_num_channels = g_slist_length(di->decoder->channels) + |
| 392 | g_slist_length(di->decoder->opt_channels); |
| 393 | |
| 394 | if (di->dec_num_channels > 0) { |
| 395 | di->dec_channelmap = malloc(sizeof(int) * di->dec_num_channels); |
| 396 |
no test coverage detected