]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_tcp.c
scpi: Pass SCPI device instance to open and close callbacks.
[libsigrok.git] / src / scpi / scpi_tcp.c
index 7b3c9155d2026e99472365215f8cf9da1510312d..62974680aa93bdc99b321c5daeff5196af842134 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #ifdef _WIN32
 #define _WIN32_WINNT 0x0501
 #include <winsock2.h>
@@ -32,8 +33,9 @@
 #include <netdb.h>
 #endif
 #include <errno.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
+#include "scpi.h"
 
 #define LOG_PREFIX "scpi_tcp"
 
@@ -70,9 +72,9 @@ static int scpi_tcp_dev_inst_new(void *priv, struct drv_context *drvc,
        return SR_OK;
 }
 
-static int scpi_tcp_open(void *priv)
+static int scpi_tcp_open(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_tcp *tcp = priv;
+       struct scpi_tcp *tcp = scpi->priv;
        struct addrinfo hints;
        struct addrinfo *results, *res;
        int err;
@@ -85,7 +87,7 @@ static int scpi_tcp_open(void *priv)
        err = getaddrinfo(tcp->address, tcp->port, &hints, &results);
 
        if (err) {
-               sr_err("Address lookup failed: %s:%d: %s", tcp->address, tcp->port,
+               sr_err("Address lookup failed: %s:%s: %s", tcp->address, tcp->port,
                        gai_strerror(err));
                return SR_ERR;
        }
@@ -106,7 +108,7 @@ static int scpi_tcp_open(void *priv)
 
        if (tcp->socket < 0) {
                sr_err("Failed to connect to %s:%s: %s", tcp->address, tcp->port,
-                               strerror(errno));
+                               g_strerror(errno));
                return SR_ERR;
        }
 
@@ -141,7 +143,7 @@ static int scpi_tcp_send(void *priv, const char *command)
        g_free(terminated_command);
 
        if (out < 0) {
-               sr_err("Send error: %s", strerror(errno));
+               sr_err("Send error: %s", g_strerror(errno));
                return SR_ERR;
        }
 
@@ -173,7 +175,7 @@ static int scpi_tcp_raw_read_data(void *priv, char *buf, int maxlen)
        len = recv(tcp->socket, buf, maxlen, 0);
 
        if (len < 0) {
-               sr_err("Receive error: %s", strerror(errno));
+               sr_err("Receive error: %s", g_strerror(errno));
                return SR_ERR;
        }
 
@@ -193,7 +195,7 @@ static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen)
                len = recv(tcp->socket, tcp->length_buf + tcp->length_bytes_read,
                                LENGTH_BYTES - tcp->length_bytes_read, 0);
                if (len < 0) {
-                       sr_err("Receive error: %s", strerror(errno));
+                       sr_err("Receive error: %s", g_strerror(errno));
                        return SR_ERR;
                }
 
@@ -211,7 +213,7 @@ static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen)
        len = recv(tcp->socket, buf, maxlen, 0);
 
        if (len < 0) {
-               sr_err("Receive error: %s", strerror(errno));
+               sr_err("Receive error: %s", g_strerror(errno));
                return SR_ERR;
        }
 
@@ -228,9 +230,9 @@ static int scpi_tcp_read_complete(void *priv)
                        tcp->response_bytes_read >= tcp->response_length);
 }
 
-static int scpi_tcp_close(void *priv)
+static int scpi_tcp_close(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_tcp *tcp = priv;
+       struct scpi_tcp *tcp = scpi->priv;
 
        if (close(tcp->socket) < 0)
                return SR_ERR;