From 7535e54df7b4e1abc1b2cf7ee388ee4fd0f49d2b Mon Sep 17 00:00:00 2001 From: englebass Date: Wed, 19 Nov 2008 06:20:55 +0000 Subject: [PATCH] e_nm_device_wireless_get_access_points git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@37704 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/nm.c | 28 +++++++++++-- src/lib/nm/E_Nm.h | 2 +- src/lib/nm/e_nm_access_point.c | 2 +- src/lib/nm/e_nm_device.c | 89 ++++++++++++++++++++++++++++++++++++++++++ src/lib/nm/e_nm_private.h | 1 + 5 files changed, 116 insertions(+), 6 deletions(-) diff --git a/src/bin/nm.c b/src/bin/nm.c index b4fb242..14e2e18 100644 --- a/src/bin/nm.c +++ b/src/bin/nm.c @@ -133,6 +133,23 @@ cb_ip4_config(void *data, E_NM_IP4_Config *config) } static int +cb_access_points(void *data, Ecore_List *list) +{ + E_NM_Access_Point *ap; + + if (list) + { + ecore_list_first_goto(list); + while ((ap = ecore_list_next(list))) + { + e_nm_access_point_dump(ap); + } + ecore_list_destroy(list); + } + return 1; +} + +static int cb_get_devices(void *data, Ecore_List *list) { E_NM_Device *device; @@ -145,11 +162,14 @@ cb_get_devices(void *data, Ecore_List *list) e_nm_device_dump(device); if (device->device_type == E_NM_DEVICE_TYPE_WIRELESS) { + e_nm_device_wireless_get_access_points(device, cb_access_points, NULL); + /* e_nm_access_point_get(nm, device->wireless.active_access_point, cb_access_point, NULL); e_nm_ip4_config_get(nm, device->ip4_config, cb_ip4_config, NULL); + */ } } - ecore_list_destroy(list); + //ecore_list_destroy(list); } //ecore_main_loop_quit(); return 1; @@ -166,7 +186,6 @@ cb_nm(void *data, E_NM *reply) nm = reply; /* e_nm_wireless_enabled_set(nm, 1); - */ if (nm->active_connections) { const char *conn; @@ -174,12 +193,13 @@ cb_nm(void *data, E_NM *reply) while ((conn = ecore_list_next(nm->active_connections))) e_nm_active_connection_get(nm, conn, cb_active_connection, NULL); } - /* - e_nm_get_devices(nm, cb_get_devices, nm); */ + e_nm_get_devices(nm, cb_get_devices, nm); + /* nms = e_nms_get(nm); e_nms_dump(nms); e_nms_list_connections(nms, cb_nms_connections, nms); + */ return 1; } diff --git a/src/lib/nm/E_Nm.h b/src/lib/nm/E_Nm.h index 1f902c4..c753f52 100644 --- a/src/lib/nm/E_Nm.h +++ b/src/lib/nm/E_Nm.h @@ -311,7 +311,7 @@ extern "C" { EAPI void e_nm_device_free(E_NM_Device *device); EAPI void e_nm_device_dump(E_NM_Device *device); - /* TODO: e_nm_device_wireless_get_access_points */ + EAPI int e_nm_device_wireless_get_access_points(E_NM_Device *device, int (*cb_func)(void *data, Ecore_List *access_points), void *data); EAPI void e_nm_device_data_set(E_NM_Device *device, void *data); EAPI void *e_nm_device_data_get(E_NM_Device *device); diff --git a/src/lib/nm/e_nm_access_point.c b/src/lib/nm/e_nm_access_point.c index 2ac6938..79573a0 100644 --- a/src/lib/nm/e_nm_access_point.c +++ b/src/lib/nm/e_nm_access_point.c @@ -145,7 +145,7 @@ e_nm_access_point_dump(E_NM_Access_Point *ap) { ecore_list_first_goto(ap->ssid); while ((c = ecore_list_next(ap->ssid))) - printf("%u", *c); + printf("%c", *c); printf("\n"); } printf("frequency : %u\n", ap->frequency); diff --git a/src/lib/nm/e_nm_device.c b/src/lib/nm/e_nm_device.c index 7dab416..841c171 100644 --- a/src/lib/nm/e_nm_device.c +++ b/src/lib/nm/e_nm_device.c @@ -189,6 +189,72 @@ error: property_data_free(data); } +static void +check_done(Reply_Data *d, Ecore_List *list) +{ + ecore_list_first_goto(list); + if (ecore_list_empty_is(list)) + { + d->cb_func(d->data, NULL); + ecore_list_destroy(list); + free(d); + } + else if (ecore_list_current(list) != (void *)-1) + { + d->cb_func(d->data, list); + free(d); + } +} + +static int +cb_access_point(void *data, E_NM_Access_Point *ap) +{ + Reply_Data *d; + Ecore_List *list; + + d = data; + list = d->reply; + if (ap) + ecore_list_append(list, ap); + ecore_list_first_remove(list); + + check_done(d, list); + return 1; +} + +static void +cb_access_points(void *data, void *reply, DBusError *err) +{ + Reply_Data *d; + E_NM_Device_Internal *dev; + Ecore_List *access_points; + Ecore_List *list; + const char *ap; + + d = data; + dev = d->object; + if (dbus_error_is_set(err)) + { + printf("Error: %s - %s\n", err->name, err->message); + d->cb_func(d->data, NULL); + free(d); + return; + } + access_points = reply; + ecore_list_first_goto(access_points); + list = ecore_list_new(); + ecore_list_free_cb_set(list, ECORE_FREE_CB(e_nm_access_point_free)); + d->reply = list; + ecore_list_append(list, (void *)-1); + while ((ap = ecore_list_next(access_points))) + { + ecore_list_prepend(list, (void *)-1); + e_nm_access_point_get(dev->nmi, ap, cb_access_point, d); + } + ecore_list_first_remove(list); + check_done(d, list); +} + EAPI int e_nm_device_get(E_NM *nm, const char *device, int (*cb_func)(void *data, E_NM_Device *device), @@ -349,6 +415,29 @@ e_nm_device_dump(E_NM_Device *dev) printf("\n"); } +EAPI int +e_nm_device_wireless_get_access_points(E_NM_Device *device, int (*cb_func)(void *data, Ecore_List *access_points), void *data) +{ + DBusMessage *msg; + Reply_Data *d; + E_NM_Device_Internal *dev; + int ret; + + if (device->device_type != E_NM_DEVICE_TYPE_WIRELESS) return 0; + + dev = (E_NM_Device_Internal *)device; + d = calloc(1, sizeof(Reply_Data)); + d->object = dev; + d->cb_func = OBJECT_CB(cb_func); + d->data = data; + + msg = e_nm_device_wireless_call_new(dev->dev.udi, "GetAccessPoints"); + + ret = e_dbus_method_call_send(dev->nmi->conn, msg, cb_nm_object_path_list, cb_access_points, free_nm_object_path_list, -1, d) ? 1 : 0; + dbus_message_unref(msg); + return ret; +} + EAPI void e_nm_device_data_set(E_NM_Device *device, void *data) { diff --git a/src/lib/nm/e_nm_private.h b/src/lib/nm/e_nm_private.h index 539ea14..19b9e5e 100644 --- a/src/lib/nm/e_nm_private.h +++ b/src/lib/nm/e_nm_private.h @@ -17,6 +17,7 @@ #define _E_NMS_INTERFACE_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection" #define e_nm_call_new(member) dbus_message_new_method_call(_E_NM_SERVICE, E_NM_PATH, _E_NM_INTERFACE, member) +#define e_nm_device_wireless_call_new(device, member) dbus_message_new_method_call(_E_NM_SERVICE, device, _E_NM_INTERFACE_DEVICE_WIRELESS, member) #define e_nms_call_new(service, member) dbus_message_new_method_call(service, _E_NMS_PATH, _E_NMS_INTERFACE, member) #define e_nms_connection_call_new(service, conn, member) dbus_message_new_method_call(service, conn, _E_NMS_INTERFACE_CONNECTION, member) -- 2.7.4