From: Marcel Holtmann Date: Mon, 1 Sep 2008 18:07:39 +0000 (+0200) Subject: Fixup due to element API changes X-Git-Tag: 0.1~201 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f4054b0b2d6c43c59caef670b4330895337d992;p=platform%2Fupstream%2Fconnman.git Fixup due to element API changes --- diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index 6d41fb2..2d0d7ad 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -43,7 +43,7 @@ static void create_element(DBusConnection *conn, const char *path) DBG("conn %p path %s", conn, path); - element = connman_element_create(); + element = connman_element_create(NULL); element->name = g_path_get_basename(path); element->type = CONNMAN_ELEMENT_TYPE_DEVICE; diff --git a/plugins/ethernet.c b/plugins/ethernet.c index 0f248bc..697149b 100644 --- a/plugins/ethernet.c +++ b/plugins/ethernet.c @@ -35,6 +35,11 @@ #include #include +struct ethernet_data { + int index; + short flags; +}; + static GStaticMutex ethernet_mutex = G_STATIC_MUTEX_INIT; static GSList *ethernet_list = NULL; @@ -45,11 +50,12 @@ static void create_element(struct connman_element *parent, DBG("parent %p name %s", parent, parent->name); - element = connman_element_create(); + element = connman_element_create(NULL); + if (element == NULL) + return; element->type = type; - element->netdev.index = parent->netdev.index; - element->netdev.name = g_strdup(parent->netdev.name); + element->index = parent->index; connman_element_register(element, parent); } @@ -70,20 +76,22 @@ static void rtnl_link(struct nlmsghdr *hdr, const char *type) for (list = ethernet_list; list; list = list->next) { struct connman_element *element = list->data; + struct ethernet_data *ethernet; - if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE) + ethernet = connman_element_get_data(element); + if (ethernet == NULL) continue; - if (element->netdev.index != msg->ifi_index) + if (ethernet->index != msg->ifi_index) continue; - if ((element->netdev.flags & IFF_RUNNING) == - (msg->ifi_flags & IFF_RUNNING)) + if ((ethernet->flags & IFF_RUNNING) == + (msg->ifi_flags & IFF_RUNNING)) continue; - element->netdev.flags = msg->ifi_flags; + ethernet->flags = msg->ifi_flags; - if (msg->ifi_flags & IFF_RUNNING) { + if (ethernet->flags & IFF_RUNNING) { DBG("carrier on"); create_element(element, CONNMAN_ELEMENT_TYPE_DHCP); @@ -153,7 +161,7 @@ static gboolean rtnl_event(GIOChannel *chan, GIOCondition cond, gpointer data) return TRUE; } -static GIOChannel *channel = NULL; +static GIOChannel *channel; static int rtnl_request(void) { @@ -184,19 +192,19 @@ static int rtnl_request(void) (struct sockaddr *) &addr, sizeof(addr)); } -static int iface_up(struct connman_element *element) +static int iface_up(struct ethernet_data *ethernet) { struct ifreq ifr; int sk, err; - DBG("element %p", element); + DBG("index %d flags %d", ethernet->index, ethernet->flags); sk = socket(PF_INET, SOCK_DGRAM, 0); if (sk < 0) return -errno; memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_ifindex = element->netdev.index; + ifr.ifr_ifindex = ethernet->index; if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) { err = -errno; @@ -228,19 +236,19 @@ done: return err; } -static int iface_down(struct connman_element *element) +static int iface_down(struct ethernet_data *ethernet) { struct ifreq ifr; int sk, err; - DBG("element %p", element); + DBG("index %d flags %d", ethernet->index, ethernet->flags); sk = socket(PF_INET, SOCK_DGRAM, 0); if (sk < 0) return -errno; memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_ifindex = element->netdev.index; + ifr.ifr_ifindex = ethernet->index; if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) { err = -errno; @@ -272,13 +280,23 @@ done: static int ethernet_probe(struct connman_element *element) { + struct ethernet_data *ethernet; + DBG("element %p name %s", element, element->name); + ethernet = g_try_new0(struct ethernet_data, 1); + if (ethernet == NULL) + return -ENOMEM; + g_static_mutex_lock(ðernet_mutex); ethernet_list = g_slist_append(ethernet_list, element); g_static_mutex_unlock(ðernet_mutex); - iface_up(element); + connman_element_set_data(element, ethernet); + + ethernet->index = element->index; + + iface_up(ethernet); rtnl_request(); @@ -287,13 +305,19 @@ static int ethernet_probe(struct connman_element *element) static void ethernet_remove(struct connman_element *element) { + struct ethernet_data *ethernet = connman_element_get_data(element); + DBG("element %p name %s", element, element->name); - iface_down(element); + connman_element_set_data(element, NULL); + + iface_down(ethernet); g_static_mutex_lock(ðernet_mutex); ethernet_list = g_slist_remove(ethernet_list, element); g_static_mutex_unlock(ðernet_mutex); + + g_free(ethernet); } static struct connman_driver ethernet_driver = { @@ -340,8 +364,6 @@ static void rtnl_cleanup(void) g_io_channel_shutdown(channel, TRUE, NULL); g_io_channel_unref(channel); - - channel = NULL; } static int ethernet_init(void) diff --git a/plugins/wifi.c b/plugins/wifi.c index 0561133..f4c3373 100644 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -140,11 +140,10 @@ static void state_change(struct connman_element *parent, if (state == STATE_COMPLETED) { struct connman_element *dhcp; - dhcp = connman_element_create(); + dhcp = connman_element_create(NULL); dhcp->type = CONNMAN_ELEMENT_TYPE_DHCP; - dhcp->netdev.index = element->netdev.index; - dhcp->netdev.name = g_strdup(element->netdev.name); + dhcp->index = element->index; dhcp_element = dhcp; @@ -191,26 +190,24 @@ static void scan_result(struct connman_element *parent, element = find_element(data, network->identifier); if (element == NULL) { - element = connman_element_create(); + element = connman_element_create(temp); element->type = CONNMAN_ELEMENT_TYPE_NETWORK; - element->name = temp; + element->index = parent->index; element->network.identifier = g_strdup(network->identifier); - element->netdev.index = parent->netdev.index; - element->netdev.name = g_strdup(parent->netdev.name); - data->list = g_slist_append(data->list, element); connman_element_add_static_property(element, "SSID", DBUS_TYPE_STRING, &network->identifier); connman_element_register(element, parent); - } else - g_free(temp); + } g_static_mutex_unlock(&data->mutex); + + g_free(temp); } static struct supplicant_callback wifi_callback = {