[PATCH 2/6] shared/hfp: Extract creation hfp to separate function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This code is going to be common between gw and hf.
---
 src/shared/hfp.c | 49 ++++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 6176514..16feaf2 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -455,6 +455,33 @@ static bool can_read_data(struct io *io, void *user_data)
 	return true;
 }
 
+static bool hfp_create(struct hfp *hfp, int fd)
+{
+	hfp->fd = fd;
+	hfp->close_on_unref = false;
+
+	hfp->read_buf = ringbuf_new(4096);
+	if (!hfp->read_buf)
+		return false;
+
+	hfp->write_buf = ringbuf_new(4096);
+	if (!hfp->write_buf) {
+		ringbuf_free(hfp->read_buf);
+		return false;
+	}
+
+	hfp->io = io_new(fd);
+	if (!hfp->io) {
+		ringbuf_free(hfp->write_buf);
+		ringbuf_free(hfp->read_buf);
+		return false;
+	}
+
+	hfp->writer_active = false;
+
+	return true;
+}
+
 struct hfp_gw *hfp_gw_new(int fd)
 {
 	struct hfp_gw *hfp;
@@ -466,26 +493,7 @@ struct hfp_gw *hfp_gw_new(int fd)
 	if (!hfp)
 		return NULL;
 
-	hfp->hfp.fd = fd;
-	hfp->hfp.close_on_unref = false;
-
-	hfp->hfp.read_buf = ringbuf_new(4096);
-	if (!hfp->hfp.read_buf) {
-		free(hfp);
-		return NULL;
-	}
-
-	hfp->hfp.write_buf = ringbuf_new(4096);
-	if (!hfp->hfp.write_buf) {
-		ringbuf_free(hfp->hfp.read_buf);
-		free(hfp);
-		return NULL;
-	}
-
-	hfp->hfp.io = io_new(fd);
-	if (!hfp->hfp.io) {
-		ringbuf_free(hfp->hfp.write_buf);
-		ringbuf_free(hfp->hfp.read_buf);
+	if (!hfp_create(&hfp->hfp, fd)) {
 		free(hfp);
 		return NULL;
 	}
@@ -510,7 +518,6 @@ struct hfp_gw *hfp_gw_new(int fd)
 		return NULL;
 	}
 
-	hfp->hfp.writer_active = false;
 	hfp->result_pending = false;
 
 	return hfp_gw_ref(hfp);
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux