[Pdbg] [PATCH v2 18/24] libsbefifo: Add connect api to use custom transport
Amitay Isaacs
amitay at ozlabs.org
Thu Nov 7 13:28:02 AEDT 2019
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libsbefifo/connect.c | 20 ++++++++++++++++++++
libsbefifo/libsbefifo.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/libsbefifo/connect.c b/libsbefifo/connect.c
index 08194e1..1295dc5 100644
--- a/libsbefifo/connect.c
+++ b/libsbefifo/connect.c
@@ -53,6 +53,26 @@ int sbefifo_connect(const char *fifo_path, struct sbefifo_context **out)
return 0;
}
+int sbefifo_connect_transport(sbefifo_transport_fn transport, void *priv, struct sbefifo_context **out)
+{
+ struct sbefifo_context *sctx;
+
+ sctx = malloc(sizeof(struct sbefifo_context));
+ if (!sctx) {
+ fprintf(stderr, "Memory allocation error\n");
+ return ENOMEM;
+ }
+
+ *sctx = (struct sbefifo_context) {
+ .fd = -1,
+ .transport = transport,
+ .priv = priv,
+ };
+
+ *out = sctx;
+ return 0;
+}
+
void sbefifo_disconnect(struct sbefifo_context *sctx)
{
if (sctx->fd != -1)
diff --git a/libsbefifo/libsbefifo.h b/libsbefifo/libsbefifo.h
index 7989b21..5a0f745 100644
--- a/libsbefifo/libsbefifo.h
+++ b/libsbefifo/libsbefifo.h
@@ -55,6 +55,7 @@ typedef int (*sbefifo_transport_fn)(uint8_t *msg, uint32_t msg_len,
void *private_data);
int sbefifo_connect(const char *fifo_path, struct sbefifo_context **out);
+int sbefifo_connect_transport(sbefifo_transport_fn transport, void *priv, struct sbefifo_context **out);
void sbefifo_disconnect(struct sbefifo_context *sctx);
int sbefifo_parse_output(struct sbefifo_context *sctx, uint32_t cmd,
--
2.21.0
More information about the Pdbg
mailing list