| | 68 | printf ("%s: Creating ConIcConnection.\n", __FUNCTION__); |
|---|
| | 69 | |
|---|
| | 70 | cnx = con_ic_connection_new (); |
|---|
| | 71 | if (!cnx) { |
|---|
| | 72 | g_warning ("con_ic_connection_new failed."); |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| | 75 | const int connection = g_signal_connect (cnx, "connection-event", |
|---|
| | 76 | G_CALLBACK(on_connection_event), NULL); |
|---|
| | 77 | |
|---|
| | 78 | /* This might be necessary to make the connection object |
|---|
| | 79 | * actually emit the signal, though the documentation says |
|---|
| | 80 | * that they should be sent even when this is not set, |
|---|
| | 81 | * when we explicitly try to connect. |
|---|
| | 82 | * The signal still does not seem to be emitted. |
|---|
| | 83 | */ |
|---|
| | 84 | g_object_set (cnx, "automatic-connection-events", TRUE, NULL); |
|---|
| | 85 | |
|---|
| | 93 | printf ("%s: Waiting for !attempting_connection.\n", __FUNCTION__); |
|---|
| | 94 | |
|---|
| | 95 | /* When the signal has been handled, |
|---|
| | 96 | * attempting_connection will be reset to FALSE. */ |
|---|
| | 97 | while (attempting_connection) { |
|---|
| | 98 | /* Iterate the main loop so that the signal can be called. */ |
|---|
| | 99 | if (g_main_context_pending (NULL)) { |
|---|
| | 100 | g_main_context_iteration (NULL, FALSE); |
|---|
| | 101 | } |
|---|
| | 102 | } |
|---|
| | 103 | |
|---|
| | 104 | printf ("%s: Finished waiting for !attempting_connection.\n", __FUNCTION__); |
|---|
| | 105 | |
|---|
| | 106 | g_signal_handler_disconnect (cnx, connection); |
|---|
| | 107 | |
|---|
| | 108 | return is_online; /* This was set by the signal handler. */ |
|---|
| | 109 | } |
|---|
| | 110 | |
|---|
| | 111 | void on_button_clicked (gpointer user_data) |
|---|
| | 112 | { |
|---|
| | 113 | /* This blocks the UI. That's what we want. */ |
|---|
| | 114 | gboolean result = connect_and_wait(); |
|---|
| | 115 | printf ("%s: connect_and_wait() returned %d\n", __FUNCTION__, result); |
|---|
| 104 | | |
|---|
| 105 | | |
|---|
| 106 | | printf ("%s: Creating ConIcConnection.\n", __FUNCTION__); |
|---|
| 107 | | |
|---|
| 108 | | cnx = con_ic_connection_new (); |
|---|
| 109 | | if (!cnx) { |
|---|
| 110 | | g_warning ("con_ic_connection_new failed."); |
|---|
| 111 | | } |
|---|
| 112 | | g_signal_connect (cnx, "connection-event", |
|---|
| 113 | | G_CALLBACK(on_connection_event), NULL); |
|---|
| 114 | | |
|---|
| 115 | | /* This might be necessary to make the connection object |
|---|
| 116 | | * actually emit the signal, though the documentation says |
|---|
| 117 | | * that they should be sent even when this is not set, |
|---|
| 118 | | * when we explicitly try to connect. |
|---|
| 119 | | * The signal still does not seem to be emitted. |
|---|
| 120 | | */ |
|---|
| 121 | | g_object_set (cnx, "automatic-connection-events", TRUE, NULL); |
|---|