X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=device.c;h=04d463c13e2a9fe34d85a6fe7cdd4095be9ecae8;hb=29cbfeaf5c6a5e9112a6830a8fe4b584b33daf2a;hp=9985fca987c8e7a209c18e887af8e9c66df029d9;hpb=dd56a9320d3ecb8f9054600f118a219f0de4ec9f;p=libsigrok.git diff --git a/device.c b/device.c index 9985fca9..04d463c1 100644 --- a/device.c +++ b/device.c @@ -25,7 +25,7 @@ extern struct sr_global *global; GSList *devices = NULL; -void device_scan(void) +void sr_device_scan(void) { GSList *plugins, *l; struct sr_device_plugin *plugin; @@ -39,12 +39,12 @@ void device_scan(void) */ for (l = plugins; l; l = l->next) { plugin = l->data; - device_plugin_init(plugin); + sr_device_plugin_init(plugin); } } -int device_plugin_init(struct sr_device_plugin *plugin) +int sr_device_plugin_init(struct sr_device_plugin *plugin) { int num_devices, num_probes, i; @@ -52,34 +52,34 @@ int device_plugin_init(struct sr_device_plugin *plugin) num_devices = plugin->init(NULL); for (i = 0; i < num_devices; i++) { num_probes = (int)plugin->get_device_info(i, SR_DI_NUM_PROBES); - device_new(plugin, i, num_probes); + sr_device_new(plugin, i, num_probes); } return num_devices; } -void device_close_all(void) +void sr_device_close_all(void) { struct sr_device *device; while (devices) { device = devices->data; - if (device->plugin) + if (device->plugin && device->plugin->close) device->plugin->close(device->plugin_index); - device_destroy(device); + sr_device_destroy(device); } } -GSList *device_list(void) +GSList *sr_device_list(void) { if (!devices) - device_scan(); + sr_device_scan(); return devices; } -struct sr_device *device_new(struct sr_device_plugin *plugin, int plugin_index, +struct sr_device *sr_device_new(struct sr_device_plugin *plugin, int plugin_index, int num_probes) { struct sr_device *device; @@ -91,12 +91,12 @@ struct sr_device *device_new(struct sr_device_plugin *plugin, int plugin_index, devices = g_slist_append(devices, device); for (i = 0; i < num_probes; i++) - device_probe_add(device, NULL); + sr_device_probe_add(device, NULL); return device; } -void device_clear(struct sr_device *device) +void sr_device_clear(struct sr_device *device) { unsigned int pnum; @@ -106,10 +106,10 @@ void device_clear(struct sr_device *device) return; for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) - device_probe_clear(device, pnum); + sr_device_probe_clear(device, pnum); } -void device_destroy(struct sr_device *device) +void sr_device_destroy(struct sr_device *device) { unsigned int pnum; @@ -121,17 +121,17 @@ void device_destroy(struct sr_device *device) devices = g_slist_remove(devices, device); if (device->probes) { for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) - device_probe_clear(device, pnum); + sr_device_probe_clear(device, pnum); g_slist_free(device->probes); } g_free(device); } -void device_probe_clear(struct sr_device *device, int probenum) +void sr_device_probe_clear(struct sr_device *device, int probenum) { - struct probe *p; + struct sr_probe *p; - p = probe_find(device, probenum); + p = sr_device_probe_find(device, probenum); if (!p) return; @@ -146,14 +146,14 @@ void device_probe_clear(struct sr_device *device, int probenum) } } -void device_probe_add(struct sr_device *device, char *name) +void sr_device_probe_add(struct sr_device *device, char *name) { - struct probe *p; + struct sr_probe *p; char probename[16]; int probenum; probenum = g_slist_length(device->probes) + 1; - p = g_malloc0(sizeof(struct probe)); + p = g_malloc0(sizeof(struct sr_probe)); p->index = probenum; p->enabled = TRUE; if (name) { @@ -166,10 +166,10 @@ void device_probe_add(struct sr_device *device, char *name) device->probes = g_slist_append(device->probes, p); } -struct probe *probe_find(struct sr_device *device, int probenum) +struct sr_probe *sr_device_probe_find(struct sr_device *device, int probenum) { GSList *l; - struct probe *p, *found_probe; + struct sr_probe *p, *found_probe; found_probe = NULL; for (l = device->probes; l; l = l->next) { @@ -184,11 +184,11 @@ struct probe *probe_find(struct sr_device *device, int probenum) } /* TODO: return SIGROK_ERR if probenum not found */ -void device_probe_name(struct sr_device *device, int probenum, char *name) +void sr_device_probe_name(struct sr_device *device, int probenum, char *name) { - struct probe *p; + struct sr_probe *p; - p = probe_find(device, probenum); + p = sr_device_probe_find(device, probenum); if (!p) return; @@ -198,16 +198,16 @@ void device_probe_name(struct sr_device *device, int probenum, char *name) } /* TODO: return SIGROK_ERR if probenum not found */ -void device_trigger_clear(struct sr_device *device) +void sr_device_trigger_clear(struct sr_device *device) { - struct probe *p; + struct sr_probe *p; unsigned int pnum; if (!device->probes) return; for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) { - p = probe_find(device, pnum); + p = sr_device_probe_find(device, pnum); if (p && p->trigger) { g_free(p->trigger); p->trigger = NULL; @@ -216,11 +216,11 @@ void device_trigger_clear(struct sr_device *device) } /* TODO: return SIGROK_ERR if probenum not found */ -void device_trigger_set(struct sr_device *device, int probenum, char *trigger) +void sr_device_trigger_set(struct sr_device *device, int probenum, char *trigger) { - struct probe *p; + struct sr_probe *p; - p = probe_find(device, probenum); + p = sr_device_probe_find(device, probenum); if (!p) return; @@ -231,10 +231,13 @@ void device_trigger_set(struct sr_device *device, int probenum, char *trigger) } -gboolean device_has_hwcap(struct sr_device *device, int hwcap) +gboolean sr_device_has_hwcap(struct sr_device *device, int hwcap) { int *capabilities, i; + if (!device || !device->plugin) + return; + if ((capabilities = device->plugin->get_capabilities())) for (i = 0; capabilities[i]; i++) if (capabilities[i] == hwcap)