use g_source_destroy instead of free on serial object
[fw/altos] / aoview / aoview_serial.c
index 5cb286f88a924c30fb656c32f379f75bf5b1870c..29038b79af6ea747af0da5bd222ed33acb5275ea 100644 (file)
@@ -191,6 +191,7 @@ serial_dispatch(GSource *source,
                gpointer user_data)
 {
        struct aoview_serial *serial = (struct aoview_serial *) source;
                gpointer user_data)
 {
        struct aoview_serial *serial = (struct aoview_serial *) source;
+       aoview_serial_callback func = (aoview_serial_callback) callback;
        gint revents = serial->poll_fd.revents;
 
        if (revents & G_IO_IN)
        gint revents = serial->poll_fd.revents;
 
        if (revents & G_IO_IN)
@@ -199,8 +200,8 @@ serial_dispatch(GSource *source,
        if (revents & G_IO_OUT)
                aoview_buf_flush(&serial->out_buf, serial->fd);
 
        if (revents & G_IO_OUT)
                aoview_buf_flush(&serial->out_buf, serial->fd);
 
-       if (callback && (revents & G_IO_IN))
-               (*callback)(user_data);
+       if (func)
+               (*func)(user_data, serial, revents);
        return TRUE;
 }
 
        return TRUE;
 }
 
@@ -233,7 +234,7 @@ aoview_serial_open(const char *tty)
        aoview_buf_init(&serial->out_buf);
        serial->fd = open (tty, O_RDWR | O_NONBLOCK);
        if (serial->fd < 0) {
        aoview_buf_init(&serial->out_buf);
        serial->fd = open (tty, O_RDWR | O_NONBLOCK);
        if (serial->fd < 0) {
-               free (serial);
+               g_source_destroy(&serial->source);
                return NULL;
        }
        tcgetattr(serial->fd, &termios);
                return NULL;
        }
        tcgetattr(serial->fd, &termios);
@@ -249,6 +250,7 @@ aoview_serial_open(const char *tty)
        serial->poll_fd.events = G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR;
        g_source_attach(&serial->source, NULL);
        g_source_add_poll(&serial->source,&serial->poll_fd);
        serial->poll_fd.events = G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR;
        g_source_attach(&serial->source, NULL);
        g_source_add_poll(&serial->source,&serial->poll_fd);
+       aoview_serial_set_callback(serial, NULL);
        return serial;
 }
 
        return serial;
 }
 
@@ -256,15 +258,13 @@ void
 aoview_serial_close(struct aoview_serial *serial)
 {
        g_source_remove_poll(&serial->source, &serial->poll_fd);
 aoview_serial_close(struct aoview_serial *serial)
 {
        g_source_remove_poll(&serial->source, &serial->poll_fd);
+       close(serial->fd);
        g_source_destroy(&serial->source);
        g_source_destroy(&serial->source);
-       g_source_unref(&serial->source);
 }
 
 void
 aoview_serial_set_callback(struct aoview_serial *serial,
 }
 
 void
 aoview_serial_set_callback(struct aoview_serial *serial,
-                          GSourceFunc func,
-                          gpointer data,
-                          GDestroyNotify notify)
+                          aoview_serial_callback func)
 {
 {
-       g_source_set_callback(&serial->source, func, data, notify);
+       g_source_set_callback(&serial->source, (GSourceFunc) func, serial, NULL);
 }
 }