X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hwplugin.c;h=cd8fad13e9cbfde819a56da97bb2204f9eafec8d;hb=7a6ec0c376cec9e41a12a876edea34fecaf5c2aa;hp=412cf2d68ab5b34e22f70a36543b61d75afd13a6;hpb=b08024a8363c7a019bebc05a25e2689e774326e8;p=libsigrok.git diff --git a/hwplugin.c b/hwplugin.c index 412cf2d6..cd8fad13 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_BOOL, "Run Length Encoding", "rle"}, {0, 0, NULL, NULL}, }; @@ -107,20 +108,48 @@ 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 = GPOINTER_TO_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 +188,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 @@ -185,7 +218,7 @@ struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus, void sr_usb_device_instance_free(struct sr_usb_device_instance *usb) { /* Avoid compiler warnings. */ - usb = usb; + (void)usb; /* Nothing to do for this device instance type. */ }