From: Daniel Wagner <[email protected]>

---
 elect/device.c |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/elect/device.c b/elect/device.c
index b404546..b4cbbfc 100644
--- a/elect/device.c
+++ b/elect/device.c
@@ -59,6 +59,7 @@ struct elect_device {
        struct ipv4_settings settings;
 
        char *tty;
+       struct elect_dial *dial;
 
        DBusPendingCall *call;
        DBusMessage *pending;
@@ -165,6 +166,27 @@ void __elect_device_foreach(elect_device_foreach_func 
func, void *userdata)
        }
 }
 
+static void settings_changed(struct elect_device *device)
+{
+       DBusConnection *conn = ofono_dbus_get_connection();
+       DBusMessage *signal;
+       DBusMessageIter iter;
+       const char *key = "Settings";
+
+       signal = dbus_message_new_signal(device->elect_path,
+                                       ELECT_DEVICE_INTERFACE,
+                                       "PropertyChanged");
+
+       if (signal == NULL)
+               return;
+       dbus_message_iter_init_append(signal, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
+
+       settings_append(device, &iter);
+
+       g_dbus_send_message(conn, signal);
+}
+
 static DBusMessage *device_get_properties(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -230,6 +252,73 @@ static int bt_disconnect(struct elect_device *device)
        return -EINPROGRESS;
 }
 
+static void disconnect_cb(void *data)
+{
+       DBusConnection *conn = ofono_dbus_get_connection();
+       struct elect_device *device = data;
+
+       DBG("%p", device);
+
+       g_free(device->settings.interface);
+       g_free(device->settings.ip);
+       g_strfreev(device->settings.nameservers);
+       device->settings.interface = NULL;
+       device->settings.ip = NULL;
+       device->settings.nameservers = NULL;
+
+       device->active = FALSE;
+
+       settings_changed(device);
+       ofono_dbus_signal_property_changed(conn, device->elect_path,
+                                       ELECT_DEVICE_INTERFACE, "Active",
+                                       DBUS_TYPE_BOOLEAN, &device->active);
+
+       bt_disconnect(device);
+}
+
+static void connect_cb(const char *interface, const char *ip,
+                       const char *peer, const char *dns1, const char *dns2,
+                       void *data)
+{
+       DBusConnection *conn = ofono_dbus_get_connection();
+       struct elect_device *device = data;
+       const char *dns[3] = { dns1, dns2, 0 };
+
+       DBG("%p", device);
+
+       g_free(device->settings.interface);
+       device->settings.interface = g_strdup(interface);
+       if (device->settings.interface == NULL)
+               goto err;
+
+       g_free(device->settings.ip);
+       device->settings.ip = g_strdup(ip);
+       if (device->settings.ip == NULL)
+               goto err;
+
+       g_strfreev(device->settings.nameservers);
+       device->settings.nameservers = g_strdupv((gchar **)dns);
+       if (device->settings.nameservers == NULL)
+               goto err;
+
+       device->active = TRUE;
+
+       settings_changed(device);
+       ofono_dbus_signal_property_changed(conn, device->elect_path,
+                                       ELECT_DEVICE_INTERFACE, "Active",
+                                       DBUS_TYPE_BOOLEAN, &device->active);
+
+       return;
+
+err:
+       g_free(device->settings.interface);
+       g_free(device->settings.ip);
+       g_strfreev(device->settings.nameservers);
+       device->settings.interface = NULL;
+       device->settings.ip = NULL;
+       device->settings.nameservers = NULL;
+}
+
 static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
 {
        struct elect_device *device = user_data;
@@ -258,6 +347,10 @@ static void bt_connect_reply(DBusPendingCall *call, 
gpointer user_data)
        DBG("%p tty %s", device, tty);
 
        device->tty = g_strdup(tty);
+       if (device->tty == NULL)
+               goto done;
+
+       __elect_dial_connect(device->dial, device->tty);
 
 done:
        dbus_message_unref(reply);
@@ -458,6 +551,10 @@ static int bt_probe(const char *path, const char *dev_addr,
        if (device->name == NULL)
                goto free;
 
+       device->dial = __elect_dial_create(connect_cb, disconnect_cb, device);
+       if (device->dial == NULL)
+               goto free;
+
        g_hash_table_insert(device_hash, g_strdup(path), device);
 
        register_device(device);
@@ -488,6 +585,9 @@ static gboolean bt_remove_device(gpointer key, gpointer 
value,
        if (device->call != NULL)
                dbus_pending_call_cancel(device->call);
 
+       if (device->dial != NULL)
+               __elect_dial_unref(device->dial);
+
        if (prefix && g_str_has_prefix(path, prefix) == FALSE)
                return FALSE;
 
@@ -541,6 +641,9 @@ static void destroy_device(gpointer user)
        if (device->call)
                dbus_pending_call_cancel(device->call);
 
+       if (device->dial)
+               __elect_dial_unref(device->dial);
+
        g_free(device->settings.interface);
        g_free(device->settings.ip);
        g_strfreev(device->settings.nameservers);
-- 
1.7.8.110.g4cb5d1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to