MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / srd_inst_new

Function srd_inst_new

libsigrokdecode4DSL/instance.c:339–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337 * @since 0.3.0
338 */
339SRD_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

Callers 1

create_decoder_instMethod · 0.85

Calls 5

srd_decoder_get_by_idFunction · 0.85
srd_inst_find_by_idFunction · 0.85
oldpins_array_seedFunction · 0.85
srd_exception_catchFunction · 0.85
srd_inst_option_setFunction · 0.85

Tested by

no test coverage detected