From: "Gustavo F. Padovan" <padovan(a)profusion.mobi>
data is now passed from one side to another
---
plugins/sap.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/plugins/sap.c b/plugins/sap.c
index 90e2a03..678addc 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -54,7 +54,9 @@ struct sap_data {
char *server_path;
struct ofono_modem *hw_modem;
GIOChannel *bt_io;
+ GIOChannel *hw_io;
guint bt_watch;
+ guint hw_watch;
};
int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
@@ -106,7 +108,7 @@ static gboolean bt_event_cb(GIOChannel *bt_io, GIOCondition
condition,
if (condition & G_IO_IN) {
GIOStatus status;
- gsize bytes_read;
+ gsize bytes_read, bytes_written;
gchar buf[300];
status = g_io_channel_read_chars(bt_io, buf, 300,
@@ -129,6 +131,37 @@ static gboolean bt_event_cb(GIOChannel *bt_io, GIOCondition
condition,
return FALSE;
}
+static gboolean hw_event_cb(GIOChannel *hw_io, GIOCondition condition,
+ gpointer data)
+{
+ struct ofono_modem *modem = data;
+ struct sap_data *sap_data = ofono_modem_get_data(modem);
+
+ if (condition & G_IO_IN) {
+ GIOStatus status;
+ gsize bytes_read, bytes_written;
+ gchar buf[300];
+
+ status = g_io_channel_read_chars(hw_io, buf, 300,
+ &bytes_read, NULL);
+
+ if (bytes_read > 0)
+ g_io_channel_write_chars(sap_data->bt_io, buf,
+ bytes_read, &bytes_written, NULL);
+
+ if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
+ return FALSE;
+
+ return TRUE;
+ }
+
+ ofono_modem_set_powered(modem, FALSE);
+
+ sap_data->hw_watch = 0;
+
+ return FALSE;
+}
+
static int sap_probe(struct ofono_modem *modem)
{
DBG("%p", modem);
@@ -154,6 +187,7 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer
user_data)
struct sap_data *data = ofono_modem_get_data(modem);
DBusError derr;
DBusMessage *reply, *msg;
+ struct bluetooth_sap_driver *sap_driver;
int fd;
DBG("");
@@ -204,6 +238,34 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer
user_data)
data->bt_watch = g_io_add_watch(data->bt_io, G_IO_HUP | G_IO_ERR
| G_IO_NVAL | G_IO_IN, bt_event_cb, modem);
+ sap_driver = g_hash_table_lookup(sap_hw_hash, data->hw_modem);
+ if (!sap_driver)
+ return;
+
+ fd = sap_driver->open(data->hw_modem);
+ if (!fd) {
+ g_io_channel_unref(data->bt_io);
+ return;
+ }
+
+ data->hw_io = g_io_channel_unix_new(fd);
+ if (data->hw_io == NULL) {
+ g_io_channel_unref(data->bt_io);
+ close(fd);
+ return;
+ }
+
+ g_io_channel_set_encoding(data->hw_io, NULL, NULL);
+ g_io_channel_set_buffered(data->hw_io, FALSE);
+ g_io_channel_set_close_on_unref(data->hw_io, TRUE);
+
+ data->hw_watch = g_io_add_watch(data->hw_io, G_IO_HUP | G_IO_ERR
+ | G_IO_NVAL | G_IO_IN, hw_event_cb, modem);
+
+ sap_driver->enable(data->hw_modem);
+
+ ofono_modem_set_powered(modem, TRUE);
+
done:
dbus_message_unref(reply);
}
--
1.7.6.1