X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hwplugin.c;h=f3401dc784ec9a3b9e8c9d70a382e358e4e30871;hb=baf1d71477ea5c1dea449bc9ce72b39d02751934;hp=412cf2d68ab5b34e22f70a36543b61d75afd13a6;hpb=b08024a8363c7a019bebc05a25e2689e774326e8;p=libsigrok.git diff --git a/hwplugin.c b/hwplugin.c index 412cf2d6..f3401dc7 100644 --- a/hwplugin.c +++ b/hwplugin.c @@ -39,6 +39,7 @@ struct sr_hwcap_option sr_hwcap_options[] = { {SR_HWCAP_SAMPLERATE, SR_T_UINT64, "Sample rate", "samplerate"}, {SR_HWCAP_CAPTURE_RATIO, SR_T_UINT64, "Pre-trigger capture ratio", "captureratio"}, {SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "patternmode"}, + {SR_HWCAP_RLE, SR_T_CHAR, "Run Length Encoding", "rle"}, {0, 0, NULL, NULL}, }; @@ -107,20 +108,47 @@ GSList *sr_list_hwplugins(void) return plugins; } +int sr_init_hwplugins(struct sr_device_plugin *plugin) +{ + int num_devices, num_probes, i; + + g_message("initializing %s plugin", plugin->name); + num_devices = plugin->init(NULL); + for (i = 0; i < num_devices; i++) { + num_probes = (int)plugin->get_device_info(i, SR_DI_NUM_PROBES); + sr_device_new(plugin, i, num_probes); + } + + return num_devices; +} + +void sr_cleanup_hwplugins(void) +{ + struct sr_device_plugin *plugin; + GSList *l; + + for (l = plugins; l; l = l->next) { + plugin = l->data; + if (plugin->cleanup) + plugin->cleanup(); + } + +} + struct sr_device_instance *sr_device_instance_new(int index, int status, const char *vendor, const char *model, const char *version) { struct sr_device_instance *sdi; - if (!(sdi = malloc(sizeof(struct sr_device_instance)))) + if (!(sdi = g_malloc(sizeof(struct sr_device_instance)))) return NULL; sdi->index = index; sdi->status = status; sdi->instance_type = -1; - sdi->vendor = vendor ? strdup(vendor) : NULL; - sdi->model = model ? strdup(model) : strdup("(unknown)"); - sdi->version = version ? strdup(version) : NULL; + sdi->vendor = vendor ? g_strdup(vendor) : NULL; + sdi->model = model ? g_strdup(model) : NULL; + sdi->version = version ? g_strdup(version) : NULL; sdi->priv = NULL; sdi->usb = NULL; @@ -159,10 +187,14 @@ void sr_device_instance_free(struct sr_device_instance *sdi) break; } - free(sdi->vendor); - free(sdi->model); - free(sdi->version); - free(sdi); + if (sdi->priv) + g_free(sdi->priv); + + g_free(sdi->vendor); + g_free(sdi->model); + g_free(sdi->version); + g_free(sdi); + } #ifdef HAVE_LIBUSB_1_0