From 95e0a15010cd425dac10c185260724eb8368d063 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 29 Apr 2010 15:50:57 -0500 Subject: gathdlc: Add from_io constructor --- gatchat/gathdlc.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'gatchat/gathdlc.c') diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c index 48426674..6e71eb43 100644 --- a/gatchat/gathdlc.c +++ b/gatchat/gathdlc.c @@ -171,16 +171,16 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data) ring_buffer_drain(rbuf, pos); } -GAtHDLC *g_at_hdlc_new(GIOChannel *channel) +GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io) { GAtHDLC *hdlc; unsigned char *buf; - if (!channel) + if (io == NULL) return NULL; hdlc = g_try_new0(GAtHDLC, 1); - if (!hdlc) + if (hdlc == NULL) return NULL; hdlc->ref_count = 1; @@ -192,8 +192,6 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel) hdlc->xmit_accm[3] = 0x60000000; /* 0x7d, 0x7e */ hdlc->recv_accm = ~0U; - hdlc->io = g_at_io_new(channel); - hdlc->write_buffer = ring_buffer_new(BUFFER_SIZE * 2); if (!hdlc->write_buffer) goto error; @@ -207,6 +205,7 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel) if (!hdlc->decode_buffer) goto error; + hdlc->io = g_at_io_ref(io); g_at_io_set_read_handler(hdlc->io, new_bytes, hdlc); hdlc->record_fd = -1; @@ -214,9 +213,6 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel) return hdlc; error: - if (hdlc->io) - g_at_io_unref(hdlc->io); - if (hdlc->write_buffer) ring_buffer_free(hdlc->write_buffer); @@ -228,6 +224,21 @@ error: return NULL; } +GAtHDLC *g_at_hdlc_new(GIOChannel *channel) +{ + GAtIO *io; + GAtHDLC *hdlc; + + io = g_at_io_new(channel); + if (io == NULL) + return NULL; + + hdlc = g_at_hdlc_new_from_io(io); + g_at_io_unref(io); + + return hdlc; +} + GAtHDLC *g_at_hdlc_ref(GAtHDLC *hdlc) { if (!hdlc) -- cgit v1.2.3