aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barth <david.barth@canonical.com>2015-09-22 09:40:12 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2015-09-22 09:40:12 +0200
commit71e55e0f6cb1c949656441ee4f90585590efc68f (patch)
tree4452a5ccaf332d7de3f160279a467882cba8e6a3
parent56462d6bfd5c99a0a5a47044cf536d286cb170c4 (diff)
downloadremote-logon-service-71e55e0f6cb1c949656441ee4f90585590efc68f.tar.gz
remote-logon-service-71e55e0f6cb1c949656441ee4f90585590efc68f.tar.bz2
remote-logon-service-71e55e0f6cb1c949656441ee4f90585590efc68f.zip
ensure that the availability of a server gets signaled, even in the absence of an exec line
-rw-r--r--src/main.c8
-rw-r--r--src/uccs-server.c28
-rw-r--r--src/uccs-server.h1
-rw-r--r--tests/server-test.c22
4 files changed, 31 insertions, 28 deletions
diff --git a/src/main.c b/src/main.c
index 7c0a806..1d53edc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,13 +68,17 @@ server_status_updated (Server * server, ServerState newstate, RemoteLogon * rl)
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
- if (server_list_to_array(&builder, config_file_servers) > 0) {
+ gint servers = server_list_to_array(&builder, config_file_servers);
+ if (servers > 0) {
array = g_variant_builder_end(&builder);
} else {
g_variant_builder_clear(&builder);
array = g_variant_new_array(G_VARIANT_TYPE("(sssba(sbva{sv})a(si))"), NULL, 0);
}
+ g_debug ("%d server(s) available", servers);
+ g_debug ("Signalling state change to: %d", newstate);
+
remote_logon_emit_servers_updated(rl, array);
return;
}
@@ -167,6 +171,8 @@ handle_get_servers (RemoteLogon * rl, GDBusMethodInvocation * invocation, gpoint
array = g_variant_new_array(G_VARIANT_TYPE("(sssba(sbva{sv})a(si))"), NULL, 0);
}
+ g_debug ("handle_get_servers: returning %s", g_variant_print (array, FALSE));
+
g_dbus_method_invocation_return_value(invocation, g_variant_new_tuple(&array, 1));
return TRUE;
diff --git a/src/uccs-server.c b/src/uccs-server.c
index a87e4d1..db3cfdf 100644
--- a/src/uccs-server.c
+++ b/src/uccs-server.c
@@ -50,7 +50,6 @@ static void json_waiters_notify (UccsServer * server, gboolean unlocked);
static GVariant * get_cached_domains (Server * server);
static Server * find_uri (Server * server, const gchar * uri);
static void set_last_used_server (Server * server, const gchar * uri);
-static void evaluate_state (UccsServer * server);
static void nm_state_changed (NMClient *client, const GParamSpec *pspec, gpointer user_data);
typedef struct _json_callback_t json_callback_t;
@@ -136,22 +135,18 @@ uccs_server_init (UccsServer *self)
self->session = soup_session_sync_new();
nm_state_changed(self->nm_client, NULL, self);
- evaluate_state(self);
+ uccs_notify_state_change(self);
return;
}
-/* Small function to try and figure out the state of the server and set the
- status appropriately */
-static void
-evaluate_state (UccsServer * server)
+/* Small function to try and figure out the state of the server and notify of
+ status changes appropriately */
+void
+uccs_notify_state_change (UccsServer * server)
{
ServerState tempstate = SERVER_STATE_ALLGOOD;
- if (server->exec == NULL) {
- tempstate = SERVER_STATE_UNAVAILABLE;
- }
-
if (server->last_network < server->min_network) {
tempstate = SERVER_STATE_UNAVAILABLE;
}
@@ -318,7 +313,7 @@ verify_server_cb (SoupSession * session, SoupMessage * message, gpointer user_da
server->verified_server = FALSE;
}
- evaluate_state(server);
+ uccs_notify_state_change(server);
return;
}
@@ -362,7 +357,7 @@ nm_state_changed (NMClient *client, const GParamSpec *pspec, gpointer user_data)
verify_server(server);
}
- evaluate_state(server);
+ uccs_notify_state_change(server);
return;
}
@@ -400,13 +395,12 @@ uccs_server_set_exec (UccsServer * server, const gchar * exec)
g_return_val_if_fail(IS_UCCS_SERVER(server), NULL);
g_clear_pointer(&server->exec, g_free);
+ server->exec = g_find_program_in_path(exec);
- if (exec != NULL) {
- server->exec = g_find_program_in_path(exec);
+ if (server->exec == NULL) {
+ g_warning ("unable to find program %s", exec);
}
- evaluate_state(server);
-
return server->exec;
}
@@ -459,7 +453,7 @@ uccs_server_new_from_keyfile (GKeyFile * keyfile, const gchar * groupname)
server->verify_server = g_key_file_get_boolean(keyfile, groupname, CONFIG_UCCS_VERIFY, NULL);
}
- evaluate_state(server);
+ uccs_notify_state_change(server);
return SERVER(server);
}
diff --git a/src/uccs-server.h b/src/uccs-server.h
index 4603a6c..d9782af 100644
--- a/src/uccs-server.h
+++ b/src/uccs-server.h
@@ -76,6 +76,7 @@ Server * uccs_server_new_from_keyfile (GKeyFile * keyfile, const gchar * name);
void uccs_server_unlock (UccsServer * server, const gchar * address, const gchar * username, const gchar * password, gboolean allowcache, void (*callback) (UccsServer * server, gboolean unlocked, gpointer user_data), gpointer user_data);
GVariant * uccs_server_get_servers (UccsServer * server, const gchar * address);
const gchar *uccs_server_set_exec (UccsServer * server, const gchar * exec);
+void uccs_notify_state_change (UccsServer * server);
G_END_DECLS
diff --git a/tests/server-test.c b/tests/server-test.c
index 06b6233..f5e50c7 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -37,27 +37,29 @@ test_update_signal (void)
Server * server = NULL;
server = server_new_from_keyfile(keyfile, groupname);
g_assert(server != NULL);
- g_assert(g_strcmp0(server->name, "My Server") == 0);
- g_assert(g_strcmp0(server->uri, "http://my.domain.com") == 0);
UccsServer * userver = UCCS_SERVER(server);
g_assert(userver != NULL);
gboolean signaled = FALSE;
g_signal_connect(G_OBJECT(server), SERVER_SIGNAL_STATE_CHANGED, G_CALLBACK(state_signal), &signaled);
-
- if (server->state == SERVER_STATE_ALLGOOD) {
- signaled = FALSE;
- uccs_server_set_exec(userver, "thisshouldnotexist");
- g_assert(signaled);
- g_assert(server->state == SERVER_STATE_UNAVAILABLE);
- }
+ server->state = SERVER_STATE_UNAVAILABLE;
signaled = FALSE;
- uccs_server_set_exec(userver, "ls");
+ uccs_notify_state_change(userver);
+ /* a change from available to good is notified */
g_assert(signaled);
g_assert(server->state == SERVER_STATE_ALLGOOD);
+ signaled = FALSE;
+ server->state = SERVER_STATE_ALLGOOD;
+ userver->last_network = NM_STATE_DISCONNECTED;
+ userver->min_network = NM_STATE_CONNECTED_GLOBAL;
+ uccs_notify_state_change(userver);
+ /* if the server becomes unavailable, it is notified as well */
+ g_assert(signaled);
+ g_assert(server->state == SERVER_STATE_UNAVAILABLE);
+
return;
}