From: Uwe Hermann Date: Sun, 4 Mar 2012 14:08:11 +0000 (+0100) Subject: sr: Fix some TODOs, improve comments/docs. X-Git-Tag: libsigrok-0.1.0~67 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0abee5076fd7751bd77d0fee940d617a1a40ea34;p=libsigrok.git sr: Fix some TODOs, improve comments/docs. --- diff --git a/datastore.c b/datastore.c index c7274ed3..96d830b4 100644 --- a/datastore.c +++ b/datastore.c @@ -96,8 +96,7 @@ SR_API int sr_datastore_destroy(struct sr_datastore *ds) g_free(chunk->data); g_slist_free(ds->chunklist); g_free(ds); - - /* TODO: Set ds = NULL? */ + ds = NULL; return SR_OK; } diff --git a/device.c b/device.c index c4ff6ebe..3166ea8e 100644 --- a/device.c +++ b/device.c @@ -55,7 +55,7 @@ static GSList *devs = NULL; * TODO: Error checks? * TODO: Option to only scan for specific devices or device classes. * - * @return SR_OK upon success, SR_ERR upon errors. + * @return SR_OK upon success, SR_ERR_BUG upon internal errors. */ SR_API int sr_dev_scan(void) { @@ -65,7 +65,7 @@ SR_API int sr_dev_scan(void) drivers = sr_driver_list(); if (!drivers[0]) { sr_err("dev: %s: no supported hardware drivers", __func__); - return SR_ERR; /* TODO: More specific error? */ + return SR_ERR_BUG; } /* diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 940dce99..b61a8abc 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -137,12 +137,12 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("alsa: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!(ctx = sdi->priv)) { sr_err("alsa: %s: sdi->priv was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } // TODO: Return values of snd_*? diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 6527b003..475da6ca 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -711,12 +711,12 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("sigma: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!(ctx = sdi->priv)) { sr_err("sigma: %s: sdi->priv was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } /* TODO */ diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index da91858f..06de6340 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -551,12 +551,12 @@ static int hw_dev_open(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } sr_dbg("la8: Opening LA8 device (%04x:%04x).", USB_VENDOR_ID, @@ -633,12 +633,12 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } sr_dbg("la8: Closing device."); @@ -767,12 +767,12 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } sr_spew("la8: %s: dev_index %d, hwcap %d", __func__, dev_index, hwcap); @@ -1021,17 +1021,17 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } if (!ctx->ftdic) { sr_err("la8: %s: ctx->ftdic was NULL", __func__); - return SR_ERR_ARG; + return SR_ERR_BUG; } ctx->divcount = samplerate_to_divcount(ctx->cur_samplerate); diff --git a/hardware/common/serial.c b/hardware/common/serial.c index de97496a..cd7002b8 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -190,7 +190,7 @@ SR_PRIV void serial_restore_params(int fd, void *backup) * flowcontrol: 1 = rts/cts, 2 = xon/xoff * parity: 0 = none, 1 = even, 2 = odd */ -SR_PRIV int serial_set_params(int fd, int speed, int bits, int parity, +SR_PRIV int serial_set_params(int fd, int baudrate, int bits, int parity, int stopbits, int flowcontrol) { #ifdef _WIN32 @@ -201,8 +201,7 @@ SR_PRIV int serial_set_params(int fd, int speed, int bits, int parity, return SR_ERR; } - /* TODO: Rename 'speed' to 'baudrate'. */ - switch(speed) { + switch (baudrate) { /* TODO: Support for higher baud rates. */ case 115200: dcb.BaudRate = CBR_115200; @@ -235,7 +234,7 @@ SR_PRIV int serial_set_params(int fd, int speed, int bits, int parity, struct termios term; speed_t baud; - switch (speed) { + switch (baudrate) { case 9600: baud = B9600; break; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index e4361384..98bf4fb0 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -314,7 +314,8 @@ static void samples_generator(uint8_t *buf, uint64_t size, void *data) memset(buf, 0xff, size); break; default: - /* TODO: Error handling. */ + sr_err("demo: %s: unknown pattern %d", __func__, + mydata->sample_generator); break; } } diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index c40285ab..d0834ded 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -377,7 +377,7 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("fx2lafw: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } /* TODO */ diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 1993e073..feb6c7eb 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -593,7 +593,7 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("mso19: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } /* TODO */ diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index a3c65b7c..5d62d901 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -507,7 +507,7 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("ols: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } ctx = sdi->priv; diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index ebe02b06..140af8b9 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -460,7 +460,7 @@ static int hw_dev_close(int dev_index) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("logic: %s: sdi was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_ARG? */ + return SR_ERR_BUG; } /* TODO */ diff --git a/session.c b/session.c index 151d96b1..8687f432 100644 --- a/session.c +++ b/session.c @@ -140,7 +140,7 @@ SR_API int sr_session_dev_add(struct sr_dev *dev) if (!session) { sr_err("session: %s: session was NULL", __func__); - return SR_ERR; /* TODO: SR_ERR_BUG? */ + return SR_ERR_BUG; } if ((ret = dev->driver->dev_open(dev->driver_index)) != SR_OK) { @@ -175,6 +175,7 @@ SR_API int sr_session_datafeed_callback_clear(void) * Add a datafeed callback to the current session. * * @param cb Function to call when a chunk of data is received. + * Must not be NULL. * * @return SR_OK upon success, SR_ERR_BUG if no session exists. */ @@ -185,7 +186,10 @@ SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback_t cb) return SR_ERR_BUG; } - /* TODO: Is 'cb' allowed to be NULL? */ + if (!cb) { + sr_err("session: %s: cb was NULL", __func__); + return SR_ERR_ARG; + } session->datafeed_callbacks = g_slist_append(session->datafeed_callbacks, cb); @@ -259,14 +263,14 @@ SR_API int sr_session_start(void) if (!session) { sr_err("session: %s: session was NULL; a session must be " "created first, before starting it.", __func__); - return SR_ERR; /* TODO: SR_ERR_BUG? */ + return SR_ERR_BUG; } if (!session->devs) { /* TODO: Actually the case? */ sr_err("session: %s: session->devs was NULL; a session " "cannot be started without devices.", __func__); - return SR_ERR; /* TODO: SR_ERR_BUG? */ + return SR_ERR_BUG; } /* TODO: Check driver_index validity? */ @@ -463,8 +467,8 @@ SR_PRIV int sr_session_send(struct sr_dev *dev, * @param fd TODO. * @param events TODO. * @param timeout TODO. - * @param cb TODO. - * @param cb_data TODO. + * @param cb Callback function to add. Must not be NULL. + * @param cb_data Data for the callback function. Can be NULL. * * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or * SR_ERR_MALLOC upon memory allocation errors. @@ -526,7 +530,7 @@ SR_API int sr_session_source_remove(int fd) if (!sources) { sr_err("session: %s: sources was NULL", __func__); - return SR_ERR_BUG; /* TODO: Other? */ + return SR_ERR_BUG; } /* TODO: Check if 'fd' valid. */ diff --git a/session_driver.c b/session_driver.c index a69e404d..9175a1cb 100644 --- a/session_driver.c +++ b/session_driver.c @@ -157,7 +157,6 @@ static int hw_init(const char *devinfo) /** * TODO. - * */ static int hw_cleanup(void) { diff --git a/sigrok-internal.h b/sigrok-internal.h index 06dd35d1..6f148023 100644 --- a/sigrok-internal.h +++ b/sigrok-internal.h @@ -105,7 +105,7 @@ SR_PRIV int serial_write(int fd, const void *buf, size_t count); SR_PRIV int serial_read(int fd, void *buf, size_t count); SR_PRIV void *serial_backup_params(int fd); SR_PRIV void serial_restore_params(int fd, void *backup); -SR_PRIV int serial_set_params(int fd, int speed, int bits, int parity, +SR_PRIV int serial_set_params(int fd, int baudrate, int bits, int parity, int stopbits, int flowcontrol); /*--- hardware/common/ezusb.c -----------------------------------------------*/