X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hwdriver.c;h=82dcb2b3036cf410f72c778e54e1d4a0d23a1fef;hb=787c43905d6f61c08d3b66a4a09dc12038120861;hp=c68d6e0c2167347d68f30283b8f065066f741606;hpb=c30b417f719e20f9f1d29fd8fa72c24278af3a0c;p=libsigrok.git diff --git a/hwdriver.c b/hwdriver.c index c68d6e0c..82dcb2b3 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -34,7 +34,7 @@ SR_API 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_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "pattern"}, {SR_HWCAP_RLE, SR_T_BOOL, "Run Length Encoding", "rle"}, {0, 0, NULL, NULL}, }; @@ -99,14 +99,11 @@ static struct sr_dev_driver *drivers_list[] = { }; /** - * Return the list of loaded hardware drivers. - * - * The list of drivers is initialized from sr_init(), and can only be reset - * by calling sr_exit(). + * Return the list of supported hardware drivers. * * @return Pointer to the NULL-terminated list of hardware driver pointers. */ -SR_API struct sr_dev_driver **sr_hw_list(void) +SR_API struct sr_dev_driver **sr_driver_list(void) { return drivers_list; } @@ -121,7 +118,7 @@ SR_API struct sr_dev_driver **sr_hw_list(void) * * @return The number of devices found and instantiated by the driver. */ -SR_API int sr_hw_init(struct sr_dev_driver *driver) +SR_API int sr_driver_init(struct sr_dev_driver *driver) { int num_devs, num_probes, i, j; int num_initialized_devs = 0; @@ -156,7 +153,7 @@ SR_PRIV void sr_hw_cleanup_all(void) int i; struct sr_dev_driver **drivers; - drivers = sr_hw_list(); + drivers = sr_driver_list(); for (i = 0; drivers[i]; i++) { if (drivers[i]->cleanup) drivers[i]->cleanup(); @@ -264,13 +261,24 @@ SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial) * @param driver The hardware driver in which to search for the capability. * @param hwcap The capability to find in the list. * - * @return TRUE if found, FALSE otherwise. + * @return TRUE if the specified capability exists in the specified driver, + * FALSE otherwise. Also, if 'driver' is NULL or the respective driver + * returns an invalid capability list, FALSE is returned. */ -SR_API gboolean sr_hw_has_hwcap(struct sr_dev_driver *driver, int hwcap) +SR_API gboolean sr_driver_hwcap_exists(struct sr_dev_driver *driver, int hwcap) { int *hwcaps, i; - hwcaps = driver->hwcap_get_all(); + if (!driver) { + sr_err("hwdriver: %s: driver was NULL", __func__); + return FALSE; + } + + if (!(hwcaps = driver->hwcap_get_all())) { + sr_err("hwdriver: %s: hwcap_get_all() returned NULL", __func__); + return FALSE; + } + for (i = 0; hwcaps[i]; i++) { if (hwcaps[i] == hwcap) return TRUE; @@ -299,15 +307,15 @@ SR_API struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap) return NULL; } -/* unnecessary level of indirection follows. */ +/* Unnecessary level of indirection follows. */ -SR_PRIV void sr_source_remove(int fd) +SR_PRIV int sr_source_remove(int fd) { - sr_session_source_remove(fd); + return sr_session_source_remove(fd); } -SR_PRIV void sr_source_add(int fd, int events, int timeout, - sr_receive_data_callback rcv_cb, void *user_data) +SR_PRIV int sr_source_add(int fd, int events, int timeout, + sr_receive_data_callback_t cb, void *cb_data) { - sr_session_source_add(fd, events, timeout, rcv_cb, user_data); + return sr_session_source_add(fd, events, timeout, cb, cb_data); }