diff options
author | Denis Kenzior <denkenz@gmail.com> | 2010-04-29 15:50:57 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-04-29 18:49:16 -0500 |
commit | 95e0a15010cd425dac10c185260724eb8368d063 (patch) | |
tree | 6a5b7bc245d36980dbfb866daf817106a62dad58 /gatchat/gathdlc.c | |
parent | 58b37ddb531c4d095962bc9ac3ecf7bd2048a210 (diff) | |
download | ofono-95e0a15010cd425dac10c185260724eb8368d063.tar.bz2 |
gathdlc: Add from_io constructor
Diffstat (limited to 'gatchat/gathdlc.c')
-rw-r--r-- | gatchat/gathdlc.c | 27 |
1 files changed, 19 insertions, 8 deletions
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) |