mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 05:58:01 +02:00
2006-05-02 Robert Love <rml@novell.com>
Patch by Timo Hoenig; * tests/nm-online.c: Print pretty status indicator as timeout winds down. Also fix possible race between DBUS startup and failure return. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1714 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
a2dbccec37
commit
5bdf83737b
2 changed files with 43 additions and 11 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
|
2006-05-02 Robert Love <rml@novell.com>
|
||||||
|
|
||||||
|
Patch by Timo Hoenig;
|
||||||
|
* tests/nm-online.c: Print pretty status indicator as timeout winds
|
||||||
|
down. Also fix possible race between DBUS startup and failure
|
||||||
|
return.
|
||||||
|
|
||||||
2006-05-01 Robert Love <rml@novell.com>
|
2006-05-01 Robert Love <rml@novell.com>
|
||||||
|
|
||||||
* gnome/applet/applet-compat.c: Warn if the returned escaped ESSID is
|
* gnome/applet/applet-compat.c: Warn if the returned escaped ESSID is
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,15 @@
|
||||||
*
|
*
|
||||||
* Return values:
|
* Return values:
|
||||||
*
|
*
|
||||||
* 0 : online
|
* 0 : already online or connection established within given timeout
|
||||||
* 1 : offline or not online within given timeout
|
* 1 : offline or not online within given timeout
|
||||||
* 2 : error
|
* 2 : unspecified error
|
||||||
*
|
*
|
||||||
* Robert Love <rml@novell.com>
|
* Robert Love <rml@novell.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DBUS_API_SUBJECT_TO_CHANGE 1
|
#define DBUS_API_SUBJECT_TO_CHANGE 1
|
||||||
|
#define PROGRESS_STEPS 15
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -21,6 +22,12 @@
|
||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
#include <NetworkManager/NetworkManager.h>
|
#include <NetworkManager/NetworkManager.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
double norm;
|
||||||
|
} Timeout;
|
||||||
|
|
||||||
static DBusHandlerResult dbus_filter (DBusConnection *connection G_GNUC_UNUSED,
|
static DBusHandlerResult dbus_filter (DBusConnection *connection G_GNUC_UNUSED,
|
||||||
DBusMessage *message,
|
DBusMessage *message,
|
||||||
void *user_data G_GNUC_UNUSED)
|
void *user_data G_GNUC_UNUSED)
|
||||||
|
|
@ -46,8 +53,8 @@ static gboolean check_online (DBusConnection *connection)
|
||||||
reply = dbus_connection_send_with_reply_and_block (connection, message,
|
reply = dbus_connection_send_with_reply_and_block (connection, message,
|
||||||
-1, &error);
|
-1, &error);
|
||||||
dbus_message_unref (message);
|
dbus_message_unref (message);
|
||||||
if (!reply)
|
if (!reply)
|
||||||
exit (2);
|
return FALSE;
|
||||||
|
|
||||||
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &state,
|
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &state,
|
||||||
DBUS_TYPE_INVALID))
|
DBUS_TYPE_INVALID))
|
||||||
|
|
@ -59,9 +66,23 @@ static gboolean check_online (DBusConnection *connection)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean handle_timeout (gpointer data G_GNUC_UNUSED)
|
static gboolean handle_timeout (gpointer data)
|
||||||
{
|
{
|
||||||
exit (1);
|
int i = PROGRESS_STEPS;
|
||||||
|
Timeout *timeout = (Timeout *) data;
|
||||||
|
|
||||||
|
g_print ("\rConnecting");
|
||||||
|
for (; i > 0; i--)
|
||||||
|
putchar ((timeout->value >= (i * timeout->norm)) ? ' ' : '.');
|
||||||
|
if (timeout->value)
|
||||||
|
g_print (" %4is", timeout->value);
|
||||||
|
fflush (stdout);
|
||||||
|
|
||||||
|
timeout->value--;
|
||||||
|
if (timeout->value < 0)
|
||||||
|
exit (1);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
|
|
@ -69,11 +90,13 @@ int main (int argc, char *argv[])
|
||||||
DBusConnection *connection;
|
DBusConnection *connection;
|
||||||
DBusError error;
|
DBusError error;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
int timeout = 30;
|
Timeout timeout;
|
||||||
|
|
||||||
|
timeout.value = 30;
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
timeout = (int) strtol (argv[1], NULL, 10);
|
timeout.value = (int) strtol (argv[1], NULL, 10);
|
||||||
if (timeout < 0 || timeout > 3600)
|
if (timeout.value <= 0 || timeout.value > 3600)
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,8 +128,10 @@ int main (int argc, char *argv[])
|
||||||
if (check_online (connection))
|
if (check_online (connection))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (timeout)
|
if (timeout.value) {
|
||||||
g_timeout_add (timeout * 1000, handle_timeout, NULL);
|
timeout.norm = (double) timeout.value / (double) PROGRESS_STEPS;
|
||||||
|
g_timeout_add (1000, handle_timeout, &timeout);
|
||||||
|
}
|
||||||
|
|
||||||
loop = g_main_loop_new (NULL, FALSE);
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue